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/helpers.js
CHANGED
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
const isPlainObject = require('lodash/isPlainObject');
|
|
2
|
-
const isTypedArray = require('lodash/isTypedArray');
|
|
3
|
-
const { CLIENT_ALIASES } = require('./constants');
|
|
4
|
-
const { isFunction } = require('./util/is');
|
|
5
|
-
|
|
6
|
-
// Check if the first argument is an array, otherwise uses all arguments as an
|
|
7
|
-
// array.
|
|
8
|
-
|
|
9
|
-
function normalizeArr() {
|
|
10
|
-
const args = new Array(arguments.length);
|
|
11
|
-
for (let i = 0; i < args.length; i++) {
|
|
12
|
-
args[i] = arguments[i];
|
|
13
|
-
}
|
|
14
|
-
if (Array.isArray(args[0])) {
|
|
15
|
-
return args[0];
|
|
16
|
-
}
|
|
17
|
-
return args;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function containsUndefined(mixed) {
|
|
21
|
-
let argContainsUndefined = false;
|
|
22
|
-
|
|
23
|
-
if (isTypedArray(mixed)) return false;
|
|
24
|
-
|
|
25
|
-
if (mixed && isFunction(mixed.toSQL)) {
|
|
26
|
-
//Any QueryBuilder or Raw will automatically be validated during compile.
|
|
27
|
-
return argContainsUndefined;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (Array.isArray(mixed)) {
|
|
31
|
-
for (let i = 0; i < mixed.length; i++) {
|
|
32
|
-
if (argContainsUndefined) break;
|
|
33
|
-
argContainsUndefined = containsUndefined(mixed[i]);
|
|
34
|
-
}
|
|
35
|
-
} else if (isPlainObject(mixed)) {
|
|
36
|
-
Object.keys(mixed).forEach((key) => {
|
|
37
|
-
if (!argContainsUndefined) {
|
|
38
|
-
argContainsUndefined = containsUndefined(mixed[key]);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
} else {
|
|
42
|
-
argContainsUndefined = mixed === undefined;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return argContainsUndefined;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function getUndefinedIndices(mixed) {
|
|
49
|
-
const indices = [];
|
|
50
|
-
|
|
51
|
-
if (Array.isArray(mixed)) {
|
|
52
|
-
mixed.forEach((item, index) => {
|
|
53
|
-
if (containsUndefined(item)) {
|
|
54
|
-
indices.push(index);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
} else if (isPlainObject(mixed)) {
|
|
58
|
-
Object.keys(mixed).forEach((key) => {
|
|
59
|
-
if (containsUndefined(mixed[key])) {
|
|
60
|
-
indices.push(key);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
} else {
|
|
64
|
-
indices.push(0);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return indices;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function addQueryContext(Target) {
|
|
71
|
-
// Stores or returns (if called with no arguments) context passed to
|
|
72
|
-
// wrapIdentifier and postProcessResponse hooks
|
|
73
|
-
Target.prototype.queryContext = function (context) {
|
|
74
|
-
if (context === undefined) {
|
|
75
|
-
return this._queryContext;
|
|
76
|
-
}
|
|
77
|
-
this._queryContext = context;
|
|
78
|
-
return this;
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function resolveClientNameWithAliases(clientName) {
|
|
83
|
-
return CLIENT_ALIASES[clientName] || clientName;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
module.exports = {
|
|
87
|
-
addQueryContext,
|
|
88
|
-
containsUndefined,
|
|
89
|
-
normalizeArr,
|
|
90
|
-
resolveClientNameWithAliases,
|
|
91
|
-
getUndefinedIndices,
|
|
92
|
-
};
|
|
1
|
+
const isPlainObject = require('lodash/isPlainObject');
|
|
2
|
+
const isTypedArray = require('lodash/isTypedArray');
|
|
3
|
+
const { CLIENT_ALIASES } = require('./constants');
|
|
4
|
+
const { isFunction } = require('./util/is');
|
|
5
|
+
|
|
6
|
+
// Check if the first argument is an array, otherwise uses all arguments as an
|
|
7
|
+
// array.
|
|
8
|
+
|
|
9
|
+
function normalizeArr() {
|
|
10
|
+
const args = new Array(arguments.length);
|
|
11
|
+
for (let i = 0; i < args.length; i++) {
|
|
12
|
+
args[i] = arguments[i];
|
|
13
|
+
}
|
|
14
|
+
if (Array.isArray(args[0])) {
|
|
15
|
+
return args[0];
|
|
16
|
+
}
|
|
17
|
+
return args;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function containsUndefined(mixed) {
|
|
21
|
+
let argContainsUndefined = false;
|
|
22
|
+
|
|
23
|
+
if (isTypedArray(mixed)) return false;
|
|
24
|
+
|
|
25
|
+
if (mixed && isFunction(mixed.toSQL)) {
|
|
26
|
+
//Any QueryBuilder or Raw will automatically be validated during compile.
|
|
27
|
+
return argContainsUndefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (Array.isArray(mixed)) {
|
|
31
|
+
for (let i = 0; i < mixed.length; i++) {
|
|
32
|
+
if (argContainsUndefined) break;
|
|
33
|
+
argContainsUndefined = containsUndefined(mixed[i]);
|
|
34
|
+
}
|
|
35
|
+
} else if (isPlainObject(mixed)) {
|
|
36
|
+
Object.keys(mixed).forEach((key) => {
|
|
37
|
+
if (!argContainsUndefined) {
|
|
38
|
+
argContainsUndefined = containsUndefined(mixed[key]);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
} else {
|
|
42
|
+
argContainsUndefined = mixed === undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return argContainsUndefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getUndefinedIndices(mixed) {
|
|
49
|
+
const indices = [];
|
|
50
|
+
|
|
51
|
+
if (Array.isArray(mixed)) {
|
|
52
|
+
mixed.forEach((item, index) => {
|
|
53
|
+
if (containsUndefined(item)) {
|
|
54
|
+
indices.push(index);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
} else if (isPlainObject(mixed)) {
|
|
58
|
+
Object.keys(mixed).forEach((key) => {
|
|
59
|
+
if (containsUndefined(mixed[key])) {
|
|
60
|
+
indices.push(key);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
} else {
|
|
64
|
+
indices.push(0);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return indices;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function addQueryContext(Target) {
|
|
71
|
+
// Stores or returns (if called with no arguments) context passed to
|
|
72
|
+
// wrapIdentifier and postProcessResponse hooks
|
|
73
|
+
Target.prototype.queryContext = function (context) {
|
|
74
|
+
if (context === undefined) {
|
|
75
|
+
return this._queryContext;
|
|
76
|
+
}
|
|
77
|
+
this._queryContext = context;
|
|
78
|
+
return this;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function resolveClientNameWithAliases(clientName) {
|
|
83
|
+
return CLIENT_ALIASES[clientName] || clientName;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
module.exports = {
|
|
87
|
+
addQueryContext,
|
|
88
|
+
containsUndefined,
|
|
89
|
+
normalizeArr,
|
|
90
|
+
resolveClientNameWithAliases,
|
|
91
|
+
getUndefinedIndices,
|
|
92
|
+
};
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const Knex = require('./knex');
|
|
2
|
-
|
|
3
|
-
module.exports = Knex;
|
|
1
|
+
const Knex = require('./knex');
|
|
2
|
+
|
|
3
|
+
module.exports = Knex;
|
package/lib/interface.js
CHANGED
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
const clone = require('lodash/clone');
|
|
2
|
-
const isEmpty = require('lodash/isEmpty');
|
|
3
|
-
const { callbackify } = require('util');
|
|
4
|
-
const finallyMixin = require('./util/finally-mixin');
|
|
5
|
-
|
|
6
|
-
function augmentWithBuilderInterface(Target) {
|
|
7
|
-
Target.prototype.toQuery = function (tz) {
|
|
8
|
-
let data = this.toSQL(this._method, tz);
|
|
9
|
-
if (!Array.isArray(data)) data = [data];
|
|
10
|
-
if (!data.length) {
|
|
11
|
-
return '';
|
|
12
|
-
}
|
|
13
|
-
return data
|
|
14
|
-
.map((statement) => {
|
|
15
|
-
return this.client._formatQuery(statement.sql, statement.bindings, tz);
|
|
16
|
-
})
|
|
17
|
-
.reduce((a, c) => a.concat(a.endsWith(';') ? '\n' : ';\n', c));
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
// Create a new instance of the `Runner`, passing in the current object.
|
|
21
|
-
Target.prototype.then = function (/* onFulfilled, onRejected */) {
|
|
22
|
-
let result = this.client.runner(this).run();
|
|
23
|
-
|
|
24
|
-
if (this.client.config.asyncStackTraces) {
|
|
25
|
-
result = result.catch((err) => {
|
|
26
|
-
err.originalStack = err.stack;
|
|
27
|
-
const firstLine = err.stack.split('\n')[0];
|
|
28
|
-
|
|
29
|
-
// a hack to get a callstack into the client code despite this
|
|
30
|
-
// node.js bug https://github.com/nodejs/node/issues/11865
|
|
31
|
-
// see lib/util/save-async-stack.js for more details
|
|
32
|
-
const { error, lines } = this._asyncStack;
|
|
33
|
-
const stackByLines = error.stack.split('\n');
|
|
34
|
-
const asyncStack = stackByLines.slice(lines);
|
|
35
|
-
asyncStack.unshift(firstLine);
|
|
36
|
-
|
|
37
|
-
// put the fake more helpful "async" stack on the thrown error
|
|
38
|
-
err.stack = asyncStack.join('\n');
|
|
39
|
-
throw err;
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return result.then.apply(result, arguments);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// Add additional "options" to the builder. Typically used for client specific
|
|
47
|
-
// items, like the `mysql` and `sqlite3` drivers.
|
|
48
|
-
Target.prototype.options = function (opts) {
|
|
49
|
-
this._options = this._options || [];
|
|
50
|
-
this._options.push(clone(opts) || {});
|
|
51
|
-
return this;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// Sets an explicit "connection" we wish to use for this query.
|
|
55
|
-
Target.prototype.connection = function (connection) {
|
|
56
|
-
this._connection = connection;
|
|
57
|
-
return this;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
// Set a debug flag for the current schema query stack.
|
|
61
|
-
Target.prototype.debug = function (enabled) {
|
|
62
|
-
this._debug = arguments.length ? enabled : true;
|
|
63
|
-
return this;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
// Set the transaction object for this query.
|
|
67
|
-
Target.prototype.transacting = function (transaction) {
|
|
68
|
-
if (transaction && transaction.client) {
|
|
69
|
-
if (!transaction.client.transacting) {
|
|
70
|
-
transaction.client.logger.warn(
|
|
71
|
-
`Invalid transaction value: ${transaction.client}`
|
|
72
|
-
);
|
|
73
|
-
} else {
|
|
74
|
-
this.client = transaction.client;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (isEmpty(transaction)) {
|
|
78
|
-
this.client.logger.error(
|
|
79
|
-
'Invalid value on transacting call, potential bug'
|
|
80
|
-
);
|
|
81
|
-
throw Error(
|
|
82
|
-
'Invalid transacting value (null, undefined or empty object)'
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
return this;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
// Initializes a stream.
|
|
89
|
-
Target.prototype.stream = function (options) {
|
|
90
|
-
return this.client.runner(this).stream(options);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
// Initialize a stream & pipe automatically.
|
|
94
|
-
Target.prototype.pipe = function (writable, options) {
|
|
95
|
-
return this.client.runner(this).pipe(writable, options);
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
Target.prototype.asCallback = function (cb) {
|
|
99
|
-
const promise = this.then();
|
|
100
|
-
callbackify(() => promise)(cb);
|
|
101
|
-
return promise;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
Target.prototype.catch = function (onReject) {
|
|
105
|
-
return this.then().catch(onReject);
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
Object.defineProperty(Target.prototype, Symbol.toStringTag, {
|
|
109
|
-
get: () => 'object',
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
finallyMixin(Target.prototype);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
module.exports = augmentWithBuilderInterface;
|
|
1
|
+
const clone = require('lodash/clone');
|
|
2
|
+
const isEmpty = require('lodash/isEmpty');
|
|
3
|
+
const { callbackify } = require('util');
|
|
4
|
+
const finallyMixin = require('./util/finally-mixin');
|
|
5
|
+
|
|
6
|
+
function augmentWithBuilderInterface(Target) {
|
|
7
|
+
Target.prototype.toQuery = function (tz) {
|
|
8
|
+
let data = this.toSQL(this._method, tz);
|
|
9
|
+
if (!Array.isArray(data)) data = [data];
|
|
10
|
+
if (!data.length) {
|
|
11
|
+
return '';
|
|
12
|
+
}
|
|
13
|
+
return data
|
|
14
|
+
.map((statement) => {
|
|
15
|
+
return this.client._formatQuery(statement.sql, statement.bindings, tz);
|
|
16
|
+
})
|
|
17
|
+
.reduce((a, c) => a.concat(a.endsWith(';') ? '\n' : ';\n', c));
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Create a new instance of the `Runner`, passing in the current object.
|
|
21
|
+
Target.prototype.then = function (/* onFulfilled, onRejected */) {
|
|
22
|
+
let result = this.client.runner(this).run();
|
|
23
|
+
|
|
24
|
+
if (this.client.config.asyncStackTraces) {
|
|
25
|
+
result = result.catch((err) => {
|
|
26
|
+
err.originalStack = err.stack;
|
|
27
|
+
const firstLine = err.stack.split('\n')[0];
|
|
28
|
+
|
|
29
|
+
// a hack to get a callstack into the client code despite this
|
|
30
|
+
// node.js bug https://github.com/nodejs/node/issues/11865
|
|
31
|
+
// see lib/util/save-async-stack.js for more details
|
|
32
|
+
const { error, lines } = this._asyncStack;
|
|
33
|
+
const stackByLines = error.stack.split('\n');
|
|
34
|
+
const asyncStack = stackByLines.slice(lines);
|
|
35
|
+
asyncStack.unshift(firstLine);
|
|
36
|
+
|
|
37
|
+
// put the fake more helpful "async" stack on the thrown error
|
|
38
|
+
err.stack = asyncStack.join('\n');
|
|
39
|
+
throw err;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return result.then.apply(result, arguments);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// Add additional "options" to the builder. Typically used for client specific
|
|
47
|
+
// items, like the `mysql` and `sqlite3` drivers.
|
|
48
|
+
Target.prototype.options = function (opts) {
|
|
49
|
+
this._options = this._options || [];
|
|
50
|
+
this._options.push(clone(opts) || {});
|
|
51
|
+
return this;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// Sets an explicit "connection" we wish to use for this query.
|
|
55
|
+
Target.prototype.connection = function (connection) {
|
|
56
|
+
this._connection = connection;
|
|
57
|
+
return this;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// Set a debug flag for the current schema query stack.
|
|
61
|
+
Target.prototype.debug = function (enabled) {
|
|
62
|
+
this._debug = arguments.length ? enabled : true;
|
|
63
|
+
return this;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// Set the transaction object for this query.
|
|
67
|
+
Target.prototype.transacting = function (transaction) {
|
|
68
|
+
if (transaction && transaction.client) {
|
|
69
|
+
if (!transaction.client.transacting) {
|
|
70
|
+
transaction.client.logger.warn(
|
|
71
|
+
`Invalid transaction value: ${transaction.client}`
|
|
72
|
+
);
|
|
73
|
+
} else {
|
|
74
|
+
this.client = transaction.client;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (isEmpty(transaction)) {
|
|
78
|
+
this.client.logger.error(
|
|
79
|
+
'Invalid value on transacting call, potential bug'
|
|
80
|
+
);
|
|
81
|
+
throw Error(
|
|
82
|
+
'Invalid transacting value (null, undefined or empty object)'
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
return this;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// Initializes a stream.
|
|
89
|
+
Target.prototype.stream = function (options) {
|
|
90
|
+
return this.client.runner(this).stream(options);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// Initialize a stream & pipe automatically.
|
|
94
|
+
Target.prototype.pipe = function (writable, options) {
|
|
95
|
+
return this.client.runner(this).pipe(writable, options);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
Target.prototype.asCallback = function (cb) {
|
|
99
|
+
const promise = this.then();
|
|
100
|
+
callbackify(() => promise)(cb);
|
|
101
|
+
return promise;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
Target.prototype.catch = function (onReject) {
|
|
105
|
+
return this.then().catch(onReject);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
Object.defineProperty(Target.prototype, Symbol.toStringTag, {
|
|
109
|
+
get: () => 'object',
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
finallyMixin(Target.prototype);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
module.exports = augmentWithBuilderInterface;
|
package/lib/knex.js
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
const Raw = require('./raw');
|
|
2
|
-
const Client = require('./client');
|
|
3
|
-
const QueryBuilder = require('./query/builder');
|
|
4
|
-
const QueryInterface = require('./query/methods');
|
|
5
|
-
|
|
6
|
-
const makeKnex = require('./util/make-knex');
|
|
7
|
-
const { KnexTimeoutError } = require('./util/timeout');
|
|
8
|
-
const fakeClient = require('./util/fake-client');
|
|
9
|
-
const { resolveConfig } = require('./config-resolver');
|
|
10
|
-
|
|
11
|
-
function Knex(config) {
|
|
12
|
-
const { resolvedConfig, Dialect } = resolveConfig(...arguments);
|
|
13
|
-
|
|
14
|
-
const newKnex = makeKnex(new Dialect(resolvedConfig));
|
|
15
|
-
if (resolvedConfig.userParams) {
|
|
16
|
-
newKnex.userParams = resolvedConfig.userParams;
|
|
17
|
-
}
|
|
18
|
-
return newKnex;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Expose Client on the main Knex namespace.
|
|
22
|
-
Knex.Client = Client;
|
|
23
|
-
|
|
24
|
-
Knex.KnexTimeoutError = KnexTimeoutError;
|
|
25
|
-
|
|
26
|
-
Knex.QueryBuilder = {
|
|
27
|
-
extend: function (methodName, fn) {
|
|
28
|
-
QueryBuilder.extend(methodName, fn);
|
|
29
|
-
QueryInterface.push(methodName);
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// Run a "raw" query, though we can't do anything with it other than put
|
|
34
|
-
// it in a query statement.
|
|
35
|
-
Knex.raw = (sql, bindings) => {
|
|
36
|
-
console.warn(
|
|
37
|
-
'global Knex.raw is deprecated, use knex.raw (chain off an initialized knex object)'
|
|
38
|
-
);
|
|
39
|
-
return new Raw(fakeClient).set(sql, bindings);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
module.exports = Knex;
|
|
1
|
+
const Raw = require('./raw');
|
|
2
|
+
const Client = require('./client');
|
|
3
|
+
const QueryBuilder = require('./query/builder');
|
|
4
|
+
const QueryInterface = require('./query/methods');
|
|
5
|
+
|
|
6
|
+
const makeKnex = require('./util/make-knex');
|
|
7
|
+
const { KnexTimeoutError } = require('./util/timeout');
|
|
8
|
+
const fakeClient = require('./util/fake-client');
|
|
9
|
+
const { resolveConfig } = require('./config-resolver');
|
|
10
|
+
|
|
11
|
+
function Knex(config) {
|
|
12
|
+
const { resolvedConfig, Dialect } = resolveConfig(...arguments);
|
|
13
|
+
|
|
14
|
+
const newKnex = makeKnex(new Dialect(resolvedConfig));
|
|
15
|
+
if (resolvedConfig.userParams) {
|
|
16
|
+
newKnex.userParams = resolvedConfig.userParams;
|
|
17
|
+
}
|
|
18
|
+
return newKnex;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Expose Client on the main Knex namespace.
|
|
22
|
+
Knex.Client = Client;
|
|
23
|
+
|
|
24
|
+
Knex.KnexTimeoutError = KnexTimeoutError;
|
|
25
|
+
|
|
26
|
+
Knex.QueryBuilder = {
|
|
27
|
+
extend: function (methodName, fn) {
|
|
28
|
+
QueryBuilder.extend(methodName, fn);
|
|
29
|
+
QueryInterface.push(methodName);
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// Run a "raw" query, though we can't do anything with it other than put
|
|
34
|
+
// it in a query statement.
|
|
35
|
+
Knex.raw = (sql, bindings) => {
|
|
36
|
+
console.warn(
|
|
37
|
+
'global Knex.raw is deprecated, use knex.raw (chain off an initialized knex object)'
|
|
38
|
+
);
|
|
39
|
+
return new Raw(fakeClient).set(sql, bindings);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
module.exports = Knex;
|
package/lib/logger.js
CHANGED
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
const color = require('colorette');
|
|
2
|
-
const { inspect } = require('util');
|
|
3
|
-
const { isString, isFunction } = require('./util/is');
|
|
4
|
-
|
|
5
|
-
class Logger {
|
|
6
|
-
constructor(config = {}) {
|
|
7
|
-
const {
|
|
8
|
-
log: {
|
|
9
|
-
debug,
|
|
10
|
-
warn,
|
|
11
|
-
error,
|
|
12
|
-
deprecate,
|
|
13
|
-
inspectionDepth,
|
|
14
|
-
enableColors,
|
|
15
|
-
} = {},
|
|
16
|
-
} = config;
|
|
17
|
-
this._inspectionDepth = inspectionDepth || 5;
|
|
18
|
-
this._enableColors = resolveIsEnabledColors(enableColors);
|
|
19
|
-
this._debug = debug;
|
|
20
|
-
this._warn = warn;
|
|
21
|
-
this._error = error;
|
|
22
|
-
this._deprecate = deprecate;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
_log(message, userFn, colorFn) {
|
|
26
|
-
if (userFn != null && !isFunction(userFn)) {
|
|
27
|
-
throw new TypeError('Extensions to knex logger must be functions!');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (isFunction(userFn)) {
|
|
31
|
-
userFn(message);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (!isString(message)) {
|
|
36
|
-
message = inspect(message, {
|
|
37
|
-
depth: this._inspectionDepth,
|
|
38
|
-
colors: this._enableColors,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
console.log(colorFn ? colorFn(message) : message);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
debug(message) {
|
|
46
|
-
this._log(message, this._debug);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
warn(message) {
|
|
50
|
-
this._log(message, this._warn, color.yellow);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
error(message) {
|
|
54
|
-
this._log(message, this._error, color.red);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
deprecate(method, alternative) {
|
|
58
|
-
const message = `${method} is deprecated, please use ${alternative}`;
|
|
59
|
-
|
|
60
|
-
this._log(message, this._deprecate, color.yellow);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function resolveIsEnabledColors(enableColorsParam) {
|
|
65
|
-
if (enableColorsParam != null) {
|
|
66
|
-
return enableColorsParam;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (process && process.stdout) {
|
|
70
|
-
return process.stdout.isTTY;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
module.exports = Logger;
|
|
1
|
+
const color = require('colorette');
|
|
2
|
+
const { inspect } = require('util');
|
|
3
|
+
const { isString, isFunction } = require('./util/is');
|
|
4
|
+
|
|
5
|
+
class Logger {
|
|
6
|
+
constructor(config = {}) {
|
|
7
|
+
const {
|
|
8
|
+
log: {
|
|
9
|
+
debug,
|
|
10
|
+
warn,
|
|
11
|
+
error,
|
|
12
|
+
deprecate,
|
|
13
|
+
inspectionDepth,
|
|
14
|
+
enableColors,
|
|
15
|
+
} = {},
|
|
16
|
+
} = config;
|
|
17
|
+
this._inspectionDepth = inspectionDepth || 5;
|
|
18
|
+
this._enableColors = resolveIsEnabledColors(enableColors);
|
|
19
|
+
this._debug = debug;
|
|
20
|
+
this._warn = warn;
|
|
21
|
+
this._error = error;
|
|
22
|
+
this._deprecate = deprecate;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
_log(message, userFn, colorFn) {
|
|
26
|
+
if (userFn != null && !isFunction(userFn)) {
|
|
27
|
+
throw new TypeError('Extensions to knex logger must be functions!');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (isFunction(userFn)) {
|
|
31
|
+
userFn(message);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!isString(message)) {
|
|
36
|
+
message = inspect(message, {
|
|
37
|
+
depth: this._inspectionDepth,
|
|
38
|
+
colors: this._enableColors,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
console.log(colorFn ? colorFn(message) : message);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
debug(message) {
|
|
46
|
+
this._log(message, this._debug);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
warn(message) {
|
|
50
|
+
this._log(message, this._warn, color.yellow);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
error(message) {
|
|
54
|
+
this._log(message, this._error, color.red);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
deprecate(method, alternative) {
|
|
58
|
+
const message = `${method} is deprecated, please use ${alternative}`;
|
|
59
|
+
|
|
60
|
+
this._log(message, this._deprecate, color.yellow);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function resolveIsEnabledColors(enableColorsParam) {
|
|
65
|
+
if (enableColorsParam != null) {
|
|
66
|
+
return enableColorsParam;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (process && process.stdout) {
|
|
70
|
+
return process.stdout.isTTY;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
module.exports = Logger;
|