knex 2.2.0 → 2.3.0
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 +16 -0
- package/lib/dialects/mssql/index.js +20 -14
- package/lib/dialects/postgres/schema/pg-columncompiler.js +1 -0
- package/lib/dialects/sqlite3/index.js +10 -6
- package/lib/dialects/sqlite3/query/sqlite-querycompiler.js +17 -0
- package/lib/formatter/wrappingFormatter.js +1 -2
- package/package.json +12 -12
- package/types/index.d.ts +9 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Master (Unreleased)
|
|
2
2
|
|
|
3
|
+
# 2.3.0 - 31 August, 2022
|
|
4
|
+
|
|
5
|
+
### New features:
|
|
6
|
+
|
|
7
|
+
- PostgreSQL: Explicit jsonb support for custom pg clients #5201
|
|
8
|
+
- SQLite: Support returning with sqlite3 and better-sqlite3 #5285
|
|
9
|
+
- MSSQL: Implement mapBinding mssql dialect option #5292
|
|
10
|
+
|
|
11
|
+
### Typings:
|
|
12
|
+
|
|
13
|
+
- Update types for TS 4.8 #5279
|
|
14
|
+
- Fix typo #5267
|
|
15
|
+
- Fix WhereJsonObject withCompositeTableType #5306
|
|
16
|
+
- Fix AnalyticFunction type #5304
|
|
17
|
+
- Infer specific column value type in aggregations #5297
|
|
18
|
+
|
|
3
19
|
# 2.2.0 - 19 July, 2022
|
|
4
20
|
|
|
5
21
|
### New features:
|
|
@@ -333,14 +333,24 @@ class Client_MSSQL extends Client {
|
|
|
333
333
|
_typeForBinding(binding) {
|
|
334
334
|
const Driver = this._driver();
|
|
335
335
|
|
|
336
|
+
if (
|
|
337
|
+
this.connectionSettings.options &&
|
|
338
|
+
this.connectionSettings.options.mapBinding
|
|
339
|
+
) {
|
|
340
|
+
const result = this.connectionSettings.options.mapBinding(binding);
|
|
341
|
+
if (result) {
|
|
342
|
+
return [result.value, result.type];
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
336
346
|
switch (typeof binding) {
|
|
337
347
|
case 'string':
|
|
338
|
-
return Driver.TYPES.NVarChar;
|
|
348
|
+
return [binding, Driver.TYPES.NVarChar];
|
|
339
349
|
case 'boolean':
|
|
340
|
-
return Driver.TYPES.Bit;
|
|
350
|
+
return [binding, Driver.TYPES.Bit];
|
|
341
351
|
case 'number': {
|
|
342
352
|
if (binding % 1 !== 0) {
|
|
343
|
-
return Driver.TYPES.Float;
|
|
353
|
+
return [binding, Driver.TYPES.Float];
|
|
344
354
|
}
|
|
345
355
|
|
|
346
356
|
if (binding < SQL_INT4.MIN || binding > SQL_INT4.MAX) {
|
|
@@ -350,25 +360,21 @@ class Client_MSSQL extends Client {
|
|
|
350
360
|
);
|
|
351
361
|
}
|
|
352
362
|
|
|
353
|
-
return Driver.TYPES.BigInt;
|
|
363
|
+
return [binding, Driver.TYPES.BigInt];
|
|
354
364
|
}
|
|
355
365
|
|
|
356
|
-
return Driver.TYPES.Int;
|
|
366
|
+
return [binding, Driver.TYPES.Int];
|
|
357
367
|
}
|
|
358
368
|
default: {
|
|
359
|
-
// if (binding === null || typeof binding === 'undefined') {
|
|
360
|
-
// return tedious.TYPES.Null;
|
|
361
|
-
// }
|
|
362
|
-
|
|
363
369
|
if (binding instanceof Date) {
|
|
364
|
-
return Driver.TYPES.DateTime;
|
|
370
|
+
return [binding, Driver.TYPES.DateTime];
|
|
365
371
|
}
|
|
366
372
|
|
|
367
373
|
if (binding instanceof Buffer) {
|
|
368
|
-
return Driver.TYPES.VarBinary;
|
|
374
|
+
return [binding, Driver.TYPES.VarBinary];
|
|
369
375
|
}
|
|
370
376
|
|
|
371
|
-
return Driver.TYPES.NVarChar;
|
|
377
|
+
return [binding, Driver.TYPES.NVarChar];
|
|
372
378
|
}
|
|
373
379
|
}
|
|
374
380
|
}
|
|
@@ -401,8 +407,8 @@ class Client_MSSQL extends Client {
|
|
|
401
407
|
}
|
|
402
408
|
|
|
403
409
|
// sets a request input parameter. Detects bigints and decimals and sets type appropriately.
|
|
404
|
-
_setReqInput(req, i,
|
|
405
|
-
const tediousType = this._typeForBinding(
|
|
410
|
+
_setReqInput(req, i, inputBinding) {
|
|
411
|
+
const [binding, tediousType] = this._typeForBinding(inputBinding);
|
|
406
412
|
const bindingName = 'p'.concat(i);
|
|
407
413
|
let options;
|
|
408
414
|
|
|
@@ -126,6 +126,8 @@ class Client_SQLite3 extends Client {
|
|
|
126
126
|
switch (method) {
|
|
127
127
|
case 'insert':
|
|
128
128
|
case 'update':
|
|
129
|
+
callMethod = obj.returning ? 'all' : 'run';
|
|
130
|
+
break;
|
|
129
131
|
case 'counter':
|
|
130
132
|
case 'del':
|
|
131
133
|
callMethod = 'run';
|
|
@@ -190,16 +192,18 @@ class Client_SQLite3 extends Client {
|
|
|
190
192
|
if (response) {
|
|
191
193
|
return response;
|
|
192
194
|
}
|
|
193
|
-
|
|
194
|
-
// ToDo Implement after https://github.com/microsoft/vscode-node-sqlite3/issues/15 is resolved
|
|
195
|
-
this.logger.warn(
|
|
196
|
-
'node-sqlite3 does not currently support RETURNING clause'
|
|
197
|
-
);
|
|
198
195
|
}
|
|
199
196
|
return [ctx.lastID];
|
|
200
197
|
}
|
|
198
|
+
case 'update': {
|
|
199
|
+
if (returning) {
|
|
200
|
+
if (response) {
|
|
201
|
+
return response;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return ctx.changes;
|
|
205
|
+
}
|
|
201
206
|
case 'del':
|
|
202
|
-
case 'update':
|
|
203
207
|
case 'counter':
|
|
204
208
|
return ctx.changes;
|
|
205
209
|
default: {
|
|
@@ -149,6 +149,23 @@ class QueryCompiler_SQLite3 extends QueryCompiler {
|
|
|
149
149
|
};
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
+
// Compiles an `update` query, allowing for a return value.
|
|
153
|
+
update() {
|
|
154
|
+
const withSQL = this.with();
|
|
155
|
+
const updateData = this._prepUpdate(this.single.update);
|
|
156
|
+
const wheres = this.where();
|
|
157
|
+
const { returning } = this.single;
|
|
158
|
+
return {
|
|
159
|
+
sql:
|
|
160
|
+
withSQL +
|
|
161
|
+
`update ${this.single.only ? 'only ' : ''}${this.tableName} ` +
|
|
162
|
+
`set ${updateData.join(', ')}` +
|
|
163
|
+
(wheres ? ` ${wheres}` : '') +
|
|
164
|
+
this._returning(returning),
|
|
165
|
+
returning,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
152
169
|
_ignore(columns) {
|
|
153
170
|
if (columns === true) {
|
|
154
171
|
return ' on conflict do nothing';
|
|
@@ -225,8 +225,7 @@ function rawOrFn(value, method, builder, client, bindingHolder) {
|
|
|
225
225
|
compileCallback(value, method, client, bindingHolder),
|
|
226
226
|
undefined,
|
|
227
227
|
builder,
|
|
228
|
-
client
|
|
229
|
-
bindingHolder
|
|
228
|
+
client
|
|
230
229
|
);
|
|
231
230
|
}
|
|
232
231
|
return unwrapRaw(value, undefined, builder, client, bindingHolder) || '';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "knex",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
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",
|
|
@@ -105,8 +105,8 @@
|
|
|
105
105
|
},
|
|
106
106
|
"devDependencies": {
|
|
107
107
|
"@tsconfig/recommended": "^1.0.1",
|
|
108
|
-
"@types/node": "^18.
|
|
109
|
-
"better-sqlite3": "^7.
|
|
108
|
+
"@types/node": "^18.7.14",
|
|
109
|
+
"better-sqlite3": "^7.6.2",
|
|
110
110
|
"chai": "^4.3.6",
|
|
111
111
|
"chai-as-promised": "^7.1.1",
|
|
112
112
|
"chai-subset-in-order": "^3.1.0",
|
|
@@ -123,26 +123,26 @@
|
|
|
123
123
|
"JSONStream": "^1.3.5",
|
|
124
124
|
"lint-staged": "^13.0.0",
|
|
125
125
|
"mocha": "^10.0.0",
|
|
126
|
-
"mock-fs": "^5.1.
|
|
126
|
+
"mock-fs": "^5.1.4",
|
|
127
127
|
"mysql": "^2.18.1",
|
|
128
128
|
"mysql2": "^2.3.3",
|
|
129
129
|
"nyc": "^15.1.0",
|
|
130
|
-
"oracledb": "^5.
|
|
131
|
-
"pg": "^8.
|
|
132
|
-
"pg-query-stream": "^4.2.
|
|
130
|
+
"oracledb": "^5.4.0",
|
|
131
|
+
"pg": "^8.8.0",
|
|
132
|
+
"pg-query-stream": "^4.2.4",
|
|
133
133
|
"prettier": "2.6.2",
|
|
134
134
|
"rimraf": "^3.0.2",
|
|
135
135
|
"sinon": "^14.0.0",
|
|
136
136
|
"sinon-chai": "^3.7.0",
|
|
137
137
|
"source-map-support": "^0.5.21",
|
|
138
|
-
"sqlite3": "^5.0.
|
|
138
|
+
"sqlite3": "^5.0.11",
|
|
139
139
|
"tap-spec": "^5.0.0",
|
|
140
|
-
"tape": "^5.
|
|
140
|
+
"tape": "^5.6.0",
|
|
141
141
|
"tedious": "^14.4.0",
|
|
142
142
|
"toxiproxy-node-client": "^2.0.6",
|
|
143
|
-
"ts-node": "^10.
|
|
144
|
-
"tsd": "^0.
|
|
145
|
-
"typescript": "4.
|
|
143
|
+
"ts-node": "^10.9.1",
|
|
144
|
+
"tsd": "^0.23.0",
|
|
145
|
+
"typescript": "4.8.2"
|
|
146
146
|
},
|
|
147
147
|
"buildDependencies": [
|
|
148
148
|
"rimraf"
|
package/types/index.d.ts
CHANGED
|
@@ -444,7 +444,7 @@ export declare namespace knex {
|
|
|
444
444
|
class QueryBuilder {
|
|
445
445
|
static extend(
|
|
446
446
|
methodName: string,
|
|
447
|
-
fn: <TRecord extends {} = any, TResult = unknown[]>(
|
|
447
|
+
fn: <TRecord extends {} = any, TResult extends {} = unknown[]>(
|
|
448
448
|
this: Knex.QueryBuilder<TRecord, TResult>,
|
|
449
449
|
...args: any[]
|
|
450
450
|
) =>
|
|
@@ -1760,12 +1760,12 @@ export declare namespace Knex {
|
|
|
1760
1760
|
}
|
|
1761
1761
|
|
|
1762
1762
|
interface WhereJsonObject<TRecord extends {} = any, TResult = unknown[]> {
|
|
1763
|
-
(columnName: keyof TRecord
|
|
1763
|
+
(columnName: keyof ResolveTableType<TRecord>, value: any): QueryBuilder<TRecord, TResult>;
|
|
1764
1764
|
}
|
|
1765
1765
|
|
|
1766
1766
|
interface WhereJsonPath<TRecord extends {} = any, TResult = unknown[]> {
|
|
1767
1767
|
(
|
|
1768
|
-
columnName: keyof TRecord
|
|
1768
|
+
columnName: keyof ResolveTableType<TRecord>,
|
|
1769
1769
|
jsonPath: string,
|
|
1770
1770
|
operator: string,
|
|
1771
1771
|
value: any
|
|
@@ -1864,7 +1864,7 @@ export declare namespace Knex {
|
|
|
1864
1864
|
}
|
|
1865
1865
|
>
|
|
1866
1866
|
>(
|
|
1867
|
-
columnName:
|
|
1867
|
+
columnName: TKey,
|
|
1868
1868
|
options: Readonly<TOptions>
|
|
1869
1869
|
): QueryBuilder<TRecord, TResult2>;
|
|
1870
1870
|
<
|
|
@@ -1918,11 +1918,11 @@ export declare namespace Knex {
|
|
|
1918
1918
|
| TKey
|
|
1919
1919
|
| TKey[]
|
|
1920
1920
|
| {
|
|
1921
|
-
|
|
1921
|
+
column: TKey;
|
|
1922
1922
|
order?: 'asc' | 'desc';
|
|
1923
1923
|
nulls?: 'first' | 'last';
|
|
1924
1924
|
},
|
|
1925
|
-
partitionBy?: TKey | TKey[] | {
|
|
1925
|
+
partitionBy?: TKey | TKey[] | { column: TKey; order?: 'asc' | 'desc' }
|
|
1926
1926
|
): QueryBuilder<TRecord, TResult2>;
|
|
1927
1927
|
}
|
|
1928
1928
|
|
|
@@ -2699,6 +2699,7 @@ export declare namespace Knex {
|
|
|
2699
2699
|
debug?: boolean;
|
|
2700
2700
|
client?: string | typeof Client;
|
|
2701
2701
|
dialect?: string;
|
|
2702
|
+
jsonbSupport?: boolean;
|
|
2702
2703
|
version?: string;
|
|
2703
2704
|
connection?: string | StaticConnectionConfig | ConnectionConfigProvider;
|
|
2704
2705
|
pool?: PoolConfig;
|
|
@@ -2887,6 +2888,7 @@ export declare namespace Knex {
|
|
|
2887
2888
|
multiSubnetFailover?: boolean;
|
|
2888
2889
|
packetSize?: number;
|
|
2889
2890
|
trustServerCertificate?: boolean;
|
|
2891
|
+
mapBinding?: (value: any) => ({ value: any, type: any } | undefined);
|
|
2890
2892
|
}>;
|
|
2891
2893
|
pool?: Readonly<{
|
|
2892
2894
|
min?: number;
|
|
@@ -3081,7 +3083,7 @@ export declare namespace Knex {
|
|
|
3081
3083
|
|
|
3082
3084
|
interface Migration {
|
|
3083
3085
|
up: (knex: Knex) => PromiseLike<any>;
|
|
3084
|
-
down?: (
|
|
3086
|
+
down?: (knex: Knex) => PromiseLike<any>;
|
|
3085
3087
|
}
|
|
3086
3088
|
|
|
3087
3089
|
interface MigrationSource<TMigrationSpec> {
|