123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680 |
- const QueryBuilderOperationSupport = require('./QueryBuilderOperationSupport');
- const { isSqlite, isMsSql } = require('../utils/knexUtils');
- const KnexOperation = require('./operations/KnexOperation');
- const SelectOperation = require('./operations/select/SelectOperation');
- const ReturningOperation = require('./operations/ReturningOperation');
- const WhereCompositeOperation = require('./operations/WhereCompositeOperation');
- const WhereInCompositeOperation = require('./operations/whereInComposite/WhereInCompositeOperation');
- const WhereInCompositeSqliteOperation = require('./operations/whereInComposite/WhereInCompositeSqliteOperation');
- const WhereInCompositeMsSqlOperation = require('./operations/whereInComposite/WhereInCompositeMsSqlOperation');
- const WhereJsonPostgresOperation = require('./operations/jsonApi/WhereJsonPostgresOperation');
- const WhereJsonHasPostgresOperation = require('./operations/jsonApi/WhereJsonHasPostgresOperation');
- const WhereJsonNotObjectPostgresOperation = require('./operations/jsonApi/WhereJsonNotObjectPostgresOperation');
- const SelectSelector = SelectOperation;
- const WhereSelector = /^(where|orWhere|andWhere)/;
- const OrderBySelector = /orderBy/;
- const JoinSelector = /(join|joinRaw)$/i;
- const FromSelector = /^(from|into|table)$/;
- class QueryBuilderBase extends QueryBuilderOperationSupport {
- static get SelectSelector() {
- return SelectSelector;
- }
- static get WhereSelector() {
- return WhereSelector;
- }
- static get JoinSelector() {
- return JoinSelector;
- }
- static get FromSelector() {
- return FromSelector;
- }
- static get OrderBySelector() {
- return OrderBySelector;
- }
- modify() {
- const func = arguments[0];
- if (!func) {
- return this;
- }
- if (arguments.length === 1) {
- func.call(this, this);
- } else {
- const args = new Array(arguments.length);
- args[0] = this;
- for (let i = 1, l = args.length; i < l; ++i) {
- args[i] = arguments[i];
- }
- func.apply(this, args);
- }
- return this;
- }
- transacting(trx) {
- this._context.knex = trx || null;
- return this;
- }
- clearSelect() {
- return this.clear(SelectSelector);
- }
- clearWhere() {
- return this.clear(WhereSelector);
- }
- clearOrder() {
- return this.clear(OrderBySelector);
- }
- select() {
- return this.addOperation(new SelectOperation('select'), arguments);
- }
- insert() {
- return this.addOperation(new KnexOperation('insert'), arguments);
- }
- update() {
- return this.addOperation(new KnexOperation('update'), arguments);
- }
- delete() {
- return this.addOperation(new KnexOperation('delete'), arguments);
- }
- del() {
- return this.addOperation(new KnexOperation('delete'), arguments);
- }
- forUpdate() {
- return this.addOperation(new KnexOperation('forUpdate'), arguments);
- }
- forShare() {
- return this.addOperation(new KnexOperation('forShare'), arguments);
- }
- as() {
- return this.addOperation(new KnexOperation('as'), arguments);
- }
- columns() {
- return this.addOperation(new SelectOperation('columns'), arguments);
- }
- column() {
- return this.addOperation(new SelectOperation('column'), arguments);
- }
- from() {
- return this.addOperation(new KnexOperation('from'), arguments);
- }
- fromJS() {
- return this.addOperation(new KnexOperation('fromJS'), arguments);
- }
- into() {
- return this.addOperation(new KnexOperation('into'), arguments);
- }
- withSchema() {
- return this.addOperation(new KnexOperation('withSchema'), arguments);
- }
- table() {
- return this.addOperation(new KnexOperation('table'), arguments);
- }
- distinct() {
- return this.addOperation(new SelectOperation('distinct'), arguments);
- }
- join() {
- return this.addOperation(new KnexOperation('join'), arguments);
- }
- joinRaw() {
- return this.addOperation(new KnexOperation('joinRaw'), arguments);
- }
- innerJoin() {
- return this.addOperation(new KnexOperation('innerJoin'), arguments);
- }
- leftJoin() {
- return this.addOperation(new KnexOperation('leftJoin'), arguments);
- }
- leftOuterJoin() {
- return this.addOperation(new KnexOperation('leftOuterJoin'), arguments);
- }
- rightJoin() {
- return this.addOperation(new KnexOperation('rightJoin'), arguments);
- }
- rightOuterJoin() {
- return this.addOperation(new KnexOperation('rightOuterJoin'), arguments);
- }
- outerJoin() {
- return this.addOperation(new KnexOperation('outerJoin'), arguments);
- }
- fullOuterJoin() {
- return this.addOperation(new KnexOperation('fullOuterJoin'), arguments);
- }
- crossJoin() {
- return this.addOperation(new KnexOperation('crossJoin'), arguments);
- }
- where() {
- return this.addOperation(new KnexOperation('where'), arguments);
- }
- andWhere() {
- return this.addOperation(new KnexOperation('andWhere'), arguments);
- }
- orWhere() {
- return this.addOperation(new KnexOperation('orWhere'), arguments);
- }
- whereNot() {
- return this.addOperation(new KnexOperation('whereNot'), arguments);
- }
- orWhereNot() {
- return this.addOperation(new KnexOperation('orWhereNot'), arguments);
- }
- whereRaw() {
- return this.addOperation(new KnexOperation('whereRaw'), arguments);
- }
- whereWrapped() {
- return this.addOperation(new KnexOperation('whereWrapped'), arguments);
- }
- havingWrapped() {
- return this.addOperation(new KnexOperation('havingWrapped'), arguments);
- }
- orWhereRaw() {
- return this.addOperation(new KnexOperation('orWhereRaw'), arguments);
- }
- whereExists() {
- return this.addOperation(new KnexOperation('whereExists'), arguments);
- }
- orWhereExists() {
- return this.addOperation(new KnexOperation('orWhereExists'), arguments);
- }
- whereNotExists() {
- return this.addOperation(new KnexOperation('whereNotExists'), arguments);
- }
- orWhereNotExists() {
- return this.addOperation(new KnexOperation('orWhereNotExists'), arguments);
- }
- whereIn() {
- return this.addOperation(new KnexOperation('whereIn'), arguments);
- }
- orWhereIn() {
- return this.addOperation(new KnexOperation('orWhereIn'), arguments);
- }
- whereNotIn() {
- return this.addOperation(new KnexOperation('whereNotIn'), arguments);
- }
- orWhereNotIn() {
- return this.addOperation(new KnexOperation('orWhereNotIn'), arguments);
- }
- whereNull() {
- return this.addOperation(new KnexOperation('whereNull'), arguments);
- }
- orWhereNull() {
- return this.addOperation(new KnexOperation('orWhereNull'), arguments);
- }
- whereNotNull() {
- return this.addOperation(new KnexOperation('whereNotNull'), arguments);
- }
- orWhereNotNull() {
- return this.addOperation(new KnexOperation('orWhereNotNull'), arguments);
- }
- whereBetween() {
- return this.addOperation(new KnexOperation('whereBetween'), arguments);
- }
- andWhereBetween() {
- return this.addOperation(new KnexOperation('andWhereBetween'), arguments);
- }
- whereNotBetween() {
- return this.addOperation(new KnexOperation('whereNotBetween'), arguments);
- }
- andWhereNotBetween() {
- return this.addOperation(new KnexOperation('andWhereNotBetween'), arguments);
- }
- orWhereBetween() {
- return this.addOperation(new KnexOperation('orWhereBetween'), arguments);
- }
- orWhereNotBetween() {
- return this.addOperation(new KnexOperation('orWhereNotBetween'), arguments);
- }
- groupBy() {
- return this.addOperation(new KnexOperation('groupBy'), arguments);
- }
- groupByRaw() {
- return this.addOperation(new KnexOperation('groupByRaw'), arguments);
- }
- orderBy() {
- return this.addOperation(new KnexOperation('orderBy'), arguments);
- }
- orderByRaw() {
- return this.addOperation(new KnexOperation('orderByRaw'), arguments);
- }
- union() {
- return this.addOperation(new KnexOperation('union'), arguments);
- }
- unionAll() {
- return this.addOperation(new KnexOperation('unionAll'), arguments);
- }
- having() {
- return this.addOperation(new KnexOperation('having'), arguments);
- }
- orHaving() {
- return this.addOperation(new KnexOperation('orHaving'), arguments);
- }
- havingIn() {
- return this.addOperation(new KnexOperation('havingIn'), arguments);
- }
- orHavingIn() {
- return this.addOperation(new KnexOperation('havingIn'), arguments);
- }
- havingNotIn() {
- return this.addOperation(new KnexOperation('havingNotIn'), arguments);
- }
- orHavingNotIn() {
- return this.addOperation(new KnexOperation('orHavingNotIn'), arguments);
- }
- havingNull() {
- return this.addOperation(new KnexOperation('havingNull'), arguments);
- }
- orHavingNull() {
- return this.addOperation(new KnexOperation('orHavingNull'), arguments);
- }
- havingNotNull() {
- return this.addOperation(new KnexOperation('havingNotNull'), arguments);
- }
- orHavingNotNull() {
- return this.addOperation(new KnexOperation('orHavingNotNull'), arguments);
- }
- havingExists() {
- return this.addOperation(new KnexOperation('havingExists'), arguments);
- }
- orHavingExists() {
- return this.addOperation(new KnexOperation('orHavingExists'), arguments);
- }
- havingNotExists() {
- return this.addOperation(new KnexOperation('havingNotExists'), arguments);
- }
- orHavingNotExists() {
- return this.addOperation(new KnexOperation('orHavingNotExists'), arguments);
- }
- havingBetween() {
- return this.addOperation(new KnexOperation('havingBetween'), arguments);
- }
- orHavingBetween() {
- return this.addOperation(new KnexOperation('havingBetween'), arguments);
- }
- havingNotBetween() {
- return this.addOperation(new KnexOperation('havingNotBetween'), arguments);
- }
- orHavingNotBetween() {
- return this.addOperation(new KnexOperation('havingNotBetween'), arguments);
- }
- havingRaw() {
- return this.addOperation(new KnexOperation('havingRaw'), arguments);
- }
- orHavingRaw() {
- return this.addOperation(new KnexOperation('orHavingRaw'), arguments);
- }
- offset() {
- return this.addOperation(new KnexOperation('offset'), arguments);
- }
- limit() {
- return this.addOperation(new KnexOperation('limit'), arguments);
- }
- count() {
- return this.addOperation(new SelectOperation('count'), arguments);
- }
- countDistinct() {
- return this.addOperation(new SelectOperation('countDistinct'), arguments);
- }
- min() {
- return this.addOperation(new SelectOperation('min'), arguments);
- }
- max() {
- return this.addOperation(new SelectOperation('max'), arguments);
- }
- sum() {
- return this.addOperation(new SelectOperation('sum'), arguments);
- }
- sumDistinct() {
- return this.addOperation(new SelectOperation('sumDistinct'), arguments);
- }
- avg() {
- return this.addOperation(new SelectOperation('avg'), arguments);
- }
- avgDistinct() {
- return this.addOperation(new SelectOperation('avgDistinct'), arguments);
- }
- debug() {
- return this.addOperation(new KnexOperation('debug'), arguments);
- }
- returning() {
- return this.addOperation(new ReturningOperation('returning'), arguments);
- }
- truncate() {
- return this.addOperation(new KnexOperation('truncate'), arguments);
- }
- connection() {
- return this.addOperation(new KnexOperation('connection'), arguments);
- }
- options() {
- return this.addOperation(new KnexOperation('options'), arguments);
- }
- columnInfo() {
- return this.addOperation(new KnexOperation('columnInfo'), arguments);
- }
- off() {
- return this.addOperation(new KnexOperation('off'), arguments);
- }
- timeout() {
- return this.addOperation(new KnexOperation('timeout'), arguments);
- }
- with() {
- return this.addOperation(new KnexOperation('with'), arguments);
- }
- withRaw() {
- return this.addOperation(new KnexOperation('withRaw'), arguments);
- }
- withWrapped() {
- return this.addOperation(new KnexOperation('withWrapped'), arguments);
- }
- whereComposite() {
- return this.addOperation(new WhereCompositeOperation('whereComposite'), arguments);
- }
- whereInComposite() {
- let operation = null;
- if (isSqlite(this.knex())) {
- operation = new WhereInCompositeSqliteOperation('whereInComposite');
- } else if (isMsSql(this.knex())) {
- operation = new WhereInCompositeMsSqlOperation('whereInComposite');
- } else {
- operation = new WhereInCompositeOperation('whereInComposite');
- }
- return this.addOperation(operation, arguments);
- }
- whereNotInComposite() {
- let operation = null;
- if (isSqlite(this.knex())) {
- operation = new WhereInCompositeSqliteOperation('whereNotInComposite', { prefix: 'not' });
- } else if (isMsSql(this.knex())) {
- operation = new WhereInCompositeMsSqlOperation('whereNotInComposite', { prefix: 'not' });
- } else {
- operation = new WhereInCompositeOperation('whereNotInComposite', { prefix: 'not' });
- }
- return this.addOperation(operation, arguments);
- }
- whereJsonSupersetOf() {
- return this.addOperation(
- new WhereJsonPostgresOperation('whereJsonSupersetOf', { operator: '@>', bool: 'and' }),
- arguments
- );
- }
- orWhereJsonSupersetOf() {
- return this.addOperation(
- new WhereJsonPostgresOperation('orWhereJsonSupersetOf', { operator: '@>', bool: 'or' }),
- arguments
- );
- }
- whereJsonNotSupersetOf() {
- return this.addOperation(
- new WhereJsonPostgresOperation('whereJsonNotSupersetOf', {
- operator: '@>',
- bool: 'and',
- prefix: 'not'
- }),
- arguments
- );
- }
- orWhereJsonNotSupersetOf() {
- return this.addOperation(
- new WhereJsonPostgresOperation('orWhereJsonNotSupersetOf', {
- operator: '@>',
- bool: 'or',
- prefix: 'not'
- }),
- arguments
- );
- }
- whereJsonSubsetOf() {
- return this.addOperation(
- new WhereJsonPostgresOperation('whereJsonSubsetOf', { operator: '<@', bool: 'and' }),
- arguments
- );
- }
- orWhereJsonSubsetOf(fieldExpression, jsonObjectOrFieldExpression) {
- return this.addOperation(
- new WhereJsonPostgresOperation('orWhereJsonSubsetOf', { operator: '<@', bool: 'or' }),
- arguments
- );
- }
- whereJsonNotSubsetOf() {
- return this.addOperation(
- new WhereJsonPostgresOperation('whereJsonNotSubsetOf', {
- operator: '<@',
- bool: 'and',
- prefix: 'not'
- }),
- arguments
- );
- }
- orWhereJsonNotSubsetOf(fieldExpression, jsonObjectOrFieldExpression) {
- return this.addOperation(
- new WhereJsonPostgresOperation('orWhereJsonNotSubsetOf', {
- operator: '<@',
- bool: 'or',
- prefix: 'not'
- }),
- arguments
- );
- }
- whereJsonNotArray() {
- return this.addOperation(
- new WhereJsonNotObjectPostgresOperation('whereJsonNotArray', {
- bool: 'and',
- compareValue: []
- }),
- arguments
- );
- }
- orWhereJsonNotArray() {
- return this.addOperation(
- new WhereJsonNotObjectPostgresOperation('orWhereJsonNotArray', {
- bool: 'or',
- compareValue: []
- }),
- arguments
- );
- }
- whereJsonNotObject() {
- return this.addOperation(
- new WhereJsonNotObjectPostgresOperation('whereJsonNotObject', {
- bool: 'and',
- compareValue: {}
- }),
- arguments
- );
- }
- orWhereJsonNotObject() {
- return this.addOperation(
- new WhereJsonNotObjectPostgresOperation('orWhereJsonNotObject', {
- bool: 'or',
- compareValue: {}
- }),
- arguments
- );
- }
- whereJsonHasAny() {
- return this.addOperation(
- new WhereJsonHasPostgresOperation('whereJsonHasAny', { bool: 'and', operator: '?|' }),
- arguments
- );
- }
- orWhereJsonHasAny() {
- return this.addOperation(
- new WhereJsonHasPostgresOperation('orWhereJsonHasAny', { bool: 'or', operator: '?|' }),
- arguments
- );
- }
- whereJsonHasAll() {
- return this.addOperation(
- new WhereJsonHasPostgresOperation('whereJsonHasAll', { bool: 'and', operator: '?&' }),
- arguments
- );
- }
- orWhereJsonHasAll() {
- return this.addOperation(
- new WhereJsonHasPostgresOperation('orWhereJsonHasAll', { bool: 'or', operator: '?&' }),
- arguments
- );
- }
- whereJsonIsArray(fieldExpression) {
- return this.whereJsonSupersetOf(fieldExpression, []);
- }
- orWhereJsonIsArray(fieldExpression) {
- return this.orWhereJsonSupersetOf(fieldExpression, []);
- }
- whereJsonIsObject(fieldExpression) {
- return this.whereJsonSupersetOf(fieldExpression, {});
- }
- orWhereJsonIsObject(fieldExpression) {
- return this.orWhereJsonSupersetOf(fieldExpression, {});
- }
- }
- Object.defineProperties(QueryBuilderBase.prototype, {
- isObjectionQueryBuilderBase: {
- enumerable: false,
- writable: false,
- value: true
- }
- });
- module.exports = QueryBuilderBase;
|