knex/src/schema/helpers.js

26 lines
807 B
JavaScript
Raw Normal View History

2016-03-02 16:52:32 +01:00
import {isString, tail} from 'lodash'
// Push a new query onto the compiled "sequence" stack,
// creating a new formatter, returning the compiler.
exports.pushQuery = function(query) {
if (!query) return;
if (isString(query)) {
query = {sql: query};
} else {
query = query;
}
if (!query.bindings) {
query.bindings = this.formatter.bindings;
}
this.sequence.push(query);
this.formatter = this.client.formatter();
};
// Used in cases where we need to push some additional column specific statements.
exports.pushAdditional = function(fn) {
var child = new this.constructor(this.client, this.tableCompiler, this.columnBuilder);
fn.call(child, tail(arguments));
this.sequence.additional = (this.sequence.additional || []).concat(child.sequence);
};