knex 0.21.20 → 0.21.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/CONTRIBUTING.md +184 -184
- package/LICENSE +22 -22
- package/README.md +95 -95
- package/bin/cli.js +414 -414
- package/bin/utils/cli-config-utils.js +151 -151
- package/bin/utils/constants.js +7 -7
- package/bin/utils/migrationsLister.js +37 -37
- package/knex.js +8 -8
- package/lib/client.js +413 -413
- package/lib/config-resolver.js +61 -61
- package/lib/constants.js +44 -44
- package/lib/dialects/mssql/index.js +390 -390
- package/lib/dialects/mssql/query/compiler.js +444 -444
- package/lib/dialects/mssql/schema/columncompiler.js +103 -103
- package/lib/dialects/mssql/schema/compiler.js +59 -59
- package/lib/dialects/mssql/schema/tablecompiler.js +245 -245
- package/lib/dialects/mssql/transaction.js +97 -97
- package/lib/dialects/mysql/index.js +191 -191
- package/lib/dialects/mysql/query/compiler.js +142 -142
- package/lib/dialects/mysql/schema/columncompiler.js +171 -171
- package/lib/dialects/mysql/schema/compiler.js +60 -60
- package/lib/dialects/mysql/schema/tablecompiler.js +262 -262
- package/lib/dialects/mysql/transaction.js +48 -48
- package/lib/dialects/mysql2/index.js +35 -35
- package/lib/dialects/mysql2/transaction.js +46 -46
- package/lib/dialects/oracle/DEAD_CODE.md +5 -5
- package/lib/dialects/oracle/formatter.js +20 -20
- package/lib/dialects/oracle/index.js +79 -79
- package/lib/dialects/oracle/query/compiler.js +327 -327
- package/lib/dialects/oracle/schema/columnbuilder.js +18 -18
- package/lib/dialects/oracle/schema/columncompiler.js +139 -139
- package/lib/dialects/oracle/schema/compiler.js +81 -81
- package/lib/dialects/oracle/schema/tablecompiler.js +165 -165
- package/lib/dialects/oracle/schema/trigger.js +126 -126
- package/lib/dialects/oracle/utils.js +86 -86
- package/lib/dialects/oracledb/index.js +489 -489
- package/lib/dialects/oracledb/query/compiler.js +363 -363
- package/lib/dialects/oracledb/schema/columncompiler.js +35 -35
- package/lib/dialects/oracledb/transaction.js +76 -76
- package/lib/dialects/oracledb/utils.js +14 -14
- package/lib/dialects/postgres/index.js +319 -319
- package/lib/dialects/postgres/query/compiler.js +206 -206
- package/lib/dialects/postgres/schema/columncompiler.js +125 -125
- package/lib/dialects/postgres/schema/compiler.js +109 -109
- package/lib/dialects/postgres/schema/tablecompiler.js +183 -183
- package/lib/dialects/redshift/index.js +73 -73
- package/lib/dialects/redshift/query/compiler.js +119 -119
- package/lib/dialects/redshift/schema/columnbuilder.js +20 -20
- package/lib/dialects/redshift/schema/columncompiler.js +60 -60
- package/lib/dialects/redshift/schema/compiler.js +14 -14
- package/lib/dialects/redshift/schema/tablecompiler.js +123 -123
- package/lib/dialects/redshift/transaction.js +18 -18
- package/lib/dialects/sqlite3/formatter.js +21 -21
- package/lib/dialects/sqlite3/index.js +169 -169
- package/lib/dialects/sqlite3/query/compiler.js +222 -222
- package/lib/dialects/sqlite3/schema/columncompiler.js +27 -27
- package/lib/dialects/sqlite3/schema/compiler.js +49 -49
- package/lib/dialects/sqlite3/schema/ddl.js +525 -525
- package/lib/dialects/sqlite3/schema/tablecompiler.js +238 -238
- package/lib/formatter.js +295 -295
- package/lib/functionhelper.js +14 -14
- package/lib/helpers.js +92 -92
- package/lib/index.js +3 -3
- package/lib/interface.js +115 -115
- package/lib/knex.js +42 -42
- package/lib/logger.js +76 -76
- package/lib/migrate/MigrationGenerator.js +82 -82
- package/lib/migrate/Migrator.js +611 -611
- package/lib/migrate/configuration-merger.js +60 -60
- package/lib/migrate/migrate-stub.js +17 -17
- package/lib/migrate/migration-list-resolver.js +36 -36
- package/lib/migrate/sources/fs-migrations.js +99 -99
- package/lib/migrate/stub/cjs.stub +15 -15
- package/lib/migrate/stub/coffee.stub +13 -13
- package/lib/migrate/stub/eg.stub +14 -14
- package/lib/migrate/stub/js.stub +15 -15
- package/lib/migrate/stub/knexfile-coffee.stub +34 -34
- package/lib/migrate/stub/knexfile-eg.stub +43 -43
- package/lib/migrate/stub/knexfile-js.stub +44 -44
- package/lib/migrate/stub/knexfile-ls.stub +35 -35
- package/lib/migrate/stub/knexfile-ts.stub +44 -44
- package/lib/migrate/stub/ls.stub +14 -14
- package/lib/migrate/stub/ts.stub +21 -21
- package/lib/migrate/table-creator.js +67 -67
- package/lib/migrate/table-resolver.js +27 -27
- package/lib/query/builder.js +1372 -1372
- package/lib/query/compiler.js +889 -889
- package/lib/query/constants.js +13 -13
- package/lib/query/joinclause.js +263 -263
- package/lib/query/methods.js +92 -92
- package/lib/query/string.js +190 -190
- package/lib/raw.js +188 -188
- package/lib/ref.js +39 -39
- package/lib/runner.js +285 -285
- package/lib/schema/builder.js +82 -82
- package/lib/schema/columnbuilder.js +117 -117
- package/lib/schema/columncompiler.js +177 -177
- package/lib/schema/compiler.js +101 -101
- package/lib/schema/helpers.js +51 -51
- package/lib/schema/tablebuilder.js +288 -288
- package/lib/schema/tablecompiler.js +296 -296
- package/lib/seed/Seeder.js +203 -203
- package/lib/seed/seed-stub.js +13 -13
- package/lib/seed/stub/coffee.stub +9 -9
- package/lib/seed/stub/eg.stub +11 -11
- package/lib/seed/stub/js.stub +13 -13
- package/lib/seed/stub/ls.stub +11 -11
- package/lib/seed/stub/ts.stub +13 -13
- package/lib/transaction.js +363 -363
- package/lib/util/batchInsert.js +59 -59
- package/lib/util/delay.js +6 -6
- package/lib/util/fake-client.js +9 -9
- package/lib/util/finally-mixin.js +13 -13
- package/lib/util/fs.js +76 -76
- package/lib/util/import-file.js +13 -13
- package/lib/util/is-module-type.js +14 -14
- package/lib/util/is.js +32 -32
- package/lib/util/make-knex.js +338 -338
- package/lib/util/nanoid.js +29 -29
- package/lib/util/noop.js +1 -1
- package/lib/util/parse-connection.js +66 -66
- package/lib/util/save-async-stack.js +14 -14
- package/lib/util/template.js +52 -52
- package/lib/util/timeout.js +29 -29
- package/lib/util/timestamp.js +16 -16
- package/package.json +1 -1
- package/scripts/build.js +125 -125
- package/scripts/docker-compose.yml +111 -111
- package/scripts/next-release-howto.md +24 -24
- package/scripts/release.sh +34 -34
- package/scripts/runkit-example.js +34 -34
- package/scripts/stress-test/README.txt +18 -18
- package/scripts/stress-test/docker-compose.yml +47 -47
- package/scripts/stress-test/knex-stress-test.js +196 -196
- package/scripts/stress-test/mysql2-random-hanging-every-now-and-then.js +145 -145
- package/scripts/stress-test/mysql2-sudden-exit-without-error.js +100 -100
- package/scripts/stress-test/reconnect-test-mysql-based-drivers.js +184 -184
- package/types/index.d.ts +2249 -2249
- package/types/result.d.ts +27 -27
- package/types/tables.d.ts +4 -4
package/lib/query/constants.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* internal constants, do not use in application code
|
|
3
|
-
*/
|
|
4
|
-
module.exports = {
|
|
5
|
-
lockMode: {
|
|
6
|
-
forShare: 'forShare',
|
|
7
|
-
forUpdate: 'forUpdate',
|
|
8
|
-
},
|
|
9
|
-
waitMode: {
|
|
10
|
-
skipLocked: 'skipLocked',
|
|
11
|
-
noWait: 'noWait',
|
|
12
|
-
},
|
|
13
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* internal constants, do not use in application code
|
|
3
|
+
*/
|
|
4
|
+
module.exports = {
|
|
5
|
+
lockMode: {
|
|
6
|
+
forShare: 'forShare',
|
|
7
|
+
forUpdate: 'forUpdate',
|
|
8
|
+
},
|
|
9
|
+
waitMode: {
|
|
10
|
+
skipLocked: 'skipLocked',
|
|
11
|
+
noWait: 'noWait',
|
|
12
|
+
},
|
|
13
|
+
};
|
package/lib/query/joinclause.js
CHANGED
|
@@ -1,263 +1,263 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
|
|
3
|
-
// JoinClause
|
|
4
|
-
// -------
|
|
5
|
-
|
|
6
|
-
// The "JoinClause" is an object holding any necessary info about a join,
|
|
7
|
-
// including the type, and any associated tables & columns being joined.
|
|
8
|
-
function JoinClause(table, type, schema) {
|
|
9
|
-
this.schema = schema;
|
|
10
|
-
this.table = table;
|
|
11
|
-
this.joinType = type;
|
|
12
|
-
this.and = this;
|
|
13
|
-
this.clauses = [];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function getClauseFromArguments(compilerType, bool, first, operator, second) {
|
|
17
|
-
let data = null;
|
|
18
|
-
|
|
19
|
-
if (typeof first === 'function') {
|
|
20
|
-
data = {
|
|
21
|
-
type: 'onWrapped',
|
|
22
|
-
value: first,
|
|
23
|
-
bool: bool,
|
|
24
|
-
};
|
|
25
|
-
} else {
|
|
26
|
-
switch (arguments.length) {
|
|
27
|
-
case 3: {
|
|
28
|
-
data = { type: 'onRaw', value: first, bool };
|
|
29
|
-
break;
|
|
30
|
-
}
|
|
31
|
-
case 4:
|
|
32
|
-
data = {
|
|
33
|
-
type: compilerType,
|
|
34
|
-
column: first,
|
|
35
|
-
operator: '=',
|
|
36
|
-
value: operator,
|
|
37
|
-
bool,
|
|
38
|
-
};
|
|
39
|
-
break;
|
|
40
|
-
default:
|
|
41
|
-
data = {
|
|
42
|
-
type: compilerType,
|
|
43
|
-
column: first,
|
|
44
|
-
operator,
|
|
45
|
-
value: second,
|
|
46
|
-
bool,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return data;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
Object.assign(JoinClause.prototype, {
|
|
55
|
-
grouping: 'join',
|
|
56
|
-
|
|
57
|
-
// Adds an "on" clause to the current join object.
|
|
58
|
-
on(first) {
|
|
59
|
-
if (typeof first === 'object' && typeof first.toSQL !== 'function') {
|
|
60
|
-
const keys = Object.keys(first);
|
|
61
|
-
let i = -1;
|
|
62
|
-
const method = this._bool() === 'or' ? 'orOn' : 'on';
|
|
63
|
-
while (++i < keys.length) {
|
|
64
|
-
this[method](keys[i], first[keys[i]]);
|
|
65
|
-
}
|
|
66
|
-
return this;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const data = getClauseFromArguments('onBasic', this._bool(), ...arguments);
|
|
70
|
-
|
|
71
|
-
if (data) {
|
|
72
|
-
this.clauses.push(data);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return this;
|
|
76
|
-
},
|
|
77
|
-
|
|
78
|
-
// Adds a "using" clause to the current join.
|
|
79
|
-
using(column) {
|
|
80
|
-
return this.clauses.push({ type: 'onUsing', column, bool: this._bool() });
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
/*// Adds an "and on" clause to the current join object.
|
|
84
|
-
andOn() {
|
|
85
|
-
return this.on.apply(this, arguments);
|
|
86
|
-
},*/
|
|
87
|
-
|
|
88
|
-
// Adds an "or on" clause to the current join object.
|
|
89
|
-
orOn(first, operator, second) {
|
|
90
|
-
return this._bool('or').on.apply(this, arguments);
|
|
91
|
-
},
|
|
92
|
-
|
|
93
|
-
onVal(first) {
|
|
94
|
-
if (typeof first === 'object' && typeof first.toSQL !== 'function') {
|
|
95
|
-
const keys = Object.keys(first);
|
|
96
|
-
let i = -1;
|
|
97
|
-
const method = this._bool() === 'or' ? 'orOnVal' : 'onVal';
|
|
98
|
-
while (++i < keys.length) {
|
|
99
|
-
this[method](keys[i], first[keys[i]]);
|
|
100
|
-
}
|
|
101
|
-
return this;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const data = getClauseFromArguments('onVal', this._bool(), ...arguments);
|
|
105
|
-
|
|
106
|
-
if (data) {
|
|
107
|
-
this.clauses.push(data);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return this;
|
|
111
|
-
},
|
|
112
|
-
|
|
113
|
-
andOnVal() {
|
|
114
|
-
return this.onVal(...arguments);
|
|
115
|
-
},
|
|
116
|
-
|
|
117
|
-
orOnVal() {
|
|
118
|
-
return this._bool('or').onVal(...arguments);
|
|
119
|
-
},
|
|
120
|
-
|
|
121
|
-
onBetween(column, values) {
|
|
122
|
-
assert(
|
|
123
|
-
Array.isArray(values),
|
|
124
|
-
'The second argument to onBetween must be an array.'
|
|
125
|
-
);
|
|
126
|
-
assert(
|
|
127
|
-
values.length === 2,
|
|
128
|
-
'You must specify 2 values for the onBetween clause'
|
|
129
|
-
);
|
|
130
|
-
this.clauses.push({
|
|
131
|
-
type: 'onBetween',
|
|
132
|
-
column,
|
|
133
|
-
value: values,
|
|
134
|
-
bool: this._bool(),
|
|
135
|
-
not: this._not(),
|
|
136
|
-
});
|
|
137
|
-
return this;
|
|
138
|
-
},
|
|
139
|
-
|
|
140
|
-
onNotBetween(column, values) {
|
|
141
|
-
return this._not(true).onBetween(column, values);
|
|
142
|
-
},
|
|
143
|
-
|
|
144
|
-
orOnBetween(column, values) {
|
|
145
|
-
return this._bool('or').onBetween(column, values);
|
|
146
|
-
},
|
|
147
|
-
|
|
148
|
-
orOnNotBetween(column, values) {
|
|
149
|
-
return this._bool('or')._not(true).onBetween(column, values);
|
|
150
|
-
},
|
|
151
|
-
|
|
152
|
-
onIn(column, values) {
|
|
153
|
-
if (Array.isArray(values) && values.length === 0) return this.on(1, '=', 0);
|
|
154
|
-
this.clauses.push({
|
|
155
|
-
type: 'onIn',
|
|
156
|
-
column,
|
|
157
|
-
value: values,
|
|
158
|
-
not: this._not(),
|
|
159
|
-
bool: this._bool(),
|
|
160
|
-
});
|
|
161
|
-
return this;
|
|
162
|
-
},
|
|
163
|
-
|
|
164
|
-
onNotIn(column, values) {
|
|
165
|
-
return this._not(true).onIn(column, values);
|
|
166
|
-
},
|
|
167
|
-
|
|
168
|
-
orOnIn(column, values) {
|
|
169
|
-
return this._bool('or').onIn(column, values);
|
|
170
|
-
},
|
|
171
|
-
|
|
172
|
-
orOnNotIn(column, values) {
|
|
173
|
-
return this._bool('or')._not(true).onIn(column, values);
|
|
174
|
-
},
|
|
175
|
-
|
|
176
|
-
onNull(column) {
|
|
177
|
-
this.clauses.push({
|
|
178
|
-
type: 'onNull',
|
|
179
|
-
column,
|
|
180
|
-
not: this._not(),
|
|
181
|
-
bool: this._bool(),
|
|
182
|
-
});
|
|
183
|
-
return this;
|
|
184
|
-
},
|
|
185
|
-
|
|
186
|
-
orOnNull(callback) {
|
|
187
|
-
return this._bool('or').onNull(callback);
|
|
188
|
-
},
|
|
189
|
-
|
|
190
|
-
onNotNull(callback) {
|
|
191
|
-
return this._not(true).onNull(callback);
|
|
192
|
-
},
|
|
193
|
-
|
|
194
|
-
orOnNotNull(callback) {
|
|
195
|
-
return this._not(true)._bool('or').onNull(callback);
|
|
196
|
-
},
|
|
197
|
-
|
|
198
|
-
onExists(callback) {
|
|
199
|
-
this.clauses.push({
|
|
200
|
-
type: 'onExists',
|
|
201
|
-
value: callback,
|
|
202
|
-
not: this._not(),
|
|
203
|
-
bool: this._bool(),
|
|
204
|
-
});
|
|
205
|
-
return this;
|
|
206
|
-
},
|
|
207
|
-
|
|
208
|
-
orOnExists(callback) {
|
|
209
|
-
return this._bool('or').onExists(callback);
|
|
210
|
-
},
|
|
211
|
-
|
|
212
|
-
onNotExists(callback) {
|
|
213
|
-
return this._not(true).onExists(callback);
|
|
214
|
-
},
|
|
215
|
-
|
|
216
|
-
orOnNotExists(callback) {
|
|
217
|
-
return this._not(true)._bool('or').onExists(callback);
|
|
218
|
-
},
|
|
219
|
-
|
|
220
|
-
// Explicitly set the type of join, useful within a function when creating a grouped join.
|
|
221
|
-
type(type) {
|
|
222
|
-
this.joinType = type;
|
|
223
|
-
return this;
|
|
224
|
-
},
|
|
225
|
-
|
|
226
|
-
_bool(bool) {
|
|
227
|
-
if (arguments.length === 1) {
|
|
228
|
-
this._boolFlag = bool;
|
|
229
|
-
return this;
|
|
230
|
-
}
|
|
231
|
-
const ret = this._boolFlag || 'and';
|
|
232
|
-
this._boolFlag = 'and';
|
|
233
|
-
return ret;
|
|
234
|
-
},
|
|
235
|
-
|
|
236
|
-
_not(val) {
|
|
237
|
-
if (arguments.length === 1) {
|
|
238
|
-
this._notFlag = val;
|
|
239
|
-
return this;
|
|
240
|
-
}
|
|
241
|
-
const ret = this._notFlag;
|
|
242
|
-
this._notFlag = false;
|
|
243
|
-
return ret;
|
|
244
|
-
},
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
Object.defineProperty(JoinClause.prototype, 'or', {
|
|
248
|
-
get() {
|
|
249
|
-
return this._bool('or');
|
|
250
|
-
},
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
JoinClause.prototype.andOn = JoinClause.prototype.on;
|
|
254
|
-
JoinClause.prototype.andOnIn = JoinClause.prototype.onIn;
|
|
255
|
-
JoinClause.prototype.andOnNotIn = JoinClause.prototype.onNotIn;
|
|
256
|
-
JoinClause.prototype.andOnNull = JoinClause.prototype.onNull;
|
|
257
|
-
JoinClause.prototype.andOnNotNull = JoinClause.prototype.onNotNull;
|
|
258
|
-
JoinClause.prototype.andOnExists = JoinClause.prototype.onExists;
|
|
259
|
-
JoinClause.prototype.andOnNotExists = JoinClause.prototype.onNotExists;
|
|
260
|
-
JoinClause.prototype.andOnBetween = JoinClause.prototype.onBetween;
|
|
261
|
-
JoinClause.prototype.andOnNotBetween = JoinClause.prototype.onNotBetween;
|
|
262
|
-
|
|
263
|
-
module.exports = JoinClause;
|
|
1
|
+
const assert = require('assert');
|
|
2
|
+
|
|
3
|
+
// JoinClause
|
|
4
|
+
// -------
|
|
5
|
+
|
|
6
|
+
// The "JoinClause" is an object holding any necessary info about a join,
|
|
7
|
+
// including the type, and any associated tables & columns being joined.
|
|
8
|
+
function JoinClause(table, type, schema) {
|
|
9
|
+
this.schema = schema;
|
|
10
|
+
this.table = table;
|
|
11
|
+
this.joinType = type;
|
|
12
|
+
this.and = this;
|
|
13
|
+
this.clauses = [];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function getClauseFromArguments(compilerType, bool, first, operator, second) {
|
|
17
|
+
let data = null;
|
|
18
|
+
|
|
19
|
+
if (typeof first === 'function') {
|
|
20
|
+
data = {
|
|
21
|
+
type: 'onWrapped',
|
|
22
|
+
value: first,
|
|
23
|
+
bool: bool,
|
|
24
|
+
};
|
|
25
|
+
} else {
|
|
26
|
+
switch (arguments.length) {
|
|
27
|
+
case 3: {
|
|
28
|
+
data = { type: 'onRaw', value: first, bool };
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
case 4:
|
|
32
|
+
data = {
|
|
33
|
+
type: compilerType,
|
|
34
|
+
column: first,
|
|
35
|
+
operator: '=',
|
|
36
|
+
value: operator,
|
|
37
|
+
bool,
|
|
38
|
+
};
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
data = {
|
|
42
|
+
type: compilerType,
|
|
43
|
+
column: first,
|
|
44
|
+
operator,
|
|
45
|
+
value: second,
|
|
46
|
+
bool,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return data;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
Object.assign(JoinClause.prototype, {
|
|
55
|
+
grouping: 'join',
|
|
56
|
+
|
|
57
|
+
// Adds an "on" clause to the current join object.
|
|
58
|
+
on(first) {
|
|
59
|
+
if (typeof first === 'object' && typeof first.toSQL !== 'function') {
|
|
60
|
+
const keys = Object.keys(first);
|
|
61
|
+
let i = -1;
|
|
62
|
+
const method = this._bool() === 'or' ? 'orOn' : 'on';
|
|
63
|
+
while (++i < keys.length) {
|
|
64
|
+
this[method](keys[i], first[keys[i]]);
|
|
65
|
+
}
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const data = getClauseFromArguments('onBasic', this._bool(), ...arguments);
|
|
70
|
+
|
|
71
|
+
if (data) {
|
|
72
|
+
this.clauses.push(data);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return this;
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
// Adds a "using" clause to the current join.
|
|
79
|
+
using(column) {
|
|
80
|
+
return this.clauses.push({ type: 'onUsing', column, bool: this._bool() });
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
/*// Adds an "and on" clause to the current join object.
|
|
84
|
+
andOn() {
|
|
85
|
+
return this.on.apply(this, arguments);
|
|
86
|
+
},*/
|
|
87
|
+
|
|
88
|
+
// Adds an "or on" clause to the current join object.
|
|
89
|
+
orOn(first, operator, second) {
|
|
90
|
+
return this._bool('or').on.apply(this, arguments);
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
onVal(first) {
|
|
94
|
+
if (typeof first === 'object' && typeof first.toSQL !== 'function') {
|
|
95
|
+
const keys = Object.keys(first);
|
|
96
|
+
let i = -1;
|
|
97
|
+
const method = this._bool() === 'or' ? 'orOnVal' : 'onVal';
|
|
98
|
+
while (++i < keys.length) {
|
|
99
|
+
this[method](keys[i], first[keys[i]]);
|
|
100
|
+
}
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const data = getClauseFromArguments('onVal', this._bool(), ...arguments);
|
|
105
|
+
|
|
106
|
+
if (data) {
|
|
107
|
+
this.clauses.push(data);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return this;
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
andOnVal() {
|
|
114
|
+
return this.onVal(...arguments);
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
orOnVal() {
|
|
118
|
+
return this._bool('or').onVal(...arguments);
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
onBetween(column, values) {
|
|
122
|
+
assert(
|
|
123
|
+
Array.isArray(values),
|
|
124
|
+
'The second argument to onBetween must be an array.'
|
|
125
|
+
);
|
|
126
|
+
assert(
|
|
127
|
+
values.length === 2,
|
|
128
|
+
'You must specify 2 values for the onBetween clause'
|
|
129
|
+
);
|
|
130
|
+
this.clauses.push({
|
|
131
|
+
type: 'onBetween',
|
|
132
|
+
column,
|
|
133
|
+
value: values,
|
|
134
|
+
bool: this._bool(),
|
|
135
|
+
not: this._not(),
|
|
136
|
+
});
|
|
137
|
+
return this;
|
|
138
|
+
},
|
|
139
|
+
|
|
140
|
+
onNotBetween(column, values) {
|
|
141
|
+
return this._not(true).onBetween(column, values);
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
orOnBetween(column, values) {
|
|
145
|
+
return this._bool('or').onBetween(column, values);
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
orOnNotBetween(column, values) {
|
|
149
|
+
return this._bool('or')._not(true).onBetween(column, values);
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
onIn(column, values) {
|
|
153
|
+
if (Array.isArray(values) && values.length === 0) return this.on(1, '=', 0);
|
|
154
|
+
this.clauses.push({
|
|
155
|
+
type: 'onIn',
|
|
156
|
+
column,
|
|
157
|
+
value: values,
|
|
158
|
+
not: this._not(),
|
|
159
|
+
bool: this._bool(),
|
|
160
|
+
});
|
|
161
|
+
return this;
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
onNotIn(column, values) {
|
|
165
|
+
return this._not(true).onIn(column, values);
|
|
166
|
+
},
|
|
167
|
+
|
|
168
|
+
orOnIn(column, values) {
|
|
169
|
+
return this._bool('or').onIn(column, values);
|
|
170
|
+
},
|
|
171
|
+
|
|
172
|
+
orOnNotIn(column, values) {
|
|
173
|
+
return this._bool('or')._not(true).onIn(column, values);
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
onNull(column) {
|
|
177
|
+
this.clauses.push({
|
|
178
|
+
type: 'onNull',
|
|
179
|
+
column,
|
|
180
|
+
not: this._not(),
|
|
181
|
+
bool: this._bool(),
|
|
182
|
+
});
|
|
183
|
+
return this;
|
|
184
|
+
},
|
|
185
|
+
|
|
186
|
+
orOnNull(callback) {
|
|
187
|
+
return this._bool('or').onNull(callback);
|
|
188
|
+
},
|
|
189
|
+
|
|
190
|
+
onNotNull(callback) {
|
|
191
|
+
return this._not(true).onNull(callback);
|
|
192
|
+
},
|
|
193
|
+
|
|
194
|
+
orOnNotNull(callback) {
|
|
195
|
+
return this._not(true)._bool('or').onNull(callback);
|
|
196
|
+
},
|
|
197
|
+
|
|
198
|
+
onExists(callback) {
|
|
199
|
+
this.clauses.push({
|
|
200
|
+
type: 'onExists',
|
|
201
|
+
value: callback,
|
|
202
|
+
not: this._not(),
|
|
203
|
+
bool: this._bool(),
|
|
204
|
+
});
|
|
205
|
+
return this;
|
|
206
|
+
},
|
|
207
|
+
|
|
208
|
+
orOnExists(callback) {
|
|
209
|
+
return this._bool('or').onExists(callback);
|
|
210
|
+
},
|
|
211
|
+
|
|
212
|
+
onNotExists(callback) {
|
|
213
|
+
return this._not(true).onExists(callback);
|
|
214
|
+
},
|
|
215
|
+
|
|
216
|
+
orOnNotExists(callback) {
|
|
217
|
+
return this._not(true)._bool('or').onExists(callback);
|
|
218
|
+
},
|
|
219
|
+
|
|
220
|
+
// Explicitly set the type of join, useful within a function when creating a grouped join.
|
|
221
|
+
type(type) {
|
|
222
|
+
this.joinType = type;
|
|
223
|
+
return this;
|
|
224
|
+
},
|
|
225
|
+
|
|
226
|
+
_bool(bool) {
|
|
227
|
+
if (arguments.length === 1) {
|
|
228
|
+
this._boolFlag = bool;
|
|
229
|
+
return this;
|
|
230
|
+
}
|
|
231
|
+
const ret = this._boolFlag || 'and';
|
|
232
|
+
this._boolFlag = 'and';
|
|
233
|
+
return ret;
|
|
234
|
+
},
|
|
235
|
+
|
|
236
|
+
_not(val) {
|
|
237
|
+
if (arguments.length === 1) {
|
|
238
|
+
this._notFlag = val;
|
|
239
|
+
return this;
|
|
240
|
+
}
|
|
241
|
+
const ret = this._notFlag;
|
|
242
|
+
this._notFlag = false;
|
|
243
|
+
return ret;
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
Object.defineProperty(JoinClause.prototype, 'or', {
|
|
248
|
+
get() {
|
|
249
|
+
return this._bool('or');
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
JoinClause.prototype.andOn = JoinClause.prototype.on;
|
|
254
|
+
JoinClause.prototype.andOnIn = JoinClause.prototype.onIn;
|
|
255
|
+
JoinClause.prototype.andOnNotIn = JoinClause.prototype.onNotIn;
|
|
256
|
+
JoinClause.prototype.andOnNull = JoinClause.prototype.onNull;
|
|
257
|
+
JoinClause.prototype.andOnNotNull = JoinClause.prototype.onNotNull;
|
|
258
|
+
JoinClause.prototype.andOnExists = JoinClause.prototype.onExists;
|
|
259
|
+
JoinClause.prototype.andOnNotExists = JoinClause.prototype.onNotExists;
|
|
260
|
+
JoinClause.prototype.andOnBetween = JoinClause.prototype.onBetween;
|
|
261
|
+
JoinClause.prototype.andOnNotBetween = JoinClause.prototype.onNotBetween;
|
|
262
|
+
|
|
263
|
+
module.exports = JoinClause;
|