knex/lib/formatter/formatterUtils.js

23 lines
699 B
JavaScript
Raw Normal View History

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