2021-01-07 02:04:10 +02:00
|
|
|
// Compiles a callback using the query builder.
|
2021-01-09 17:40:30 +02:00
|
|
|
function compileCallback(callback, method, client, bindingsHolder) {
|
2021-01-07 02:04:10 +02:00
|
|
|
// Build the callback
|
|
|
|
const builder = client.queryBuilder();
|
|
|
|
callback.call(builder, builder);
|
|
|
|
|
|
|
|
// Compile the callback, using the current formatter (to track all bindings).
|
2021-01-09 17:40:30 +02:00
|
|
|
const compiler = client.queryCompiler(builder, bindingsHolder.bindings);
|
2021-01-07 02:04:10 +02:00
|
|
|
|
|
|
|
// Return the compiled & parameterized sql.
|
|
|
|
return compiler.toSQL(method || builder._method || 'select');
|
|
|
|
}
|
|
|
|
|
2021-01-07 17:31:56 +02:00
|
|
|
function wrapAsIdentifier(value, builder, client) {
|
|
|
|
const queryContext = builder.queryContext();
|
|
|
|
return client.wrapIdentifier((value || '').trim(), queryContext);
|
|
|
|
}
|
|
|
|
|
2021-01-07 02:04:10 +02:00
|
|
|
module.exports = {
|
|
|
|
compileCallback,
|
2021-01-07 17:31:56 +02:00
|
|
|
wrapAsIdentifier,
|
2021-01-07 02:04:10 +02:00
|
|
|
};
|