2016-03-02 17:07:05 +01:00
|
|
|
|
2016-05-18 20:22:50 +10:00
|
|
|
import { isString, tail } from 'lodash'
|
2018-02-01 23:41:01 +01:00
|
|
|
import ColumnCompiler from './columncompiler'
|
|
|
|
import TableCompiler from './tablecompiler'
|
|
|
|
import SchemaCompiler from './compiler'
|
2016-03-02 17:07:05 +01:00
|
|
|
|
|
|
|
// Push a new query onto the compiled "sequence" stack,
|
|
|
|
// creating a new formatter, returning the compiler.
|
2016-05-17 01:01:34 +10:00
|
|
|
export function pushQuery(query) {
|
2016-03-02 17:07:05 +01:00
|
|
|
if (!query) return;
|
|
|
|
if (isString(query)) {
|
|
|
|
query = {sql: query};
|
|
|
|
}
|
|
|
|
if (!query.bindings) {
|
|
|
|
query.bindings = this.formatter.bindings;
|
|
|
|
}
|
|
|
|
this.sequence.push(query);
|
2018-02-01 23:41:01 +01:00
|
|
|
|
|
|
|
let builder;
|
|
|
|
if (this instanceof ColumnCompiler) {
|
|
|
|
builder = this.columnBuilder;
|
|
|
|
} else if (this instanceof TableCompiler) {
|
|
|
|
builder = this.tableBuilder;
|
|
|
|
} else if (this instanceof SchemaCompiler) {
|
|
|
|
builder = this.builder;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.formatter = this.client.formatter(builder);
|
2016-05-17 01:01:34 +10:00
|
|
|
}
|
2016-03-02 17:07:05 +01:00
|
|
|
|
|
|
|
// Used in cases where we need to push some additional column specific statements.
|
2016-05-17 01:01:34 +10:00
|
|
|
export function pushAdditional(fn) {
|
|
|
|
const child = new this.constructor(this.client, this.tableCompiler, this.columnBuilder);
|
2016-03-02 17:07:05 +01:00
|
|
|
fn.call(child, tail(arguments));
|
|
|
|
this.sequence.additional = (this.sequence.additional || []).concat(child.sequence);
|
2016-05-17 01:01:34 +10:00
|
|
|
}
|