knex 0.95.14 → 1.0.2
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 +90 -1
- package/README.md +1 -1
- package/UPGRADING.md +7 -0
- package/lib/client.js +14 -1
- package/lib/constants.js +2 -0
- package/lib/dialects/better-sqlite3/index.js +72 -0
- package/lib/dialects/cockroachdb/crdb-querycompiler.js +92 -33
- package/lib/dialects/cockroachdb/crdb-tablecompiler.js +19 -0
- package/lib/dialects/cockroachdb/index.js +13 -0
- package/lib/dialects/mssql/index.js +0 -11
- package/lib/dialects/mssql/query/mssql-querycompiler.js +122 -64
- package/lib/dialects/mssql/schema/mssql-columncompiler.js +41 -6
- package/lib/dialects/mssql/schema/mssql-compiler.js +3 -4
- package/lib/dialects/mssql/schema/mssql-tablecompiler.js +24 -9
- package/lib/dialects/mssql/schema/mssql-viewcompiler.js +15 -1
- package/lib/dialects/mysql/query/mysql-querycompiler.js +93 -5
- package/lib/dialects/mysql/schema/mysql-columncompiler.js +32 -5
- package/lib/dialects/mysql/schema/mysql-tablecompiler.js +33 -6
- package/lib/dialects/oracle/query/oracle-querycompiler.js +7 -6
- package/lib/dialects/oracle/schema/internal/trigger.js +1 -1
- package/lib/dialects/oracle/schema/oracle-columncompiler.js +10 -4
- package/lib/dialects/oracle/schema/oracle-tablecompiler.js +17 -6
- package/lib/dialects/oracledb/index.js +0 -4
- package/lib/dialects/oracledb/query/oracledb-querycompiler.js +89 -0
- package/lib/dialects/oracledb/schema/oracledb-columncompiler.js +23 -0
- package/lib/dialects/postgres/index.js +21 -6
- package/lib/dialects/postgres/query/pg-querybuilder.js +38 -0
- package/lib/dialects/postgres/query/pg-querycompiler.js +172 -9
- package/lib/dialects/postgres/schema/pg-columncompiler.js +24 -4
- package/lib/dialects/postgres/schema/pg-tablecompiler.js +63 -46
- package/lib/dialects/redshift/index.js +12 -0
- package/lib/dialects/redshift/query/redshift-querycompiler.js +62 -26
- package/lib/dialects/redshift/schema/redshift-columncompiler.js +2 -1
- package/lib/dialects/redshift/schema/redshift-tablecompiler.js +4 -1
- package/lib/dialects/sqlite3/index.js +23 -4
- package/lib/dialects/sqlite3/query/sqlite-querybuilder.js +33 -0
- package/lib/dialects/sqlite3/query/sqlite-querycompiler.js +87 -22
- package/lib/dialects/sqlite3/schema/ddl.js +274 -282
- package/lib/dialects/sqlite3/schema/internal/sqlite-ddl-operations.js +18 -8
- package/lib/dialects/sqlite3/schema/sqlite-columncompiler.js +20 -0
- package/lib/dialects/sqlite3/schema/sqlite-compiler.js +16 -12
- package/lib/dialects/sqlite3/schema/sqlite-tablecompiler.js +15 -5
- package/lib/dialects/sqlite3/schema/sqlite-viewcompiler.js +31 -2
- package/lib/execution/runner.js +37 -2
- package/lib/knex-builder/FunctionHelper.js +36 -0
- package/lib/migrations/common/MigrationsLoader.js +36 -0
- package/lib/migrations/migrate/MigrationGenerator.js +1 -1
- package/lib/migrations/migrate/Migrator.js +22 -24
- package/lib/migrations/migrate/migration-list-resolver.js +2 -5
- package/lib/migrations/migrate/{configuration-merger.js → migrator-configuration-merger.js} +2 -4
- package/lib/migrations/migrate/sources/fs-migrations.js +4 -29
- package/lib/migrations/migrate/stub/js.stub +8 -1
- package/lib/migrations/migrate/stub/knexfile-js.stub +3 -0
- package/lib/migrations/migrate/stub/knexfile-ts.stub +5 -2
- package/lib/migrations/migrate/table-creator.js +6 -5
- package/lib/migrations/seed/Seeder.js +25 -92
- package/lib/migrations/seed/seeder-configuration-merger.js +60 -0
- package/lib/migrations/seed/sources/fs-seeds.js +65 -0
- package/lib/migrations/seed/stub/js.stub +4 -1
- package/lib/migrations/util/import-file.js +0 -1
- package/lib/query/joinclause.js +24 -5
- package/lib/query/method-constants.js +37 -0
- package/lib/query/querybuilder.js +292 -53
- package/lib/query/querycompiler.js +309 -85
- package/lib/schema/columnbuilder.js +14 -1
- package/lib/schema/columncompiler.js +132 -5
- package/lib/schema/compiler.js +1 -0
- package/lib/schema/tablebuilder.js +41 -8
- package/lib/schema/tablecompiler.js +61 -4
- package/lib/schema/viewcompiler.js +13 -10
- package/package.json +37 -27
- package/scripts/docker-compose.yml +7 -7
- package/scripts/oracledb-install-driver-libs.sh +82 -0
- package/scripts/runkit-example.js +1 -1
- package/scripts/stress-test/docker-compose.yml +3 -3
- package/scripts/stress-test/knex-stress-test.js +1 -1
- package/scripts/stress-test/reconnect-test-mysql-based-drivers.js +1 -1
- package/types/index.d.ts +133 -21
|
@@ -9,6 +9,7 @@ const has = require('lodash/has');
|
|
|
9
9
|
const tail = require('lodash/tail');
|
|
10
10
|
const { toNumber } = require('../util/helpers');
|
|
11
11
|
const { formatDefault } = require('../formatter/formatterUtils');
|
|
12
|
+
const { operator: operator_ } = require('../formatter/wrappingFormatter');
|
|
12
13
|
|
|
13
14
|
class ColumnCompiler {
|
|
14
15
|
constructor(client, tableCompiler, columnBuilder) {
|
|
@@ -29,6 +30,21 @@ class ColumnCompiler {
|
|
|
29
30
|
|
|
30
31
|
this.sequence = [];
|
|
31
32
|
this.modifiers = [];
|
|
33
|
+
|
|
34
|
+
this.checksCount = 0;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
_addCheckModifiers() {
|
|
38
|
+
this.modifiers.push(
|
|
39
|
+
'check',
|
|
40
|
+
'checkPositive',
|
|
41
|
+
'checkNegative',
|
|
42
|
+
'checkIn',
|
|
43
|
+
'checkNotIn',
|
|
44
|
+
'checkBetween',
|
|
45
|
+
'checkLength',
|
|
46
|
+
'checkRegex'
|
|
47
|
+
);
|
|
32
48
|
}
|
|
33
49
|
|
|
34
50
|
defaults(label) {
|
|
@@ -134,6 +150,120 @@ class ColumnCompiler {
|
|
|
134
150
|
defaultTo(value) {
|
|
135
151
|
return `default ${formatDefault(value, this.type, this.client)}`;
|
|
136
152
|
}
|
|
153
|
+
|
|
154
|
+
increments(options = { primaryKey: true }) {
|
|
155
|
+
return (
|
|
156
|
+
'integer not null' +
|
|
157
|
+
(this.tableCompiler._canBeAddPrimaryKey(options) ? ' primary key' : '') +
|
|
158
|
+
' autoincrement'
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
bigincrements(options = { primaryKey: true }) {
|
|
163
|
+
return this.increments(options);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
_pushAlterCheckQuery(checkPredicate, constraintName) {
|
|
167
|
+
let checkName = constraintName;
|
|
168
|
+
if (!checkName) {
|
|
169
|
+
this.checksCount++;
|
|
170
|
+
checkName =
|
|
171
|
+
this.tableCompiler.tableNameRaw +
|
|
172
|
+
'_' +
|
|
173
|
+
this.getColumnName() +
|
|
174
|
+
'_' +
|
|
175
|
+
this.checksCount;
|
|
176
|
+
}
|
|
177
|
+
this.pushAdditional(function () {
|
|
178
|
+
this.pushQuery(
|
|
179
|
+
`alter table ${this.tableCompiler.tableName()} add constraint ${checkName} check(${checkPredicate})`
|
|
180
|
+
);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
_checkConstraintName(constraintName) {
|
|
185
|
+
return constraintName ? `constraint ${constraintName} ` : '';
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
_check(checkPredicate, constraintName) {
|
|
189
|
+
if (this.columnBuilder._method === 'alter') {
|
|
190
|
+
this._pushAlterCheckQuery(checkPredicate, constraintName);
|
|
191
|
+
return '';
|
|
192
|
+
}
|
|
193
|
+
return `${this._checkConstraintName(
|
|
194
|
+
constraintName
|
|
195
|
+
)}check (${checkPredicate})`;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
checkPositive(constraintName) {
|
|
199
|
+
return this._check(
|
|
200
|
+
`${this.formatter.wrap(this.getColumnName())} ${operator_(
|
|
201
|
+
'>',
|
|
202
|
+
this.columnBuilder,
|
|
203
|
+
this.bindingsHolder
|
|
204
|
+
)} 0`,
|
|
205
|
+
constraintName
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
checkNegative(constraintName) {
|
|
210
|
+
return this._check(
|
|
211
|
+
`${this.formatter.wrap(this.getColumnName())} ${operator_(
|
|
212
|
+
'<',
|
|
213
|
+
this.columnBuilder,
|
|
214
|
+
this.bindingsHolder
|
|
215
|
+
)} 0`,
|
|
216
|
+
constraintName
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
_checkIn(values, constraintName, not) {
|
|
221
|
+
return this._check(
|
|
222
|
+
`${this.formatter.wrap(this.getColumnName())} ${
|
|
223
|
+
not ? 'not ' : ''
|
|
224
|
+
}in (${values.map((v) => this.client._escapeBinding(v)).join(',')})`,
|
|
225
|
+
constraintName
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
checkIn(values, constraintName) {
|
|
230
|
+
return this._checkIn(values, constraintName);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
checkNotIn(values, constraintName) {
|
|
234
|
+
return this._checkIn(values, constraintName, true);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
checkBetween(intervals, constraintName) {
|
|
238
|
+
if (
|
|
239
|
+
intervals.length === 2 &&
|
|
240
|
+
!Array.isArray(intervals[0]) &&
|
|
241
|
+
!Array.isArray(intervals[1])
|
|
242
|
+
) {
|
|
243
|
+
intervals = [intervals];
|
|
244
|
+
}
|
|
245
|
+
const intervalChecks = intervals
|
|
246
|
+
.map((interval) => {
|
|
247
|
+
return `${this.formatter.wrap(
|
|
248
|
+
this.getColumnName()
|
|
249
|
+
)} between ${this.client._escapeBinding(
|
|
250
|
+
interval[0]
|
|
251
|
+
)} and ${this.client._escapeBinding(interval[1])}`;
|
|
252
|
+
})
|
|
253
|
+
.join(' or ');
|
|
254
|
+
return this._check(intervalChecks, constraintName);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
checkLength(operator, length, constraintName) {
|
|
258
|
+
return this._check(
|
|
259
|
+
`length(${this.formatter.wrap(this.getColumnName())}) ${operator_(
|
|
260
|
+
operator,
|
|
261
|
+
this.columnBuilder,
|
|
262
|
+
this.bindingsHolder
|
|
263
|
+
)} ${toNumber(length)}`,
|
|
264
|
+
constraintName
|
|
265
|
+
);
|
|
266
|
+
}
|
|
137
267
|
}
|
|
138
268
|
|
|
139
269
|
ColumnCompiler.prototype.binary = 'blob';
|
|
@@ -147,11 +277,8 @@ ColumnCompiler.prototype.geography = 'geography';
|
|
|
147
277
|
ColumnCompiler.prototype.point = 'point';
|
|
148
278
|
ColumnCompiler.prototype.enu = 'varchar';
|
|
149
279
|
ColumnCompiler.prototype.bit = ColumnCompiler.prototype.json = 'text';
|
|
150
|
-
ColumnCompiler.prototype.uuid =
|
|
151
|
-
|
|
152
|
-
'integer not null' + (primaryKey ? ' primary key' : '') + ' autoincrement';
|
|
153
|
-
ColumnCompiler.prototype.bigincrements = ({ primaryKey = true } = {}) =>
|
|
154
|
-
'integer not null' + (primaryKey ? ' primary key' : '') + ' autoincrement';
|
|
280
|
+
ColumnCompiler.prototype.uuid = ({ useBinaryUuid = false } = {}) =>
|
|
281
|
+
useBinaryUuid ? 'binary(16)' : 'char(36)';
|
|
155
282
|
ColumnCompiler.prototype.integer =
|
|
156
283
|
ColumnCompiler.prototype.smallint =
|
|
157
284
|
ColumnCompiler.prototype.mediumint =
|
package/lib/schema/compiler.js
CHANGED
|
@@ -10,7 +10,7 @@ const each = require('lodash/each');
|
|
|
10
10
|
const extend = require('lodash/extend');
|
|
11
11
|
const toArray = require('lodash/toArray');
|
|
12
12
|
const helpers = require('../util/helpers');
|
|
13
|
-
const { isString, isFunction } = require('../util/is');
|
|
13
|
+
const { isString, isFunction, isObject } = require('../util/is');
|
|
14
14
|
|
|
15
15
|
class TableBuilder {
|
|
16
16
|
constructor(client, method, tableName, tableNameLike, fn) {
|
|
@@ -50,16 +50,20 @@ class TableBuilder {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
// The "timestamps" call is really just sets the `created_at` and `updated_at` columns.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
|
|
54
|
+
timestamps(useTimestamps, defaultToNow, useCamelCase) {
|
|
55
|
+
if (isObject(useTimestamps)) {
|
|
56
|
+
({ useTimestamps, defaultToNow, useCamelCase } = useTimestamps);
|
|
57
|
+
}
|
|
58
|
+
const method = useTimestamps === true ? 'timestamp' : 'datetime';
|
|
59
|
+
const createdAt = this[method](useCamelCase ? 'createdAt' : 'created_at');
|
|
60
|
+
const updatedAt = this[method](useCamelCase ? 'updatedAt' : 'updated_at');
|
|
61
|
+
|
|
62
|
+
if (defaultToNow === true) {
|
|
58
63
|
const now = this.client.raw('CURRENT_TIMESTAMP');
|
|
59
64
|
createdAt.notNullable().defaultTo(now);
|
|
60
65
|
updatedAt.notNullable().defaultTo(now);
|
|
61
66
|
}
|
|
62
|
-
return;
|
|
63
67
|
}
|
|
64
68
|
|
|
65
69
|
// Set the comment value for a table, they're only allowed to be called
|
|
@@ -142,6 +146,14 @@ class TableBuilder {
|
|
|
142
146
|
};
|
|
143
147
|
return returnObj;
|
|
144
148
|
}
|
|
149
|
+
|
|
150
|
+
check(checkPredicate, bindings, constraintName) {
|
|
151
|
+
this._statements.push({
|
|
152
|
+
grouping: 'checks',
|
|
153
|
+
args: [checkPredicate, bindings, constraintName],
|
|
154
|
+
});
|
|
155
|
+
return this;
|
|
156
|
+
}
|
|
145
157
|
}
|
|
146
158
|
|
|
147
159
|
[
|
|
@@ -290,7 +302,12 @@ const AlterMethods = {
|
|
|
290
302
|
},
|
|
291
303
|
|
|
292
304
|
dropTimestamps() {
|
|
293
|
-
|
|
305
|
+
// arguments[0] = useCamelCase
|
|
306
|
+
return this.dropColumns(
|
|
307
|
+
arguments[0] === true
|
|
308
|
+
? ['createdAt', 'updatedAt']
|
|
309
|
+
: ['created_at', 'updated_at']
|
|
310
|
+
);
|
|
294
311
|
},
|
|
295
312
|
|
|
296
313
|
setNullable(column) {
|
|
@@ -303,6 +320,22 @@ const AlterMethods = {
|
|
|
303
320
|
return this;
|
|
304
321
|
},
|
|
305
322
|
|
|
323
|
+
check(checkPredicate, bindings, constraintName) {
|
|
324
|
+
this._statements.push({
|
|
325
|
+
grouping: 'alterTable',
|
|
326
|
+
method: 'check',
|
|
327
|
+
args: [checkPredicate, bindings, constraintName],
|
|
328
|
+
});
|
|
329
|
+
},
|
|
330
|
+
|
|
331
|
+
dropChecks() {
|
|
332
|
+
this._statements.push({
|
|
333
|
+
grouping: 'alterTable',
|
|
334
|
+
method: 'dropChecks',
|
|
335
|
+
args: toArray(arguments),
|
|
336
|
+
});
|
|
337
|
+
},
|
|
338
|
+
|
|
306
339
|
dropNullable(column) {
|
|
307
340
|
this._statements.push({
|
|
308
341
|
grouping: 'alterTable',
|
|
@@ -12,6 +12,7 @@ const groupBy = require('lodash/groupBy');
|
|
|
12
12
|
const indexOf = require('lodash/indexOf');
|
|
13
13
|
const isEmpty = require('lodash/isEmpty');
|
|
14
14
|
const tail = require('lodash/tail');
|
|
15
|
+
const { normalizeArr } = require('../util/helpers');
|
|
15
16
|
|
|
16
17
|
class TableCompiler {
|
|
17
18
|
constructor(client, tableBuilder) {
|
|
@@ -32,6 +33,8 @@ class TableCompiler {
|
|
|
32
33
|
|
|
33
34
|
this.sequence = [];
|
|
34
35
|
this._formatting = client.config && client.config.formatting;
|
|
36
|
+
|
|
37
|
+
this.checksCount = 0;
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
// Convert the tableCompiler toSQL
|
|
@@ -124,9 +127,9 @@ class TableCompiler {
|
|
|
124
127
|
' (' +
|
|
125
128
|
references +
|
|
126
129
|
')' +
|
|
127
|
-
deferrable +
|
|
128
130
|
onUpdate +
|
|
129
|
-
onDelete
|
|
131
|
+
onDelete +
|
|
132
|
+
deferrable
|
|
130
133
|
);
|
|
131
134
|
} else {
|
|
132
135
|
this.pushQuery(
|
|
@@ -141,9 +144,9 @@ class TableCompiler {
|
|
|
141
144
|
' (' +
|
|
142
145
|
references +
|
|
143
146
|
')' +
|
|
144
|
-
deferrable +
|
|
145
147
|
onUpdate +
|
|
146
|
-
onDelete
|
|
148
|
+
onDelete +
|
|
149
|
+
deferrable
|
|
147
150
|
);
|
|
148
151
|
}
|
|
149
152
|
}
|
|
@@ -346,6 +349,43 @@ class TableCompiler {
|
|
|
346
349
|
return this._setNullableState(column, false);
|
|
347
350
|
}
|
|
348
351
|
|
|
352
|
+
dropChecks(checkConstraintNames) {
|
|
353
|
+
if (checkConstraintNames === undefined) return '';
|
|
354
|
+
checkConstraintNames = normalizeArr(checkConstraintNames);
|
|
355
|
+
const tableName = this.tableName();
|
|
356
|
+
const sql = `alter table ${tableName} ${checkConstraintNames
|
|
357
|
+
.map((constraint) => `drop constraint ${constraint}`)
|
|
358
|
+
.join(', ')}`;
|
|
359
|
+
this.pushQuery(sql);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
check(checkPredicate, bindings, constraintName) {
|
|
363
|
+
const tableName = this.tableName();
|
|
364
|
+
let checkConstraint = constraintName;
|
|
365
|
+
if (!checkConstraint) {
|
|
366
|
+
this.checksCount++;
|
|
367
|
+
checkConstraint = tableName + '_' + this.checksCount;
|
|
368
|
+
}
|
|
369
|
+
const sql = `alter table ${tableName} add constraint ${checkConstraint} check(${checkPredicate})`;
|
|
370
|
+
this.pushQuery(sql);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
_addChecks() {
|
|
374
|
+
if (this.grouped.checks) {
|
|
375
|
+
return (
|
|
376
|
+
', ' +
|
|
377
|
+
this.grouped.checks
|
|
378
|
+
.map((c) => {
|
|
379
|
+
return `${
|
|
380
|
+
c.args[2] ? 'constraint ' + c.args[2] + ' ' : ''
|
|
381
|
+
}check (${this.client.raw(c.args[0], c.args[1])})`;
|
|
382
|
+
})
|
|
383
|
+
.join(', ')
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
return '';
|
|
387
|
+
}
|
|
388
|
+
|
|
349
389
|
// If no name was specified for this index, we will create one using a basic
|
|
350
390
|
// convention of the table name, followed by the columns, followed by an
|
|
351
391
|
// index type, such as primary or index, which makes the index unique.
|
|
@@ -361,6 +401,23 @@ class TableCompiler {
|
|
|
361
401
|
).toLowerCase();
|
|
362
402
|
return this.formatter.wrap(indexName);
|
|
363
403
|
}
|
|
404
|
+
|
|
405
|
+
_getPrimaryKeys() {
|
|
406
|
+
return (this.grouped.alterTable || [])
|
|
407
|
+
.filter((a) => a.method === 'primary')
|
|
408
|
+
.flatMap((a) => a.args)
|
|
409
|
+
.flat();
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
_canBeAddPrimaryKey(options) {
|
|
413
|
+
return options.primaryKey && this._getPrimaryKeys().length === 0;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
_getIncrementsColumnNames() {
|
|
417
|
+
return this.grouped.columns
|
|
418
|
+
.filter((c) => c.builder._type === 'increments')
|
|
419
|
+
.map((c) => c.builder._args[0]);
|
|
420
|
+
}
|
|
364
421
|
}
|
|
365
422
|
|
|
366
423
|
TableCompiler.prototype.pushQuery = pushQuery;
|
|
@@ -52,16 +52,19 @@ class ViewCompiler {
|
|
|
52
52
|
const createStatement =
|
|
53
53
|
'create ' +
|
|
54
54
|
(materialized ? 'materialized ' : '') +
|
|
55
|
-
'
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
(replace ? 'or replace ' : '') +
|
|
56
|
+
'view ';
|
|
57
|
+
const columnList = columns
|
|
58
|
+
? ' (' +
|
|
59
|
+
columnize_(
|
|
60
|
+
columns,
|
|
61
|
+
this.viewBuilder,
|
|
62
|
+
this.client,
|
|
63
|
+
this.bindingsHolder
|
|
64
|
+
) +
|
|
65
|
+
')'
|
|
66
|
+
: '';
|
|
67
|
+
let sql = createStatement + this.viewName() + columnList;
|
|
65
68
|
sql += ' as ';
|
|
66
69
|
sql += selectQuery.toString();
|
|
67
70
|
switch (this.single.checkOption) {
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "knex",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "A batteries-included SQL query & schema builder for PostgresSQL, MySQL, CockroachDB, MSSQL and SQLite3",
|
|
5
5
|
"main": "knex",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
7
7
|
"engines": {
|
|
8
|
-
"node": ">=
|
|
8
|
+
"node": ">=12"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"format": "prettier --write \"{lib,bin,scripts,test}/**/*.js\"",
|
|
@@ -28,12 +28,13 @@
|
|
|
28
28
|
"test:mysql2": "cross-env DB=mysql2 npm run test:db",
|
|
29
29
|
"test:oracledb": "cross-env DB=oracledb npm run test:db",
|
|
30
30
|
"test:sqlite": "cross-env DB=sqlite3 npm run test:db",
|
|
31
|
+
"test:better-sqlite3": "cross-env DB=better-sqlite3 npm run test:db",
|
|
31
32
|
"test:postgres": "cross-env DB=postgres npm run test:db",
|
|
32
33
|
"test:cockroachdb": "cross-env DB=cockroachdb npm run test:db",
|
|
33
34
|
"test:pgnative": "cross-env DB=pgnative npm run test:db",
|
|
34
35
|
"test:tape": "node test/tape/index.js | tap-spec",
|
|
35
36
|
"test:cli": "cross-env KNEX_PATH=../knex.js KNEX=bin/cli.js jake -f test/jake/Jakefile",
|
|
36
|
-
"db:start": "docker-compose -f scripts/docker-compose.yml up --build -d mysql
|
|
37
|
+
"db:start": "docker-compose -f scripts/docker-compose.yml up --build -d mysql oracledb postgres mssql cockroachdb pgnative && docker-compose -f scripts/docker-compose.yml up waitmssql waitmysql waitpostgres waitoracledb",
|
|
37
38
|
"db:start:no-oracle": "docker-compose -f scripts/docker-compose.yml up --build -d mysql postgres mssql cockroachdb pgnative && docker-compose -f scripts/docker-compose.yml up waitmssql waitmysql waitpostgres",
|
|
38
39
|
"db:stop": "docker-compose -f scripts/docker-compose.yml down",
|
|
39
40
|
"db:start:postgres": "docker-compose -f scripts/docker-compose.yml up --build -d postgres && docker-compose -f scripts/docker-compose.yml up waitpostgres",
|
|
@@ -46,7 +47,7 @@
|
|
|
46
47
|
"db:stop:mssql": "docker-compose -f scripts/docker-compose.yml down",
|
|
47
48
|
"db:start:cockroachdb": "docker-compose -f scripts/docker-compose.yml up --build -d cockroachdb && docker-compose -f scripts/docker-compose.yml up waitcockroachdb",
|
|
48
49
|
"db:stop:cockroachdb": "docker-compose -f scripts/docker-compose.yml down",
|
|
49
|
-
"db:start:oracle": "docker-compose -f scripts/docker-compose.yml up --build -d
|
|
50
|
+
"db:start:oracle": "docker-compose -f scripts/docker-compose.yml up --build -d oracledb && docker-compose -f scripts/docker-compose.yml up waitoracledb",
|
|
50
51
|
"db:stop:oracle": "docker-compose -f scripts/docker-compose.yml down",
|
|
51
52
|
"stress:init": "docker-compose -f scripts/stress-test/docker-compose.yml up --no-start && docker-compose -f scripts/stress-test/docker-compose.yml start",
|
|
52
53
|
"stress:test": "node scripts/stress-test/knex-stress-test.js | grep -A 5 -B 60 -- '- STATS '",
|
|
@@ -54,17 +55,17 @@
|
|
|
54
55
|
},
|
|
55
56
|
"dependencies": {
|
|
56
57
|
"colorette": "2.0.16",
|
|
57
|
-
"commander": "^
|
|
58
|
-
"debug": "4.3.
|
|
58
|
+
"commander": "^8.3.0",
|
|
59
|
+
"debug": "4.3.3",
|
|
59
60
|
"escalade": "^3.1.1",
|
|
60
61
|
"esm": "^3.2.25",
|
|
61
|
-
"getopts": "2.
|
|
62
|
+
"getopts": "2.3.0",
|
|
62
63
|
"interpret": "^2.2.0",
|
|
63
64
|
"lodash": "^4.17.21",
|
|
64
65
|
"pg-connection-string": "2.5.0",
|
|
65
|
-
"rechoir": "0.
|
|
66
|
+
"rechoir": "^0.8.0",
|
|
66
67
|
"resolve-from": "^5.0.0",
|
|
67
|
-
"tarn": "^3.0.
|
|
68
|
+
"tarn": "^3.0.2",
|
|
68
69
|
"tildify": "2.0.0"
|
|
69
70
|
},
|
|
70
71
|
"peerDependenciesMeta": {
|
|
@@ -83,7 +84,10 @@
|
|
|
83
84
|
"pg-native": {
|
|
84
85
|
"optional": true
|
|
85
86
|
},
|
|
86
|
-
"sqlite3": {
|
|
87
|
+
"@vscode/sqlite3": {
|
|
88
|
+
"optional": true
|
|
89
|
+
},
|
|
90
|
+
"better-sqlite3": {
|
|
87
91
|
"optional": true
|
|
88
92
|
}
|
|
89
93
|
},
|
|
@@ -94,42 +98,43 @@
|
|
|
94
98
|
]
|
|
95
99
|
},
|
|
96
100
|
"devDependencies": {
|
|
97
|
-
"@types/node": "^16.
|
|
98
|
-
"
|
|
101
|
+
"@types/node": "^16.11.22",
|
|
102
|
+
"@vscode/sqlite3": "^5.0.7",
|
|
103
|
+
"better-sqlite3": "^7.5.0",
|
|
104
|
+
"chai": "^4.3.6",
|
|
99
105
|
"chai-as-promised": "^7.1.1",
|
|
100
106
|
"chai-subset-in-order": "^3.1.0",
|
|
101
107
|
"cli-testlab": "^2.2.0",
|
|
102
108
|
"coveralls": "^3.1.1",
|
|
103
109
|
"cross-env": "^7.0.3",
|
|
104
|
-
"dtslint": "4.2.
|
|
105
|
-
"eslint": "^8.
|
|
110
|
+
"dtslint": "4.2.1",
|
|
111
|
+
"eslint": "^8.8.0",
|
|
106
112
|
"eslint-config-prettier": "^8.3.0",
|
|
107
|
-
"eslint-plugin-import": "^2.25.
|
|
113
|
+
"eslint-plugin-import": "^2.25.4",
|
|
108
114
|
"husky": "^4.3.8",
|
|
109
115
|
"jake": "^8.1.1",
|
|
110
116
|
"JSONStream": "^1.3.5",
|
|
111
117
|
"lint-staged": "^11.1.2",
|
|
112
|
-
"mocha": "^9.
|
|
113
|
-
"mock-fs": "^
|
|
118
|
+
"mocha": "^9.2.0",
|
|
119
|
+
"mock-fs": "^5.1.2",
|
|
114
120
|
"mysql": "^2.18.1",
|
|
115
|
-
"mysql2": "^2.3.
|
|
121
|
+
"mysql2": "^2.3.3",
|
|
116
122
|
"nyc": "^15.1.0",
|
|
117
|
-
"oracledb": "^5.
|
|
123
|
+
"oracledb": "^5.3.0",
|
|
118
124
|
"pg": "^8.7.1",
|
|
119
125
|
"pg-query-stream": "^4.2.1",
|
|
120
126
|
"prettier": "2.4.1",
|
|
121
127
|
"rimraf": "^3.0.2",
|
|
122
|
-
"sinon": "^
|
|
128
|
+
"sinon": "^13.0.1",
|
|
123
129
|
"sinon-chai": "^3.7.0",
|
|
124
|
-
"source-map-support": "^0.5.
|
|
125
|
-
"sqlite3": "^5.0.2",
|
|
130
|
+
"source-map-support": "^0.5.21",
|
|
126
131
|
"tap-spec": "^5.0.0",
|
|
127
|
-
"tape": "^5.
|
|
128
|
-
"tedious": "^12.
|
|
132
|
+
"tape": "^5.5.0",
|
|
133
|
+
"tedious": "^12.3.0",
|
|
129
134
|
"toxiproxy-node-client": "^2.0.6",
|
|
130
|
-
"ts-node": "^10.
|
|
131
|
-
"tsd": "^0.
|
|
132
|
-
"typescript": "4.
|
|
135
|
+
"ts-node": "^10.4.0",
|
|
136
|
+
"tsd": "^0.19.1",
|
|
137
|
+
"typescript": "4.5.5"
|
|
133
138
|
},
|
|
134
139
|
"buildDependencies": [
|
|
135
140
|
"rimraf"
|
|
@@ -180,6 +185,9 @@
|
|
|
180
185
|
{
|
|
181
186
|
"name": "Brian Lauber",
|
|
182
187
|
"web": "https://briandamaged.org"
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
"name": "Olivier Cavadenti"
|
|
183
191
|
}
|
|
184
192
|
],
|
|
185
193
|
"browser": {
|
|
@@ -194,6 +202,8 @@
|
|
|
194
202
|
"pg-query-stream": false,
|
|
195
203
|
"oracle": false,
|
|
196
204
|
"sqlite3": false,
|
|
205
|
+
"@vscode/sqlite3": false,
|
|
206
|
+
"better-sqlite3": false,
|
|
197
207
|
"oracledb": false
|
|
198
208
|
},
|
|
199
209
|
"react-native": {
|
|
@@ -85,7 +85,7 @@ services:
|
|
|
85
85
|
- 'until /usr/local/bin/psql postgres://testuser:knextest@postgres/knex_test -c "SELECT 1"; do sleep 5; done'
|
|
86
86
|
|
|
87
87
|
cockroachdb:
|
|
88
|
-
image: cockroachdb/cockroach:latest-v21.
|
|
88
|
+
image: cockroachdb/cockroach:latest-v21.2
|
|
89
89
|
container_name: crdb
|
|
90
90
|
hostname: crdb
|
|
91
91
|
command: start-single-node --cluster-name=example-single-node --insecure
|
|
@@ -125,25 +125,25 @@ services:
|
|
|
125
125
|
- -c
|
|
126
126
|
- 'until /usr/local/bin/psql postgres://testuser:knextest@pgnative/knex_test -c "SELECT 1"; do sleep 5; done'
|
|
127
127
|
|
|
128
|
-
|
|
128
|
+
oracledb:
|
|
129
129
|
image: quillbuilduser/oracle-18-xe
|
|
130
|
-
container_name:
|
|
130
|
+
container_name: oracledb_container
|
|
131
131
|
ports:
|
|
132
132
|
- '21521:1521'
|
|
133
133
|
environment:
|
|
134
134
|
- ORACLE_ALLOW_REMOTE=true
|
|
135
|
-
|
|
135
|
+
waitoracledb:
|
|
136
136
|
image: quillbuilduser/oracle-18-xe
|
|
137
137
|
links:
|
|
138
|
-
-
|
|
138
|
+
- oracledb
|
|
139
139
|
depends_on:
|
|
140
|
-
-
|
|
140
|
+
- oracledb
|
|
141
141
|
environment:
|
|
142
142
|
- ORACLE_HOME=/opt/oracle/product/18c/dbhomeXE
|
|
143
143
|
entrypoint:
|
|
144
144
|
- bash
|
|
145
145
|
- -c
|
|
146
|
-
- 'until /opt/oracle/product/18c/dbhomeXE/bin/sqlplus -s sys/Oracle18@
|
|
146
|
+
- 'until /opt/oracle/product/18c/dbhomeXE/bin/sqlplus -s sys/Oracle18@oracledb/XE as sysdba <<< "SELECT 13376411 FROM DUAL; exit;" | grep "13376411"; do echo "Could not connect to oracle... sleep for a while"; sleep 5; done'
|
|
147
147
|
|
|
148
148
|
volumes:
|
|
149
149
|
mysql_data:
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
# Exit on error
|
|
4
|
+
set -e
|
|
5
|
+
|
|
6
|
+
# Directory constants
|
|
7
|
+
repo_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." >/dev/null 2>&1 && pwd )"
|
|
8
|
+
exec_dir="$( pwd )"
|
|
9
|
+
script_dir="$repo_dir/scripts/"
|
|
10
|
+
docker_compose_file="$repo_dir/scripts/docker-compose.yml"
|
|
11
|
+
|
|
12
|
+
help_text="
|
|
13
|
+
Helper script to install oracle drivers on local linux machine from Oracle
|
|
14
|
+
database container.
|
|
15
|
+
|
|
16
|
+
oracledb-install-driver-libs.sh COMMAND
|
|
17
|
+
|
|
18
|
+
COMMAND:
|
|
19
|
+
run: Do the driver install.
|
|
20
|
+
dry-run: Do the driver install but do not save any files.
|
|
21
|
+
help: Print this menu.
|
|
22
|
+
|
|
23
|
+
NOTES FOR USAGE:
|
|
24
|
+
1. This script is tested to work on Ubuntu 18.04 LTS.
|
|
25
|
+
2. This script requires you to have sudo capabilities so to use ldconfig.
|
|
26
|
+
"
|
|
27
|
+
|
|
28
|
+
# Main script logic
|
|
29
|
+
cmd="$1"
|
|
30
|
+
|
|
31
|
+
function main () {
|
|
32
|
+
case "$1" in
|
|
33
|
+
"run")
|
|
34
|
+
printf "Starting run ...\n"
|
|
35
|
+
do_install true
|
|
36
|
+
exit 0
|
|
37
|
+
;;
|
|
38
|
+
"dry-run")
|
|
39
|
+
printf "Starting dry-run ...\n"
|
|
40
|
+
do_install false
|
|
41
|
+
exit 0
|
|
42
|
+
;;
|
|
43
|
+
"help"|"--help"|"-h"|"")
|
|
44
|
+
printf "$help_text"
|
|
45
|
+
exit 0
|
|
46
|
+
;;
|
|
47
|
+
*)
|
|
48
|
+
printf "Unsupported command: $cmd\n"
|
|
49
|
+
printf "Try running with 'help' to see supported commands.\n"
|
|
50
|
+
exit 1
|
|
51
|
+
;;
|
|
52
|
+
esac
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function do_install () {
|
|
56
|
+
do_changes="$1"
|
|
57
|
+
printf "\nEnsuring oracle containers from docker-compose are up ...\n"
|
|
58
|
+
docker-compose -f "$docker_compose_file" up --build -d oracledb
|
|
59
|
+
docker-compose -f "$docker_compose_file" up waitoracledb
|
|
60
|
+
printf "\nSleeping an extra 15 seconds to ensure oracle has fully started ...\n"
|
|
61
|
+
sleep 15
|
|
62
|
+
printf "\nInstalling oracle client libs to db container ...\n"
|
|
63
|
+
set -x
|
|
64
|
+
docker-compose -f "$docker_compose_file" exec -T oracledb curl http://yum.oracle.com/public-yum-ol7.repo -o /etc/yum.repos.d/public-yum-ol7.repo
|
|
65
|
+
docker-compose -f "$docker_compose_file" exec -T oracledb yum install -y yum-utils
|
|
66
|
+
docker-compose -f "$docker_compose_file" exec -T oracledb yum-config-manager --enable ol7_oracle_instantclient
|
|
67
|
+
docker-compose -f "$docker_compose_file" exec -T oracledb yum install -y oracle-instantclient18.3-basiclite
|
|
68
|
+
set +x
|
|
69
|
+
printf "\nCopying to host's ~/lib directory and adding to ldconfig ...\n"
|
|
70
|
+
if [ "$do_changes" = "true" ]; then
|
|
71
|
+
set -x
|
|
72
|
+
docker cp oracledb_container:/usr/lib/oracle/18.3/client64/lib/ ~/
|
|
73
|
+
sudo sh -c "echo $HOME/lib > /etc/ld.so.conf.d/oracle-instantclient.conf"
|
|
74
|
+
sudo ldconfig
|
|
75
|
+
set +x
|
|
76
|
+
else
|
|
77
|
+
printf "(skipping because dry-run)\n"
|
|
78
|
+
fi
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
# Start the bash app's main function
|
|
82
|
+
main "$cmd"
|