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/util/nanoid.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
// This alphabet uses `A-Za-z0-9_-` symbols. The genetic algorithm helped
|
|
2
|
-
// optimize the gzip compression for this alphabet.
|
|
3
|
-
const urlAlphabet =
|
|
4
|
-
'ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Generate URL-friendly unique ID. This method uses the non-secure
|
|
8
|
-
* predictable random generator with bigger collision probability.
|
|
9
|
-
* Based on https://github.com/ai/nanoid
|
|
10
|
-
*
|
|
11
|
-
* ```js
|
|
12
|
-
* model.id = nanoid() //=> "Uakgb_J5m9g-0JDMbcJqL"
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* @param size Size of the ID. The default size is 21.
|
|
16
|
-
* @returns A random string.
|
|
17
|
-
*/
|
|
18
|
-
function nanoid(size = 21) {
|
|
19
|
-
let id = '';
|
|
20
|
-
// A compact alternative for `for (var i = 0; i < step; i++)`.
|
|
21
|
-
let i = size;
|
|
22
|
-
while (i--) {
|
|
23
|
-
// `| 0` is more compact and faster than `Math.floor()`.
|
|
24
|
-
id += urlAlphabet[(Math.random() * 64) | 0];
|
|
25
|
-
}
|
|
26
|
-
return id;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
module.exports = { nanoid };
|
|
1
|
+
// This alphabet uses `A-Za-z0-9_-` symbols. The genetic algorithm helped
|
|
2
|
+
// optimize the gzip compression for this alphabet.
|
|
3
|
+
const urlAlphabet =
|
|
4
|
+
'ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Generate URL-friendly unique ID. This method uses the non-secure
|
|
8
|
+
* predictable random generator with bigger collision probability.
|
|
9
|
+
* Based on https://github.com/ai/nanoid
|
|
10
|
+
*
|
|
11
|
+
* ```js
|
|
12
|
+
* model.id = nanoid() //=> "Uakgb_J5m9g-0JDMbcJqL"
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @param size Size of the ID. The default size is 21.
|
|
16
|
+
* @returns A random string.
|
|
17
|
+
*/
|
|
18
|
+
function nanoid(size = 21) {
|
|
19
|
+
let id = '';
|
|
20
|
+
// A compact alternative for `for (var i = 0; i < step; i++)`.
|
|
21
|
+
let i = size;
|
|
22
|
+
while (i--) {
|
|
23
|
+
// `| 0` is more compact and faster than `Math.floor()`.
|
|
24
|
+
id += urlAlphabet[(Math.random() * 64) | 0];
|
|
25
|
+
}
|
|
26
|
+
return id;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = { nanoid };
|
package/lib/util/noop.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = function () {};
|
|
1
|
+
module.exports = function () {};
|
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
const url = require('url');
|
|
2
|
-
const { parse } = require('pg-connection-string');
|
|
3
|
-
const parsePG = parse;
|
|
4
|
-
const isWindows = process && process.platform && process.platform === 'win32';
|
|
5
|
-
|
|
6
|
-
module.exports = function parseConnectionString(str) {
|
|
7
|
-
const parsed = url.parse(str, true);
|
|
8
|
-
let { protocol } = parsed;
|
|
9
|
-
const isDriveLetter = isWindows && protocol && protocol.length === 2;
|
|
10
|
-
if (protocol === null || isDriveLetter) {
|
|
11
|
-
return {
|
|
12
|
-
client: 'sqlite3',
|
|
13
|
-
connection: {
|
|
14
|
-
filename: str,
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
if (protocol.slice(-1) === ':') {
|
|
19
|
-
protocol = protocol.slice(0, -1);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const isPG = ['postgresql', 'postgres'].includes(protocol);
|
|
23
|
-
|
|
24
|
-
return {
|
|
25
|
-
client: protocol,
|
|
26
|
-
connection: isPG ? parsePG(str) : connectionObject(parsed),
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
function connectionObject(parsed) {
|
|
31
|
-
const connection = {};
|
|
32
|
-
let db = parsed.pathname;
|
|
33
|
-
if (db[0] === '/') {
|
|
34
|
-
db = db.slice(1);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
connection.database = db;
|
|
38
|
-
|
|
39
|
-
if (parsed.hostname) {
|
|
40
|
-
if (parsed.protocol.indexOf('mssql') === 0) {
|
|
41
|
-
connection.server = parsed.hostname;
|
|
42
|
-
} else {
|
|
43
|
-
connection.host = parsed.hostname;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
if (parsed.port) {
|
|
47
|
-
connection.port = parsed.port;
|
|
48
|
-
}
|
|
49
|
-
if (parsed.auth) {
|
|
50
|
-
const idx = parsed.auth.indexOf(':');
|
|
51
|
-
if (idx !== -1) {
|
|
52
|
-
connection.user = parsed.auth.slice(0, idx);
|
|
53
|
-
if (idx < parsed.auth.length - 1) {
|
|
54
|
-
connection.password = parsed.auth.slice(idx + 1);
|
|
55
|
-
}
|
|
56
|
-
} else {
|
|
57
|
-
connection.user = parsed.auth;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (parsed.query) {
|
|
61
|
-
for (const key in parsed.query) {
|
|
62
|
-
connection[key] = parsed.query[key];
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return connection;
|
|
66
|
-
}
|
|
1
|
+
const url = require('url');
|
|
2
|
+
const { parse } = require('pg-connection-string');
|
|
3
|
+
const parsePG = parse;
|
|
4
|
+
const isWindows = process && process.platform && process.platform === 'win32';
|
|
5
|
+
|
|
6
|
+
module.exports = function parseConnectionString(str) {
|
|
7
|
+
const parsed = url.parse(str, true);
|
|
8
|
+
let { protocol } = parsed;
|
|
9
|
+
const isDriveLetter = isWindows && protocol && protocol.length === 2;
|
|
10
|
+
if (protocol === null || isDriveLetter) {
|
|
11
|
+
return {
|
|
12
|
+
client: 'sqlite3',
|
|
13
|
+
connection: {
|
|
14
|
+
filename: str,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
if (protocol.slice(-1) === ':') {
|
|
19
|
+
protocol = protocol.slice(0, -1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const isPG = ['postgresql', 'postgres'].includes(protocol);
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
client: protocol,
|
|
26
|
+
connection: isPG ? parsePG(str) : connectionObject(parsed),
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function connectionObject(parsed) {
|
|
31
|
+
const connection = {};
|
|
32
|
+
let db = parsed.pathname;
|
|
33
|
+
if (db[0] === '/') {
|
|
34
|
+
db = db.slice(1);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
connection.database = db;
|
|
38
|
+
|
|
39
|
+
if (parsed.hostname) {
|
|
40
|
+
if (parsed.protocol.indexOf('mssql') === 0) {
|
|
41
|
+
connection.server = parsed.hostname;
|
|
42
|
+
} else {
|
|
43
|
+
connection.host = parsed.hostname;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (parsed.port) {
|
|
47
|
+
connection.port = parsed.port;
|
|
48
|
+
}
|
|
49
|
+
if (parsed.auth) {
|
|
50
|
+
const idx = parsed.auth.indexOf(':');
|
|
51
|
+
if (idx !== -1) {
|
|
52
|
+
connection.user = parsed.auth.slice(0, idx);
|
|
53
|
+
if (idx < parsed.auth.length - 1) {
|
|
54
|
+
connection.password = parsed.auth.slice(idx + 1);
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
connection.user = parsed.auth;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (parsed.query) {
|
|
61
|
+
for (const key in parsed.query) {
|
|
62
|
+
connection[key] = parsed.query[key];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return connection;
|
|
66
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
module.exports = function saveAsyncStack(instance, lines) {
|
|
2
|
-
if (instance.client.config.asyncStackTraces) {
|
|
3
|
-
// a hack to get a callstack into the client code despite this
|
|
4
|
-
// node.js bug https://github.com/nodejs/node/issues/11865
|
|
5
|
-
|
|
6
|
-
// Save error here but not error trace
|
|
7
|
-
// reading trace with '--enable-source-maps' flag on node can be very costly
|
|
8
|
-
|
|
9
|
-
instance._asyncStack = {
|
|
10
|
-
error: new Error(),
|
|
11
|
-
lines,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
};
|
|
1
|
+
module.exports = function saveAsyncStack(instance, lines) {
|
|
2
|
+
if (instance.client.config.asyncStackTraces) {
|
|
3
|
+
// a hack to get a callstack into the client code despite this
|
|
4
|
+
// node.js bug https://github.com/nodejs/node/issues/11865
|
|
5
|
+
|
|
6
|
+
// Save error here but not error trace
|
|
7
|
+
// reading trace with '--enable-source-maps' flag on node can be very costly
|
|
8
|
+
|
|
9
|
+
instance._asyncStack = {
|
|
10
|
+
error: new Error(),
|
|
11
|
+
lines,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
};
|
package/lib/util/template.js
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
const template = require('lodash/template');
|
|
2
|
-
|
|
3
|
-
const { readFile, writeFile } = require('./fs');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Light wrapper over lodash templates making it safer to be used with javascript source code.
|
|
7
|
-
*
|
|
8
|
-
* In particular, doesn't interfere with use of interpolated strings in javascript.
|
|
9
|
-
*
|
|
10
|
-
* @param {string} content Template source
|
|
11
|
-
* @param {_.TemplateOptions} options Template options
|
|
12
|
-
*/
|
|
13
|
-
const jsSourceTemplate = (content, options) =>
|
|
14
|
-
template(content, {
|
|
15
|
-
interpolate: /<%=([\s\S]+?)%>/g,
|
|
16
|
-
...options,
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Compile the contents of specified (javascript) file as a lodash template
|
|
21
|
-
*
|
|
22
|
-
* @param {string} filePath Path of file to be used as template
|
|
23
|
-
* @param {_.TemplateOptions} options Lodash template options
|
|
24
|
-
*/
|
|
25
|
-
const jsFileTemplate = async (filePath, options) => {
|
|
26
|
-
const contentBuffer = await readFile(filePath);
|
|
27
|
-
return jsSourceTemplate(contentBuffer.toString(), options);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Write a javascript file using another file as a (lodash) template
|
|
32
|
-
*
|
|
33
|
-
* @param {string} targetFilePath
|
|
34
|
-
* @param {string} sourceFilePath
|
|
35
|
-
* @param {_.TemplateOptions} options options passed to lodash templates
|
|
36
|
-
*/
|
|
37
|
-
const writeJsFileUsingTemplate = async (
|
|
38
|
-
targetFilePath,
|
|
39
|
-
sourceFilePath,
|
|
40
|
-
options,
|
|
41
|
-
variables
|
|
42
|
-
) =>
|
|
43
|
-
writeFile(
|
|
44
|
-
targetFilePath,
|
|
45
|
-
(await jsFileTemplate(sourceFilePath, options))(variables)
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
module.exports = {
|
|
49
|
-
jsSourceTemplate,
|
|
50
|
-
jsFileTemplate,
|
|
51
|
-
writeJsFileUsingTemplate,
|
|
52
|
-
};
|
|
1
|
+
const template = require('lodash/template');
|
|
2
|
+
|
|
3
|
+
const { readFile, writeFile } = require('./fs');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Light wrapper over lodash templates making it safer to be used with javascript source code.
|
|
7
|
+
*
|
|
8
|
+
* In particular, doesn't interfere with use of interpolated strings in javascript.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} content Template source
|
|
11
|
+
* @param {_.TemplateOptions} options Template options
|
|
12
|
+
*/
|
|
13
|
+
const jsSourceTemplate = (content, options) =>
|
|
14
|
+
template(content, {
|
|
15
|
+
interpolate: /<%=([\s\S]+?)%>/g,
|
|
16
|
+
...options,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Compile the contents of specified (javascript) file as a lodash template
|
|
21
|
+
*
|
|
22
|
+
* @param {string} filePath Path of file to be used as template
|
|
23
|
+
* @param {_.TemplateOptions} options Lodash template options
|
|
24
|
+
*/
|
|
25
|
+
const jsFileTemplate = async (filePath, options) => {
|
|
26
|
+
const contentBuffer = await readFile(filePath);
|
|
27
|
+
return jsSourceTemplate(contentBuffer.toString(), options);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Write a javascript file using another file as a (lodash) template
|
|
32
|
+
*
|
|
33
|
+
* @param {string} targetFilePath
|
|
34
|
+
* @param {string} sourceFilePath
|
|
35
|
+
* @param {_.TemplateOptions} options options passed to lodash templates
|
|
36
|
+
*/
|
|
37
|
+
const writeJsFileUsingTemplate = async (
|
|
38
|
+
targetFilePath,
|
|
39
|
+
sourceFilePath,
|
|
40
|
+
options,
|
|
41
|
+
variables
|
|
42
|
+
) =>
|
|
43
|
+
writeFile(
|
|
44
|
+
targetFilePath,
|
|
45
|
+
(await jsFileTemplate(sourceFilePath, options))(variables)
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
module.exports = {
|
|
49
|
+
jsSourceTemplate,
|
|
50
|
+
jsFileTemplate,
|
|
51
|
+
writeJsFileUsingTemplate,
|
|
52
|
+
};
|
package/lib/util/timeout.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
class KnexTimeoutError extends Error {
|
|
2
|
-
constructor(message) {
|
|
3
|
-
super(message);
|
|
4
|
-
this.name = 'KnexTimeoutError';
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function timeout(promise, ms) {
|
|
9
|
-
return new Promise(function (resolve, reject) {
|
|
10
|
-
const id = setTimeout(function () {
|
|
11
|
-
reject(new KnexTimeoutError('operation timed out'));
|
|
12
|
-
}, ms);
|
|
13
|
-
|
|
14
|
-
function wrappedResolve(value) {
|
|
15
|
-
clearTimeout(id);
|
|
16
|
-
resolve(value);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function wrappedReject(err) {
|
|
20
|
-
clearTimeout(id);
|
|
21
|
-
reject(err);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
promise.then(wrappedResolve, wrappedReject);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
module.exports.KnexTimeoutError = KnexTimeoutError;
|
|
29
|
-
module.exports.timeout = timeout;
|
|
1
|
+
class KnexTimeoutError extends Error {
|
|
2
|
+
constructor(message) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.name = 'KnexTimeoutError';
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function timeout(promise, ms) {
|
|
9
|
+
return new Promise(function (resolve, reject) {
|
|
10
|
+
const id = setTimeout(function () {
|
|
11
|
+
reject(new KnexTimeoutError('operation timed out'));
|
|
12
|
+
}, ms);
|
|
13
|
+
|
|
14
|
+
function wrappedResolve(value) {
|
|
15
|
+
clearTimeout(id);
|
|
16
|
+
resolve(value);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function wrappedReject(err) {
|
|
20
|
+
clearTimeout(id);
|
|
21
|
+
reject(err);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
promise.then(wrappedResolve, wrappedReject);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports.KnexTimeoutError = KnexTimeoutError;
|
|
29
|
+
module.exports.timeout = timeout;
|
package/lib/util/timestamp.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
// Get a date object in the correct format, without requiring a full out library
|
|
2
|
-
// like "moment.js".
|
|
3
|
-
function yyyymmddhhmmss() {
|
|
4
|
-
const d = new Date();
|
|
5
|
-
|
|
6
|
-
return (
|
|
7
|
-
d.getFullYear().toString() +
|
|
8
|
-
(d.getMonth() + 1).toString().padStart(2, '0') +
|
|
9
|
-
d.getDate().toString().padStart(2, '0') +
|
|
10
|
-
d.getHours().toString().padStart(2, '0') +
|
|
11
|
-
d.getMinutes().toString().padStart(2, '0') +
|
|
12
|
-
d.getSeconds().toString().padStart(2, '0')
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
module.exports = { yyyymmddhhmmss };
|
|
1
|
+
// Get a date object in the correct format, without requiring a full out library
|
|
2
|
+
// like "moment.js".
|
|
3
|
+
function yyyymmddhhmmss() {
|
|
4
|
+
const d = new Date();
|
|
5
|
+
|
|
6
|
+
return (
|
|
7
|
+
d.getFullYear().toString() +
|
|
8
|
+
(d.getMonth() + 1).toString().padStart(2, '0') +
|
|
9
|
+
d.getDate().toString().padStart(2, '0') +
|
|
10
|
+
d.getHours().toString().padStart(2, '0') +
|
|
11
|
+
d.getMinutes().toString().padStart(2, '0') +
|
|
12
|
+
d.getSeconds().toString().padStart(2, '0')
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
module.exports = { yyyymmddhhmmss };
|