knex 0.14.2 → 0.14.6
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 +77 -0
- package/CONTRIBUTING.md +116 -1
- package/bin/cli.js +4 -3
- package/lib/client.js +111 -105
- package/lib/dialects/maria/index.js +7 -4
- package/lib/dialects/mssql/index.js +5 -4
- package/lib/dialects/mssql/query/compiler.js +19 -4
- package/lib/dialects/mssql/schema/columncompiler.js +2 -0
- package/lib/dialects/mssql/schema/tablecompiler.js +2 -2
- package/lib/dialects/mysql/index.js +12 -7
- package/lib/dialects/mysql/query/compiler.js +11 -1
- package/lib/dialects/mysql/schema/columncompiler.js +1 -1
- package/lib/dialects/mysql/schema/tablecompiler.js +3 -3
- package/lib/dialects/mysql2/index.js +2 -60
- package/lib/dialects/oracle/index.js +1 -1
- package/lib/dialects/oracle/query/compiler.js +12 -11
- package/lib/dialects/oracle/schema/columncompiler.js +4 -0
- package/lib/dialects/oracle/transaction.js +6 -0
- package/lib/dialects/oracledb/index.js +2 -2
- package/lib/dialects/oracledb/query/compiler.js +5 -3
- package/lib/dialects/oracledb/transaction.js +1 -0
- package/lib/dialects/postgres/index.js +10 -3
- package/lib/dialects/postgres/query/compiler.js +21 -4
- package/lib/dialects/postgres/schema/columncompiler.js +5 -0
- package/lib/dialects/postgres/schema/compiler.js +2 -2
- package/lib/dialects/redshift/index.js +102 -0
- package/lib/dialects/redshift/query/compiler.js +142 -0
- package/lib/dialects/redshift/schema/columnbuilder.js +34 -0
- package/lib/dialects/redshift/schema/columncompiler.js +73 -0
- package/lib/dialects/redshift/schema/compiler.js +26 -0
- package/lib/dialects/redshift/schema/tablecompiler.js +133 -0
- package/lib/dialects/redshift/transaction.js +56 -0
- package/lib/dialects/sqlite3/query/compiler.js +26 -4
- package/lib/formatter.js +34 -3
- package/lib/helpers.js +16 -3
- package/lib/interface.js +8 -0
- package/lib/migrate/index.js +58 -31
- package/lib/migrate/stub/coffee.stub +12 -12
- 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/ls.stub +14 -14
- package/lib/query/builder.js +32 -2
- package/lib/query/compiler.js +89 -31
- package/lib/query/methods.js +1 -1
- package/lib/query/string.js +2 -2
- package/lib/raw.js +4 -4
- package/lib/runner.js +20 -2
- package/lib/schema/builder.js +6 -0
- package/lib/schema/columnbuilder.js +4 -0
- package/lib/schema/columncompiler.js +4 -1
- package/lib/schema/compiler.js +11 -1
- package/lib/schema/helpers.js +23 -1
- package/lib/schema/tablebuilder.js +2 -0
- package/lib/schema/tablecompiler.js +12 -1
- package/lib/transaction.js +4 -0
- package/package.json +56 -49
- package/scripts/mssql-docker-compose.yml +26 -0
- package/scripts/oracle-tests-Dockerfile +49 -0
- package/scripts/release.sh +0 -0
- package/scripts/stress-test/README.txt +18 -0
- package/scripts/stress-test/docker-compose.yml +44 -0
- package/scripts/stress-test/knex-stress-test.js +162 -0
- package/scripts/stress-test/mysql2-random-hanging-every-now-and-then.js +132 -0
- package/scripts/stress-test/mysql2-sudden-exit-without-error.js +98 -0
- package/scripts/stress-test/reconnect-test-mysql-based-drivers.js +174 -0
- package/src/client.js +120 -107
- package/src/dialects/maria/index.js +8 -5
- package/src/dialects/mssql/index.js +6 -5
- package/src/dialects/mssql/query/compiler.js +17 -6
- package/src/dialects/mssql/schema/columncompiler.js +2 -0
- package/src/dialects/mssql/schema/tablecompiler.js +2 -2
- package/src/dialects/mysql/index.js +15 -11
- package/src/dialects/mysql/query/compiler.js +8 -2
- package/src/dialects/mysql/schema/columncompiler.js +1 -1
- package/src/dialects/mysql/schema/tablecompiler.js +3 -3
- package/src/dialects/mysql2/index.js +4 -49
- package/src/dialects/oracle/index.js +1 -1
- package/src/dialects/oracle/query/compiler.js +9 -12
- package/src/dialects/oracle/schema/columncompiler.js +6 -1
- package/src/dialects/oracle/transaction.js +18 -13
- package/src/dialects/oracledb/index.js +2 -2
- package/src/dialects/oracledb/query/compiler.js +8 -6
- package/src/dialects/oracledb/transaction.js +1 -0
- package/src/dialects/postgres/index.js +10 -3
- package/src/dialects/postgres/query/compiler.js +19 -5
- package/src/dialects/postgres/schema/columncompiler.js +5 -1
- package/src/dialects/postgres/schema/compiler.js +2 -2
- package/src/dialects/redshift/index.js +74 -0
- package/src/dialects/redshift/query/compiler.js +111 -0
- package/src/dialects/redshift/schema/columnbuilder.js +23 -0
- package/src/dialects/redshift/schema/columncompiler.js +59 -0
- package/src/dialects/redshift/schema/compiler.js +14 -0
- package/src/dialects/redshift/schema/tablecompiler.js +92 -0
- package/src/dialects/redshift/transaction.js +21 -0
- package/src/dialects/sqlite3/query/compiler.js +20 -4
- package/src/dialects/sqlite3/schema/ddl.js +21 -21
- package/src/formatter.js +29 -5
- package/src/helpers.js +24 -3
- package/src/interface.js +5 -1
- package/src/migrate/index.js +58 -29
- package/src/migrate/stub/coffee.stub +12 -12
- package/src/migrate/stub/eg.stub +14 -14
- package/src/migrate/stub/js.stub +15 -15
- package/src/migrate/stub/knexfile-coffee.stub +34 -34
- package/src/migrate/stub/knexfile-eg.stub +43 -43
- package/src/migrate/stub/knexfile-js.stub +44 -44
- package/src/migrate/stub/knexfile-ls.stub +35 -35
- package/src/migrate/stub/ls.stub +14 -14
- package/src/query/builder.js +27 -3
- package/src/query/compiler.js +83 -36
- package/src/query/methods.js +1 -0
- package/src/query/string.js +2 -2
- package/src/raw.js +4 -4
- package/src/runner.js +26 -11
- package/src/schema/builder.js +11 -0
- package/src/schema/columnbuilder.js +4 -1
- package/src/schema/columncompiler.js +9 -4
- package/src/schema/compiler.js +8 -2
- package/src/schema/helpers.js +14 -1
- package/src/schema/tablebuilder.js +2 -0
- package/src/schema/tablecompiler.js +12 -3
- package/src/transaction.js +31 -26
- package/src/util/batchInsert.js +1 -1
- package/scripts/docker-for-test.sh +0 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,83 @@
|
|
|
1
1
|
|
|
2
2
|
# Master (Unreleased)
|
|
3
3
|
|
|
4
|
+
# 0.14.6 - 12 Apr, 2018
|
|
5
|
+
|
|
6
|
+
### Bug fixes:
|
|
7
|
+
|
|
8
|
+
- Restored functionality of query event #2566 (#2549)
|
|
9
|
+
|
|
10
|
+
# 0.14.5 - 8 Apr, 2018
|
|
11
|
+
|
|
12
|
+
### Bug fixes:
|
|
13
|
+
|
|
14
|
+
- Fix wrapping returning column on oracledb #2554
|
|
15
|
+
|
|
16
|
+
### New Features:
|
|
17
|
+
|
|
18
|
+
- Support passing DB schema name for migrations #2499 #2559
|
|
19
|
+
- add clearOrder method #2360 #2553
|
|
20
|
+
- Added knexTxId to query events and debug calls #2476
|
|
21
|
+
- Support multi-column `whereIn` with query #1390
|
|
22
|
+
- Added error if chaining update/insert/etc with first() #2506
|
|
23
|
+
- Checks for an empty, undefined or null object on transacting #2494
|
|
24
|
+
- countDistinct with multiple columns #2449
|
|
25
|
+
|
|
26
|
+
### Test / internal changes
|
|
27
|
+
|
|
28
|
+
- Added npm run test:oracledb command that runs oracledb tests in docker #2491
|
|
29
|
+
- Runnin mssql tests in docker #2496
|
|
30
|
+
- Update dependencies #2561
|
|
31
|
+
|
|
32
|
+
# 0.14.4 - 19 Feb, 2018
|
|
33
|
+
|
|
34
|
+
### Bug fixes:
|
|
35
|
+
|
|
36
|
+
- containsUndefined only validate plain objects. Fixes #1898 (#2468)
|
|
37
|
+
- Add warning when using .returning() in sqlite3. Fixes #1660 (#2471)
|
|
38
|
+
- Throw an error if .update() results in an empty sql (#2472)
|
|
39
|
+
- Removed unnecessary createTableIfNotExist and replaced with createTable (#2473)
|
|
40
|
+
|
|
41
|
+
### New Features:
|
|
42
|
+
|
|
43
|
+
- Allow calling lock procedures (such as forUpdate) outside of transaction. Fixes #2403. (#2475)
|
|
44
|
+
- Added test and documentation for Event 'start' (#2488)
|
|
45
|
+
|
|
46
|
+
### Test / internal changes
|
|
47
|
+
|
|
48
|
+
- Added stress test, which uses TCP proxy to simulate flaky connection #2460
|
|
49
|
+
- Removed old docker tests, new stress test setup (#2474)
|
|
50
|
+
- Removed unused property __cid on the base client (#2481)
|
|
51
|
+
- Changed rm to rimraf in 'npm run dev' (#2483)
|
|
52
|
+
- Changed babel preset and use latest node as target when running dev (#2484)
|
|
53
|
+
|
|
54
|
+
# 0.14.3 - 8 Feb, 2018
|
|
55
|
+
|
|
56
|
+
### Bug fixes:
|
|
57
|
+
|
|
58
|
+
- Use tarn as pool instead of generic-pool which has been given various problems #2450
|
|
59
|
+
- Fixed mysql issue where add columns failed if using both after and collate #2432
|
|
60
|
+
- CLI sets exit-code 1 if the command supplied was not parseable #2358
|
|
61
|
+
- Set toNative() to be not enumerable #2388
|
|
62
|
+
- Use wrapIdentifier in columnInfo. fixes #2402 #2405
|
|
63
|
+
- Fixed a bug when using .returning (OUTPUT) in an update query with joins in MSSQL #2399
|
|
64
|
+
- Better error message when running migrations fail before even starting run migrations #2373
|
|
65
|
+
- Read oracle's UV_THREADPOOL_SIZE env variable correctly #2372
|
|
66
|
+
- Added decimal variable precision / scale support #2353
|
|
67
|
+
|
|
68
|
+
### New Features:
|
|
69
|
+
|
|
70
|
+
- Added queryContext to schema and query builders #2314
|
|
71
|
+
- Added redshift dialect #2233
|
|
72
|
+
- Added warning when one uses .createTableIfNotExist and deprecated it from docs #2458
|
|
73
|
+
|
|
74
|
+
### Test / internal changes
|
|
75
|
+
|
|
76
|
+
- Update dependencies and fix ESLint warnings accordingly #2433
|
|
77
|
+
- Disable oracledb tests from non LTS nodes #2407
|
|
78
|
+
- Update dependencies #2422
|
|
79
|
+
|
|
80
|
+
|
|
4
81
|
# 0.14.2 - 24 Nov, 2017
|
|
5
82
|
|
|
6
83
|
### Bug fixes:
|
package/CONTRIBUTING.md
CHANGED
|
@@ -22,6 +22,82 @@ Documentation is no longer maintained in knex master repository. All the documen
|
|
|
22
22
|
|
|
23
23
|
Documentation pull requests should not be merged before knex version which has the new documented feature is released.
|
|
24
24
|
|
|
25
|
+
## I would like to add support for new dialect to knex, is it possible?
|
|
26
|
+
|
|
27
|
+
Currently there are already way too many dialects supported in `knex` and instead of adding new dialect to central codebase, all the dialects should be moved to separate npm packages out from `knex` core library with their respective maintainers and test suites.
|
|
28
|
+
|
|
29
|
+
So if you like to write your own dialect, you can just inherit own dialect from knex base classes and use it by passing dilaect to knex in knex configuration (https://runkit.com/embed/90b3cpyr4jh2):
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
// simple dialect overriding sqlite3 dialect to use sqlite3-offline driver
|
|
33
|
+
require('sqlite3-offline');
|
|
34
|
+
const Knex = require("knex");
|
|
35
|
+
|
|
36
|
+
const Dialect = require(`knex/lib/dialects/sqlite3/index.js`);
|
|
37
|
+
Dialect.prototype._driver = () => require('sqlite3-offline');
|
|
38
|
+
|
|
39
|
+
const knex = Knex({
|
|
40
|
+
client: Dialect,
|
|
41
|
+
connection: ':memory:'
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
console.log(
|
|
45
|
+
knex.select(knex.raw(1)).toSQL()
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
await knex.schema.createTable('fooobar', (t) => {
|
|
49
|
+
t.bigincrements('id');
|
|
50
|
+
t.string('data');
|
|
51
|
+
});
|
|
52
|
+
await knex('fooobar').insert({ data: 'nomnom' });
|
|
53
|
+
|
|
54
|
+
console.log("Gimme all the data:", await knex('fooobar'));
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## What is minimal code to reproduce bug and why I have to provide that when I can just tell whats the problem is
|
|
58
|
+
|
|
59
|
+
Writing minimal reproduction code for the problem is timeconsuming and some times it also really hard when for
|
|
60
|
+
example when the original code where the bug happens is written using express or mocha. So why it is necessary
|
|
61
|
+
for me to commit so much time to it when the problem is in `knex`? Contributors should be grateful that I reported
|
|
62
|
+
the bug I found.
|
|
63
|
+
|
|
64
|
+
The point of runnable code to reproduce the problem is to easily verify that there really is a problem and that the one
|
|
65
|
+
who did the report did nothing wrong (surprisingly often problem is in the user code). So instead of just description
|
|
66
|
+
what to do the complete code encourages devs to actually test out that problem exists and start solving it and it
|
|
67
|
+
saves lots of time.
|
|
68
|
+
|
|
69
|
+
tl;dr list:
|
|
70
|
+
|
|
71
|
+
1. Actually in most of the cases developer already figures out what was the problem when writing the minimal test case
|
|
72
|
+
or if there was problem how stuff was initilized or how async code was written it is easy to point out the problem.
|
|
73
|
+
|
|
74
|
+
2. It motivates developer to actually try out if the bug really exist by not having to figure out from incomplete example
|
|
75
|
+
environment in which and how bug actually manifests.
|
|
76
|
+
|
|
77
|
+
3. There are curently very few people fixing knex issues and if one has to put easily 15-30 minutes time to issue just
|
|
78
|
+
to see that I cannot reproduce this issue it just wastes development hours that were available for improving knex.
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
Test case should initialize needed tables, insert needed data and fail...
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
const knex = require('knex')({
|
|
85
|
+
client: 'pg',
|
|
86
|
+
connection: 'postgres:///knex_test'
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
async function main() {
|
|
90
|
+
await knex.schema.createTable(...);
|
|
91
|
+
await knex('table').insert({foo: 'bar}');
|
|
92
|
+
await knex.destroy();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
main();
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Usually issues without reproduction code available are just closed and if the same issue is reported multiple
|
|
99
|
+
times maybe someone looks into it.
|
|
100
|
+
|
|
25
101
|
## Integration Tests
|
|
26
102
|
|
|
27
103
|
### The Easy Way
|
|
@@ -40,7 +116,7 @@ You can optionally specify which dialects to test using the `DB` environment var
|
|
|
40
116
|
* postgres
|
|
41
117
|
* sqlite3
|
|
42
118
|
* maria
|
|
43
|
-
*
|
|
119
|
+
* oracledb
|
|
44
120
|
* mssql
|
|
45
121
|
|
|
46
122
|
```bash
|
|
@@ -69,6 +145,45 @@ Once this is done, check it works by attempting to login:
|
|
|
69
145
|
psql -h localhost -U postgres -d knex_test
|
|
70
146
|
```
|
|
71
147
|
|
|
148
|
+
### Running OracleDB tests in docker
|
|
149
|
+
|
|
150
|
+
Since node-oracledb driver is so hard to install on every platform, oracle tests
|
|
151
|
+
are actually ran inside docker container. Container has Oracle XE g11,
|
|
152
|
+
node 8 and node-oracledb driver installed and copies local knex directory in
|
|
153
|
+
to be able to run the tests.
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
npm run oracledb:test
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
You can also manually start shell in the docker image and run build commands manually:
|
|
160
|
+
```
|
|
161
|
+
docker run -i -t knex-test-oracledb /bin/bash
|
|
162
|
+
|
|
163
|
+
root@34f1f1cd20cf:/#
|
|
164
|
+
|
|
165
|
+
/usr/sbin/startup.sh
|
|
166
|
+
cd knex
|
|
167
|
+
npm install
|
|
168
|
+
npm install oracledb
|
|
169
|
+
npm test
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Runnin MSSQL SQL Server tests
|
|
173
|
+
|
|
174
|
+
SQL Server needs to be started as docker container before running tests
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
# start mssql docker container
|
|
178
|
+
npm run mssql:init
|
|
179
|
+
|
|
180
|
+
# run tests, do changes etc.
|
|
181
|
+
npm run mssql:test
|
|
182
|
+
|
|
183
|
+
# stop mssql container
|
|
184
|
+
npm run mssql:destroy
|
|
185
|
+
```
|
|
186
|
+
|
|
72
187
|
## Want to be Collaborator?
|
|
73
188
|
|
|
74
189
|
There is always room for more collaborators. Be active on resolving github issues / sending pull requests / reviewing code and we will ask you to join.
|
package/bin/cli.js
CHANGED
|
@@ -13,9 +13,9 @@ var cliPkg = require('../package');
|
|
|
13
13
|
|
|
14
14
|
function exit(text) {
|
|
15
15
|
if (text instanceof Error) {
|
|
16
|
-
chalk.red(
|
|
16
|
+
console.error(chalk.red(text.stack));
|
|
17
17
|
} else {
|
|
18
|
-
chalk.red(
|
|
18
|
+
console.error(chalk.red(text));
|
|
19
19
|
}
|
|
20
20
|
process.exit(1);
|
|
21
21
|
}
|
|
@@ -186,7 +186,8 @@ function invoke(env) {
|
|
|
186
186
|
commander.parse(process.argv);
|
|
187
187
|
|
|
188
188
|
Promise.resolve(pending).then(function() {
|
|
189
|
-
commander.
|
|
189
|
+
commander.outputHelp();
|
|
190
|
+
exit('Unknown command-line options, exiting');
|
|
190
191
|
});
|
|
191
192
|
}
|
|
192
193
|
|
package/lib/client.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _assign2 = require('babel-runtime/core-js/object/assign');
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _assign3 = _interopRequireDefault(_assign2);
|
|
8
8
|
|
|
9
9
|
var _defaults2 = require('lodash/defaults');
|
|
10
10
|
|
|
@@ -18,9 +18,9 @@ var _uniqueId2 = require('lodash/uniqueId');
|
|
|
18
18
|
|
|
19
19
|
var _uniqueId3 = _interopRequireDefault(_uniqueId2);
|
|
20
20
|
|
|
21
|
-
var
|
|
21
|
+
var _assign4 = require('lodash/assign');
|
|
22
22
|
|
|
23
|
-
var
|
|
23
|
+
var _assign5 = _interopRequireDefault(_assign4);
|
|
24
24
|
|
|
25
25
|
var _bluebird = require('bluebird');
|
|
26
26
|
|
|
@@ -78,13 +78,7 @@ var _columncompiler = require('./schema/columncompiler');
|
|
|
78
78
|
|
|
79
79
|
var _columncompiler2 = _interopRequireDefault(_columncompiler);
|
|
80
80
|
|
|
81
|
-
var
|
|
82
|
-
|
|
83
|
-
var genericPool = _interopRequireWildcard(_genericPool);
|
|
84
|
-
|
|
85
|
-
var _errors = require('generic-pool/lib/errors');
|
|
86
|
-
|
|
87
|
-
var genericPoolErrors = _interopRequireWildcard(_errors);
|
|
81
|
+
var _tarn = require('tarn');
|
|
88
82
|
|
|
89
83
|
var _inherits = require('inherits');
|
|
90
84
|
|
|
@@ -102,11 +96,6 @@ var debug = require('debug')('knex:client');
|
|
|
102
96
|
var debugQuery = require('debug')('knex:query');
|
|
103
97
|
var debugBindings = require('debug')('knex:bindings');
|
|
104
98
|
|
|
105
|
-
var id = 0;
|
|
106
|
-
function clientId() {
|
|
107
|
-
return 'client' + id++;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
99
|
// The base client provides the general structure
|
|
111
100
|
// for a dialect specific client object.
|
|
112
101
|
function Client() {
|
|
@@ -125,7 +114,6 @@ function Client() {
|
|
|
125
114
|
if (this.driverName && config.connection) {
|
|
126
115
|
this.initializeDriver();
|
|
127
116
|
if (!config.pool || config.pool && config.pool.max !== 0) {
|
|
128
|
-
this.__cid = clientId();
|
|
129
117
|
this.initializePool(config);
|
|
130
118
|
}
|
|
131
119
|
}
|
|
@@ -136,9 +124,9 @@ function Client() {
|
|
|
136
124
|
}
|
|
137
125
|
(0, _inherits2.default)(Client, _events.EventEmitter);
|
|
138
126
|
|
|
139
|
-
(0,
|
|
140
|
-
formatter: function formatter() {
|
|
141
|
-
return new _formatter2.default(this);
|
|
127
|
+
(0, _assign5.default)(Client.prototype, {
|
|
128
|
+
formatter: function formatter(builder) {
|
|
129
|
+
return new _formatter2.default(this, builder);
|
|
142
130
|
},
|
|
143
131
|
queryBuilder: function queryBuilder() {
|
|
144
132
|
return new _builder2.default(this);
|
|
@@ -203,24 +191,38 @@ function Client() {
|
|
|
203
191
|
var _this2 = this;
|
|
204
192
|
|
|
205
193
|
if (typeof obj === 'string') obj = { sql: obj };
|
|
206
|
-
obj.sql = this.positionBindings(obj.sql);
|
|
207
194
|
obj.bindings = this.prepBindings(obj.bindings);
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
195
|
+
|
|
196
|
+
var __knexUid = connection.__knexUid,
|
|
197
|
+
__knexTxId = connection.__knexTxId;
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
this.emit('query', (0, _assign5.default)({ __knexUid: __knexUid, __knexTxId: __knexTxId }, obj));
|
|
201
|
+
debugQuery(obj.sql, __knexTxId);
|
|
202
|
+
debugBindings(obj.bindings, __knexTxId);
|
|
203
|
+
|
|
204
|
+
obj.sql = this.positionBindings(obj.sql);
|
|
205
|
+
|
|
211
206
|
return this._query(connection, obj).catch(function (err) {
|
|
212
207
|
err.message = _this2._formatQuery(obj.sql, obj.bindings) + ' - ' + err.message;
|
|
213
|
-
_this2.emit('query-error', err, (0,
|
|
208
|
+
_this2.emit('query-error', err, (0, _assign5.default)({ __knexUid: __knexUid, __knexTxId: __knexTxId }, obj));
|
|
214
209
|
throw err;
|
|
215
210
|
});
|
|
216
211
|
},
|
|
217
212
|
stream: function stream(connection, obj, _stream, options) {
|
|
218
213
|
if (typeof obj === 'string') obj = { sql: obj };
|
|
219
|
-
obj.sql = this.positionBindings(obj.sql);
|
|
220
214
|
obj.bindings = this.prepBindings(obj.bindings);
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
215
|
+
|
|
216
|
+
var __knexUid = connection.__knexUid,
|
|
217
|
+
__knexTxId = connection.__knexTxId;
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
this.emit('query', (0, _assign5.default)({ __knexUid: __knexUid, __knexTxId: __knexTxId }, obj));
|
|
221
|
+
debugQuery(obj.sql, __knexTxId);
|
|
222
|
+
debugBindings(obj.bindings, __knexTxId);
|
|
223
|
+
|
|
224
|
+
obj.sql = this.positionBindings(obj.sql);
|
|
225
|
+
|
|
224
226
|
return this._stream(connection, obj, _stream, options);
|
|
225
227
|
},
|
|
226
228
|
prepBindings: function prepBindings(bindings) {
|
|
@@ -229,17 +231,20 @@ function Client() {
|
|
|
229
231
|
positionBindings: function positionBindings(sql) {
|
|
230
232
|
return sql;
|
|
231
233
|
},
|
|
232
|
-
postProcessResponse: function postProcessResponse(resp) {
|
|
234
|
+
postProcessResponse: function postProcessResponse(resp, queryContext) {
|
|
233
235
|
if (this.config.postProcessResponse) {
|
|
234
|
-
return this.config.postProcessResponse(resp);
|
|
236
|
+
return this.config.postProcessResponse(resp, queryContext);
|
|
235
237
|
}
|
|
236
238
|
return resp;
|
|
237
239
|
},
|
|
238
|
-
wrapIdentifier: function wrapIdentifier(value) {
|
|
240
|
+
wrapIdentifier: function wrapIdentifier(value, queryContext) {
|
|
241
|
+
return this.customWrapIdentifier(value, this.wrapIdentifierImpl, queryContext);
|
|
242
|
+
},
|
|
243
|
+
customWrapIdentifier: function customWrapIdentifier(value, origImpl, queryContext) {
|
|
239
244
|
if (this.config.wrapIdentifier) {
|
|
240
|
-
return this.config.wrapIdentifier(value,
|
|
245
|
+
return this.config.wrapIdentifier(value, origImpl, queryContext);
|
|
241
246
|
}
|
|
242
|
-
return
|
|
247
|
+
return origImpl(value);
|
|
243
248
|
},
|
|
244
249
|
wrapIdentifierImpl: function wrapIdentifierImpl(value) {
|
|
245
250
|
return value !== '*' ? '"' + value.replace(/"/g, '""') + '"' : '*';
|
|
@@ -252,78 +257,59 @@ function Client() {
|
|
|
252
257
|
}
|
|
253
258
|
},
|
|
254
259
|
poolDefaults: function poolDefaults() {
|
|
255
|
-
return { min: 2, max: 10,
|
|
260
|
+
return { min: 2, max: 10, propagateCreateError: true };
|
|
256
261
|
},
|
|
257
262
|
getPoolSettings: function getPoolSettings(poolConfig) {
|
|
258
263
|
var _this3 = this;
|
|
259
264
|
|
|
260
265
|
poolConfig = (0, _defaults3.default)({}, poolConfig, this.poolDefaults());
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
if (
|
|
264
|
-
|
|
265
|
-
if (isNaN(timeout) || timeout <= 0) {
|
|
266
|
-
throw new Error(path + ' must be a positive int');
|
|
267
|
-
}
|
|
266
|
+
|
|
267
|
+
['maxWaitingClients', 'testOnBorrow', 'fifo', 'priorityRange', 'autostart', 'evictionRunIntervalMillis', 'numTestsPerRun', 'softIdleTimeoutMillis', 'Promise'].forEach(function (option) {
|
|
268
|
+
if (option in poolConfig) {
|
|
269
|
+
helpers.warn(['Pool config option "' + option + '" is no longer supported.', 'See https://github.com/Vincit/tarn.js for possible pool config options.'].join(' '));
|
|
268
270
|
}
|
|
269
|
-
|
|
270
|
-
};
|
|
271
|
+
});
|
|
271
272
|
|
|
272
|
-
|
|
273
|
-
// choose the smallest, positive timeout setting and set on poolConfig
|
|
274
|
-
var timeouts = [timeoutValidator(this.config, 'acquireConnectionTimeout') || 60000, timeoutValidator({ pool: poolConfig }, 'pool.acquireTimeoutMillis')].filter(function (timeout) {
|
|
273
|
+
var timeouts = [this.config.acquireConnectionTimeout || 60000, poolConfig.acquireTimeoutMillis].filter(function (timeout) {
|
|
275
274
|
return timeout !== undefined;
|
|
276
275
|
});
|
|
276
|
+
|
|
277
|
+
// acquire connection timeout can be set on config or config.pool
|
|
278
|
+
// choose the smallest, positive timeout setting and set on poolConfig
|
|
277
279
|
poolConfig.acquireTimeoutMillis = Math.min.apply(Math, timeouts);
|
|
278
280
|
|
|
279
|
-
return {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
return _this3.acquireRawConnection().tap(function (connection) {
|
|
284
|
-
connection.__knexUid = (0, _uniqueId3.default)('__knexUid');
|
|
285
|
-
if (poolConfig.afterCreate) {
|
|
286
|
-
return _bluebird2.default.promisify(poolConfig.afterCreate)(connection);
|
|
287
|
-
}
|
|
288
|
-
}).catch(function (err) {
|
|
289
|
-
// Acquire connection must never reject, because generic-pool
|
|
290
|
-
// will retry trying to get connection until acquireConnectionTimeout is
|
|
291
|
-
// reached. acquireConnectionTimeout should trigger in knex only
|
|
292
|
-
// in that case if aquiring connection waits because pool is full
|
|
293
|
-
// https://github.com/coopernurse/node-pool/pull/184
|
|
294
|
-
// https://github.com/tgriesser/knex/issues/2325
|
|
295
|
-
return {
|
|
296
|
-
genericPoolMissingRetryCountHack: true,
|
|
297
|
-
__knex__disposed: err,
|
|
298
|
-
query: function query() {
|
|
299
|
-
throw err; // pass error to query
|
|
300
|
-
}
|
|
301
|
-
};
|
|
302
|
-
});
|
|
303
|
-
},
|
|
304
|
-
destroy: function destroy(connection) {
|
|
305
|
-
if (connection.genericPoolMissingRetryCountHack) {
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
if (poolConfig.beforeDestroy) {
|
|
309
|
-
helpers.warn('\n beforeDestroy is deprecated, please open an issue if you use this\n to discuss alternative apis\n ');
|
|
310
|
-
poolConfig.beforeDestroy(connection, function () {});
|
|
311
|
-
}
|
|
312
|
-
if (connection !== void 0) {
|
|
313
|
-
return _this3.destroyRawConnection(connection);
|
|
314
|
-
}
|
|
281
|
+
return (0, _assign3.default)(poolConfig, {
|
|
282
|
+
create: function create() {
|
|
283
|
+
return _this3.acquireRawConnection().tap(function (connection) {
|
|
284
|
+
connection.__knexUid = (0, _uniqueId3.default)('__knexUid');
|
|
315
285
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
validate: function validate(connection) {
|
|
319
|
-
if (connection.__knex__disposed) {
|
|
320
|
-
helpers.warn('Connection Error: ' + connection.__knex__disposed);
|
|
321
|
-
return _bluebird2.default.resolve(false);
|
|
286
|
+
if (poolConfig.afterCreate) {
|
|
287
|
+
return _bluebird2.default.promisify(poolConfig.afterCreate)(connection);
|
|
322
288
|
}
|
|
323
|
-
|
|
289
|
+
});
|
|
290
|
+
},
|
|
291
|
+
|
|
292
|
+
destroy: function destroy(connection) {
|
|
293
|
+
if (poolConfig.beforeDestroy) {
|
|
294
|
+
helpers.warn('\n beforeDestroy is deprecated, please open an issue if you use this\n to discuss alternative apis\n ');
|
|
295
|
+
|
|
296
|
+
poolConfig.beforeDestroy(connection, function () {});
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (connection !== void 0) {
|
|
300
|
+
return _this3.destroyRawConnection(connection);
|
|
324
301
|
}
|
|
302
|
+
},
|
|
303
|
+
|
|
304
|
+
validate: function validate(connection) {
|
|
305
|
+
if (connection.__knex__disposed) {
|
|
306
|
+
helpers.warn('Connection Error: ' + connection.__knex__disposed);
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return _this3.validateConnection(connection);
|
|
325
311
|
}
|
|
326
|
-
};
|
|
312
|
+
});
|
|
327
313
|
},
|
|
328
314
|
initializePool: function initializePool(config) {
|
|
329
315
|
if (this.pool) {
|
|
@@ -331,23 +317,26 @@ function Client() {
|
|
|
331
317
|
return;
|
|
332
318
|
}
|
|
333
319
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
this.pool = genericPool.createPool(poolSettings.factory, poolSettings.config);
|
|
320
|
+
this.pool = new _tarn.Pool(this.getPoolSettings(config.pool));
|
|
337
321
|
},
|
|
338
322
|
validateConnection: function validateConnection(connection) {
|
|
339
|
-
return
|
|
323
|
+
return true;
|
|
340
324
|
},
|
|
341
325
|
|
|
342
326
|
|
|
343
327
|
// Acquire a connection from the pool.
|
|
344
328
|
acquireConnection: function acquireConnection() {
|
|
329
|
+
var _this4 = this;
|
|
330
|
+
|
|
345
331
|
if (!this.pool) {
|
|
346
332
|
return _bluebird2.default.reject(new Error('Unable to acquire a connection'));
|
|
347
333
|
}
|
|
348
|
-
|
|
334
|
+
|
|
335
|
+
return _bluebird2.default.try(function () {
|
|
336
|
+
return _this4.pool.acquire().promise;
|
|
337
|
+
}).tap(function (connection) {
|
|
349
338
|
debug('acquired connection from pool: %s', connection.__knexUid);
|
|
350
|
-
}).catch(
|
|
339
|
+
}).catch(_tarn.TimeoutError, function () {
|
|
351
340
|
throw new _bluebird2.default.TimeoutError('Knex: Timeout acquiring a connection. The pool is probably full. ' + 'Are you missing a .transacting(trx) call?');
|
|
352
341
|
});
|
|
353
342
|
},
|
|
@@ -357,24 +346,41 @@ function Client() {
|
|
|
357
346
|
// returning a promise resolved when the connection is released.
|
|
358
347
|
releaseConnection: function releaseConnection(connection) {
|
|
359
348
|
debug('releasing connection to pool: %s', connection.__knexUid);
|
|
360
|
-
|
|
349
|
+
var didRelease = this.pool.release(connection);
|
|
350
|
+
|
|
351
|
+
if (!didRelease) {
|
|
361
352
|
debug('pool refused connection: %s', connection.__knexUid);
|
|
362
|
-
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return _bluebird2.default.resolve();
|
|
363
356
|
},
|
|
364
357
|
|
|
365
358
|
|
|
366
359
|
// Destroy the current connection pool for the client.
|
|
367
360
|
destroy: function destroy(callback) {
|
|
368
|
-
var
|
|
361
|
+
var _this5 = this;
|
|
362
|
+
|
|
363
|
+
var promise = null;
|
|
364
|
+
|
|
365
|
+
if (this.pool) {
|
|
366
|
+
promise = this.pool.destroy();
|
|
367
|
+
} else {
|
|
368
|
+
promise = _bluebird2.default.resolve();
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
return promise.then(function () {
|
|
372
|
+
_this5.pool = void 0;
|
|
369
373
|
|
|
370
|
-
return _bluebird2.default.resolve(this.pool && this.pool.drain().then(function () {
|
|
371
|
-
return _this4.pool.clear();
|
|
372
|
-
}).then(function () {
|
|
373
|
-
_this4.pool = void 0;
|
|
374
374
|
if (typeof callback === 'function') {
|
|
375
375
|
callback();
|
|
376
376
|
}
|
|
377
|
-
}))
|
|
377
|
+
}).catch(function (err) {
|
|
378
|
+
if (typeof callback === 'function') {
|
|
379
|
+
callback(err);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
return _bluebird2.default.reject(err);
|
|
383
|
+
});
|
|
378
384
|
},
|
|
379
385
|
|
|
380
386
|
|
|
@@ -69,16 +69,19 @@ function Client_MariaSQL(config) {
|
|
|
69
69
|
var connection = new _this.driver();
|
|
70
70
|
connection.connect((0, _assign3.default)({ metadata: true }, _this.connectionSettings));
|
|
71
71
|
connection.on('ready', function () {
|
|
72
|
-
connection.removeAllListeners('error');
|
|
73
72
|
resolver(connection);
|
|
74
|
-
}).on('error',
|
|
73
|
+
}).on('error', function (err) {
|
|
74
|
+
connection.__knex__disposed = err;
|
|
75
|
+
rejecter(err);
|
|
76
|
+
});
|
|
75
77
|
});
|
|
76
78
|
},
|
|
77
79
|
validateConnection: function validateConnection(connection) {
|
|
78
80
|
if (connection.connected === true) {
|
|
79
|
-
return
|
|
81
|
+
return true;
|
|
80
82
|
}
|
|
81
|
-
|
|
83
|
+
|
|
84
|
+
return false;
|
|
82
85
|
},
|
|
83
86
|
|
|
84
87
|
|
|
@@ -104,7 +104,7 @@ var SQL_BIGINT_SAFE = { MIN: -9007199254740991, MAX: 9007199254740991
|
|
|
104
104
|
return require('mssql');
|
|
105
105
|
},
|
|
106
106
|
formatter: function formatter() {
|
|
107
|
-
return new MSSQL_Formatter(this);
|
|
107
|
+
return new (Function.prototype.bind.apply(MSSQL_Formatter, [null].concat([this], Array.prototype.slice.call(arguments))))();
|
|
108
108
|
},
|
|
109
109
|
transaction: function transaction() {
|
|
110
110
|
return new (Function.prototype.bind.apply(_transaction2.default, [null].concat([this], Array.prototype.slice.call(arguments))))();
|
|
@@ -122,7 +122,7 @@ var SQL_BIGINT_SAFE = { MIN: -9007199254740991, MAX: 9007199254740991
|
|
|
122
122
|
return new (Function.prototype.bind.apply(_columncompiler2.default, [null].concat([this], Array.prototype.slice.call(arguments))))();
|
|
123
123
|
},
|
|
124
124
|
wrapIdentifierImpl: function wrapIdentifierImpl(value) {
|
|
125
|
-
return value !== '*' ? '[' + value.replace(/\[/g, '
|
|
125
|
+
return value !== '*' ? '[' + value.replace(/\[/g, '[') + ']' : '*';
|
|
126
126
|
},
|
|
127
127
|
|
|
128
128
|
|
|
@@ -146,9 +146,10 @@ var SQL_BIGINT_SAFE = { MIN: -9007199254740991, MAX: 9007199254740991
|
|
|
146
146
|
},
|
|
147
147
|
validateConnection: function validateConnection(connection) {
|
|
148
148
|
if (connection.connected === true) {
|
|
149
|
-
return
|
|
149
|
+
return true;
|
|
150
150
|
}
|
|
151
|
-
|
|
151
|
+
|
|
152
|
+
return false;
|
|
152
153
|
},
|
|
153
154
|
|
|
154
155
|
|