2020-04-18 20:41:23 +03:00
|
|
|
const tail = require('lodash/tail');
|
2020-12-28 16:55:08 +02:00
|
|
|
const { isString } = require('../../util/is');
|
2016-03-02 17:07:05 +01:00
|
|
|
|
|
|
|
// Push a new query onto the compiled "sequence" stack,
|
|
|
|
// creating a new formatter, returning the compiler.
|
2019-06-04 00:37:17 +02:00
|
|
|
function pushQuery(query) {
|
2016-03-02 17:07:05 +01:00
|
|
|
if (!query) return;
|
|
|
|
if (isString(query)) {
|
2018-07-09 08:10:34 -04:00
|
|
|
query = { sql: query };
|
2016-03-02 17:07:05 +01:00
|
|
|
}
|
|
|
|
if (!query.bindings) {
|
2021-02-04 15:54:26 +02:00
|
|
|
query.bindings = this.bindingsHolder.bindings;
|
2016-03-02 17:07:05 +01:00
|
|
|
}
|
|
|
|
this.sequence.push(query);
|
2018-02-01 23:41:01 +01:00
|
|
|
|
2018-10-04 00:25:05 +03:00
|
|
|
this.formatter = this.client.formatter(this._commonBuilder);
|
2021-02-04 15:54:26 +02:00
|
|
|
this.bindings = [];
|
|
|
|
this.formatter.bindings = this.bindings;
|
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.
|
2019-06-04 00:37:17 +02:00
|
|
|
function pushAdditional(fn) {
|
2018-07-09 08:10:34 -04:00
|
|
|
const child = new this.constructor(
|
|
|
|
this.client,
|
|
|
|
this.tableCompiler,
|
|
|
|
this.columnBuilder
|
|
|
|
);
|
2016-03-02 17:07:05 +01:00
|
|
|
fn.call(child, tail(arguments));
|
2018-07-09 08:10:34 -04:00
|
|
|
this.sequence.additional = (this.sequence.additional || []).concat(
|
|
|
|
child.sequence
|
|
|
|
);
|
2016-05-17 01:01:34 +10:00
|
|
|
}
|
2018-05-29 10:09:13 -04:00
|
|
|
|
|
|
|
// Unshift a new query onto the compiled "sequence" stack,
|
|
|
|
// creating a new formatter, returning the compiler.
|
2019-06-04 00:37:17 +02:00
|
|
|
function unshiftQuery(query) {
|
2018-05-29 10:09:13 -04:00
|
|
|
if (!query) return;
|
|
|
|
if (isString(query)) {
|
2018-07-09 08:10:34 -04:00
|
|
|
query = { sql: query };
|
2018-05-29 10:09:13 -04:00
|
|
|
}
|
|
|
|
if (!query.bindings) {
|
2021-02-04 15:54:26 +02:00
|
|
|
query.bindings = this.bindingsHolder.bindings;
|
2018-05-29 10:09:13 -04:00
|
|
|
}
|
|
|
|
this.sequence.unshift(query);
|
|
|
|
|
2018-10-04 00:25:05 +03:00
|
|
|
this.formatter = this.client.formatter(this._commonBuilder);
|
2021-02-04 15:54:26 +02:00
|
|
|
this.bindings = [];
|
|
|
|
this.formatter.bindings = this.bindings;
|
2018-05-29 10:09:13 -04:00
|
|
|
}
|
2019-06-04 00:37:17 +02:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
pushAdditional,
|
|
|
|
pushQuery,
|
|
|
|
unshiftQuery,
|
|
|
|
};
|