knex 3.2.9 → 3.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 +53 -2
- package/README.md +2 -2
- package/bin/cli.js +40 -12
- package/lib/client.js +78 -7
- package/lib/constants.js +2 -0
- package/lib/dialects/index.js +1 -0
- package/lib/dialects/mariadb/index.js +55 -0
- package/lib/dialects/mariadb/query/mariadb-querycompiler.js +98 -0
- package/lib/dialects/mariadb/schema/mariadb-columncompiler.js +17 -0
- package/lib/dialects/mariadb/transaction.js +44 -0
- package/lib/dialects/mssql/index.js +3 -0
- package/lib/dialects/mssql/query/mssql-querycompiler.js +4 -4
- package/lib/dialects/mysql/index.js +42 -0
- package/lib/dialects/mysql/query/mysql-querycompiler.js +11 -8
- package/lib/dialects/mysql2/index.js +7 -0
- package/lib/dialects/oracledb/index.js +45 -1
- package/lib/dialects/postgres/index.js +36 -0
- package/lib/dialects/postgres/query/pg-querycompiler.js +30 -35
- package/lib/dialects/sqlite3/query/sqlite-querycompiler.js +2 -0
- package/lib/execution/runner.js +8 -2
- package/lib/formatter/wrappingFormatter.js +52 -13
- package/lib/knex-builder/FunctionHelper.js +1 -0
- package/lib/knex-builder/Knex.js +2 -0
- package/lib/knex-builder/internal/config-resolver.js +7 -0
- package/lib/migrations/migrate/Migrator.js +130 -0
- package/lib/pool.js +24 -0
- package/lib/query/querycompiler.js +1 -1
- package/lib/schema/tablecompiler.js +1 -0
- package/package.json +15 -7
- package/types/index.d.ts +78 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "knex",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "A batteries-included SQL query & schema builder for PostgresSQL, MySQL, CockroachDB, MSSQL and SQLite3",
|
|
5
5
|
"main": "knex.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -25,11 +25,12 @@
|
|
|
25
25
|
"test:unit-only": "mocha --exit -t 10000 --config test/mocha-unit-config-test.js",
|
|
26
26
|
"test:db": "mocha --exit -t 10000 --config test/mocha-integration-config-test.js",
|
|
27
27
|
"test:db:coverage": "nyc mocha --exit --check-leaks -t 10000 --config test/mocha-integration-config-test.js && npm run test:tape",
|
|
28
|
-
"test:db:no-oracle": "cross-env DB=\"mssql mysql mysql2 postgres sqlite3\" mocha --exit -t 10000 --config test/mocha-integration-config-test.js && npm run test:tape",
|
|
28
|
+
"test:db:no-oracle": "cross-env DB=\"mssql mysql mysql2 mariadb postgres sqlite3\" mocha --exit -t 10000 --config test/mocha-integration-config-test.js && npm run test:tape",
|
|
29
29
|
"test": "mocha --exit -t 10000 --config test/mocha-all-config-test.js && npm run test:tape && npm run test:cli",
|
|
30
30
|
"test:coverage": "nyc mocha --exit --check-leaks -t 10000 --config test/mocha-all-config-test.js && npm run test:tape && npm run test:cli",
|
|
31
31
|
"test:everything": "npm run lint:everything && npm run test:coverage",
|
|
32
32
|
"test:mssql": "cross-env DB=mssql npm run test:db",
|
|
33
|
+
"test:mariadb": "cross-env DB=mariadb npm run test:db",
|
|
33
34
|
"test:mysql": "cross-env DB=mysql npm run test:db",
|
|
34
35
|
"test:mysql2": "cross-env DB=mysql2 npm run test:db",
|
|
35
36
|
"test:oracledb": "cross-env DB=oracledb npm run test:db",
|
|
@@ -40,8 +41,8 @@
|
|
|
40
41
|
"test:pgnative": "cross-env DB=pgnative npm run test:db",
|
|
41
42
|
"test:tape": "node test/tape/index.js | faucet",
|
|
42
43
|
"test:cli": "cross-env KNEX_PATH=../knex.js KNEX=bin/cli.js jake -f test/jake/Jakefile && mocha --exit -t 10000 test/cli-tests-suite.js",
|
|
43
|
-
"db:start": "docker compose -f scripts/docker-compose.yml up --build -d mysql oracledb postgres mssql cockroachdb pgnative && docker compose -f scripts/docker-compose.yml up waitmssql waitmysql waitpostgres waitoracledb",
|
|
44
|
-
"db:start:no-oracle": "docker compose -f scripts/docker-compose.yml up --build -d mysql postgres mssql cockroachdb pgnative && docker compose -f scripts/docker-compose.yml up waitmssql waitmysql waitpostgres",
|
|
44
|
+
"db:start": "docker compose -f scripts/docker-compose.yml up --build -d mysql oracledb postgres mssql mariadb cockroachdb pgnative && docker compose -f scripts/docker-compose.yml up waitmssql waitmysql waitmariadb waitpostgres waitoracledb",
|
|
45
|
+
"db:start:no-oracle": "docker compose -f scripts/docker-compose.yml up --build -d mysql postgres mssql mariadb cockroachdb pgnative && docker compose -f scripts/docker-compose.yml up waitmssql waitmysql waitmariadb waitpostgres",
|
|
45
46
|
"db:stop": "docker compose -f scripts/docker-compose.yml down",
|
|
46
47
|
"db:start:postgres": "docker compose -f scripts/docker-compose.yml up --build -d postgres && docker compose -f scripts/docker-compose.yml up waitpostgres",
|
|
47
48
|
"db:stop:postgres": "docker compose -f scripts/docker-compose.yml down",
|
|
@@ -49,6 +50,8 @@
|
|
|
49
50
|
"db:stop:pgnative": "docker compose -f scripts/docker-compose.yml down",
|
|
50
51
|
"db:start:mysql": "docker compose -f scripts/docker-compose.yml up --build -d mysql && docker compose -f scripts/docker-compose.yml up waitmysql",
|
|
51
52
|
"db:stop:mysql": "docker compose -f scripts/docker-compose.yml down",
|
|
53
|
+
"db:start:mariadb": "docker compose -f scripts/docker-compose.yml up --build -d mariadb && docker compose -f scripts/docker-compose.yml up waitmariadb",
|
|
54
|
+
"db:stop:mariadb": "docker compose -f scripts/docker-compose.yml down",
|
|
52
55
|
"db:start:mssql": "docker compose -f scripts/docker-compose.yml up --build -d mssql && docker compose -f scripts/docker-compose.yml up waitmssql",
|
|
53
56
|
"db:stop:mssql": "docker compose -f scripts/docker-compose.yml down",
|
|
54
57
|
"db:start:cockroachdb": "docker compose -f scripts/docker-compose.yml up --build -d cockroachdb && docker compose -f scripts/docker-compose.yml up waitcockroachdb",
|
|
@@ -68,11 +71,11 @@
|
|
|
68
71
|
"get-package-type": "^0.1.0",
|
|
69
72
|
"getopts": "2.3.0",
|
|
70
73
|
"interpret": "^2.2.0",
|
|
71
|
-
"lodash": "^4.
|
|
74
|
+
"lodash": "^4.18.1",
|
|
72
75
|
"pg-connection-string": "2.6.2",
|
|
73
76
|
"rechoir": "^0.8.0",
|
|
74
77
|
"resolve-from": "^5.0.0",
|
|
75
|
-
"tarn": "^3.0
|
|
78
|
+
"tarn": "^3.1.0",
|
|
76
79
|
"tildify": "2.0.0"
|
|
77
80
|
},
|
|
78
81
|
"peerDependencies": {
|
|
@@ -82,6 +85,9 @@
|
|
|
82
85
|
"tedious": {
|
|
83
86
|
"optional": true
|
|
84
87
|
},
|
|
88
|
+
"mariadb": {
|
|
89
|
+
"optional": true
|
|
90
|
+
},
|
|
85
91
|
"mysql": {
|
|
86
92
|
"optional": true
|
|
87
93
|
},
|
|
@@ -131,6 +137,7 @@
|
|
|
131
137
|
"jake": "^10.8.5",
|
|
132
138
|
"JSONStream": "^1.3.5",
|
|
133
139
|
"lint-staged": "^16.2.7",
|
|
140
|
+
"mariadb": "^3.5.2",
|
|
134
141
|
"mocha": "^10.0.0",
|
|
135
142
|
"mock-fs": "^5.1.4",
|
|
136
143
|
"mysql": "^2.18.1",
|
|
@@ -164,7 +171,7 @@
|
|
|
164
171
|
"type": "git",
|
|
165
172
|
"url": "git://github.com/knex/knex.git"
|
|
166
173
|
},
|
|
167
|
-
"homepage": "https://
|
|
174
|
+
"homepage": "https://knexjs.org/",
|
|
168
175
|
"keywords": [
|
|
169
176
|
"sql",
|
|
170
177
|
"query",
|
|
@@ -213,6 +220,7 @@
|
|
|
213
220
|
"./lib/bin/cli.js": "./lib/util/noop.js",
|
|
214
221
|
"./lib/migrations/seed/Seeder.js": "./lib/util/noop.js",
|
|
215
222
|
"tedious": false,
|
|
223
|
+
"mariadb": false,
|
|
216
224
|
"mysql": false,
|
|
217
225
|
"mysql2": false,
|
|
218
226
|
"pg": false,
|
package/types/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import type { EventEmitter } from 'events';
|
|
10
10
|
import type { Duplex, PassThrough, Stream } from 'stream';
|
|
11
11
|
import type { Pool } from 'tarn';
|
|
12
|
+
import type { PoolOptions } from 'tarn/dist/Pool';
|
|
12
13
|
import type { ConnectionOptions } from 'tls';
|
|
13
14
|
|
|
14
15
|
import type { Registry } from './result';
|
|
@@ -482,6 +483,10 @@ declare namespace knex {
|
|
|
482
483
|
|
|
483
484
|
export class KnexTimeoutError extends Error {}
|
|
484
485
|
|
|
486
|
+
export class KnexPool<T = any> extends Pool<T> {
|
|
487
|
+
constructor(config: PoolOptions<T>);
|
|
488
|
+
}
|
|
489
|
+
|
|
485
490
|
export const Client: typeof Knex.Client;
|
|
486
491
|
}
|
|
487
492
|
|
|
@@ -1704,7 +1709,10 @@ declare namespace Knex {
|
|
|
1704
1709
|
TResult
|
|
1705
1710
|
>;
|
|
1706
1711
|
|
|
1707
|
-
|
|
1712
|
+
// note: `Object` is intentional here: its mapped members preserve excess-property
|
|
1713
|
+
// checking so `.where({ unknownColumn })` stays a compile error, while still
|
|
1714
|
+
// accepting pre-typed dynamic objects, see #6452
|
|
1715
|
+
(object: Readonly<Object>): QueryBuilder<TRecord, TResult>;
|
|
1708
1716
|
|
|
1709
1717
|
<T extends keyof ResolveTableType<TRecord>>(
|
|
1710
1718
|
columnName: T,
|
|
@@ -2757,6 +2765,14 @@ declare namespace Knex {
|
|
|
2757
2765
|
jsonbSupport?: boolean;
|
|
2758
2766
|
version?: string;
|
|
2759
2767
|
connection?: string | StaticConnectionConfig | ConnectionConfigProvider;
|
|
2768
|
+
/**
|
|
2769
|
+
* An external pool to use instead of knex creating its own.
|
|
2770
|
+
* Accepts a KnexPool, tarn Pool, or a native driver pool (pg.Pool,
|
|
2771
|
+
* mysql.createPool(), oracledb.createPool()).
|
|
2772
|
+
* Mutually exclusive with `connection` — knex does not own the pool
|
|
2773
|
+
* lifecycle; call pool.end() / pool.close() yourself when done.
|
|
2774
|
+
*/
|
|
2775
|
+
connectionPool?: ConnectionPool;
|
|
2760
2776
|
pool?: PoolConfig;
|
|
2761
2777
|
migrations?: MigratorConfig;
|
|
2762
2778
|
postProcessResponse?: (result: any, queryContext: any) => any;
|
|
@@ -2817,7 +2833,8 @@ declare namespace Knex {
|
|
|
2817
2833
|
| 'azure-active-directory-access-token'
|
|
2818
2834
|
| 'azure-active-directory-msi-vm'
|
|
2819
2835
|
| 'azure-active-directory-msi-app-service'
|
|
2820
|
-
| 'azure-active-directory-service-principal-secret'
|
|
2836
|
+
| 'azure-active-directory-service-principal-secret'
|
|
2837
|
+
| 'token-credential';
|
|
2821
2838
|
|
|
2822
2839
|
interface MsSqlDefaultAuthenticationConfig extends MsSqlConnectionConfigBase {
|
|
2823
2840
|
type?: 'default' | never;
|
|
@@ -2895,6 +2912,19 @@ declare namespace Knex {
|
|
|
2895
2912
|
tenantId: string;
|
|
2896
2913
|
}
|
|
2897
2914
|
|
|
2915
|
+
interface MsSqlTokenCredential {
|
|
2916
|
+
getToken(
|
|
2917
|
+
scopes: string | string[],
|
|
2918
|
+
options?: unknown
|
|
2919
|
+
): Promise<{ token: string; expiresOnTimestamp: number } | null>;
|
|
2920
|
+
}
|
|
2921
|
+
|
|
2922
|
+
interface MsSqlTokenCredentialAuthenticationConfig
|
|
2923
|
+
extends MsSqlConnectionConfigBase {
|
|
2924
|
+
type: 'token-credential';
|
|
2925
|
+
credential: MsSqlTokenCredential;
|
|
2926
|
+
}
|
|
2927
|
+
|
|
2898
2928
|
interface MsSqlNtlmAuthenticationConfig extends MsSqlConnectionConfigBase {
|
|
2899
2929
|
type: 'ntlm';
|
|
2900
2930
|
/**
|
|
@@ -2914,7 +2944,8 @@ declare namespace Knex {
|
|
|
2914
2944
|
| MsSqlAzureActiveDirectoryMsiAppServiceAuthenticationConfig
|
|
2915
2945
|
| MsSqlAzureActiveDirectoryMsiVmAuthenticationConfig
|
|
2916
2946
|
| MsSqlAzureActiveDirectoryPasswordAuthenticationConfig
|
|
2917
|
-
| MsSqlAzureActiveDirectoryServicePrincipalSecretConfig
|
|
2947
|
+
| MsSqlAzureActiveDirectoryServicePrincipalSecretConfig
|
|
2948
|
+
| MsSqlTokenCredentialAuthenticationConfig;
|
|
2918
2949
|
|
|
2919
2950
|
// Config object for tedious: see http://tediousjs.github.io/tedious/api-connection.html
|
|
2920
2951
|
interface MsSqlConnectionConfigBase {
|
|
@@ -3124,6 +3155,46 @@ declare namespace Knex {
|
|
|
3124
3155
|
expirationChecker?(): boolean;
|
|
3125
3156
|
}
|
|
3126
3157
|
|
|
3158
|
+
// Pool-like interfaces matching the shapes of native driver pools.
|
|
3159
|
+
// These allow `connectionPool` to accept pools from pg, mysql/mysql2,
|
|
3160
|
+
// oracledb, or any tarn-compatible pool without importing driver types.
|
|
3161
|
+
|
|
3162
|
+
/** Matches the pg.Pool interface */
|
|
3163
|
+
interface PgPoolLike {
|
|
3164
|
+
connect(): Promise<any>;
|
|
3165
|
+
end(): Promise<void>;
|
|
3166
|
+
totalCount: number;
|
|
3167
|
+
idleCount: number;
|
|
3168
|
+
waitingCount: number;
|
|
3169
|
+
}
|
|
3170
|
+
|
|
3171
|
+
/** Matches the mysql / mysql2 pool interface */
|
|
3172
|
+
interface MySQLPoolLike {
|
|
3173
|
+
getConnection(cb: (err: Error | null, connection: any) => void): void;
|
|
3174
|
+
end(cb?: (err?: Error) => void): void;
|
|
3175
|
+
}
|
|
3176
|
+
|
|
3177
|
+
/** Matches the oracledb pool interface */
|
|
3178
|
+
interface OraclePoolLike {
|
|
3179
|
+
getConnection(): Promise<any>;
|
|
3180
|
+
close(drainTime?: number): Promise<void>;
|
|
3181
|
+
}
|
|
3182
|
+
|
|
3183
|
+
/** Any tarn-compatible pool (including KnexPool) */
|
|
3184
|
+
interface TarnPoolLike {
|
|
3185
|
+
acquire(): { promise: Promise<any> };
|
|
3186
|
+
release(resource: any): boolean;
|
|
3187
|
+
destroy(): Promise<void>;
|
|
3188
|
+
}
|
|
3189
|
+
|
|
3190
|
+
/** Types accepted by the `connectionPool` config option */
|
|
3191
|
+
type ConnectionPool =
|
|
3192
|
+
| Pool<any>
|
|
3193
|
+
| TarnPoolLike
|
|
3194
|
+
| PgPoolLike
|
|
3195
|
+
| MySQLPoolLike
|
|
3196
|
+
| OraclePoolLike;
|
|
3197
|
+
|
|
3127
3198
|
interface PoolConfig {
|
|
3128
3199
|
name?: string;
|
|
3129
3200
|
afterCreate?: Function;
|
|
@@ -3209,6 +3280,8 @@ declare namespace Knex {
|
|
|
3209
3280
|
list(config?: MigratorConfig): Promise<any>;
|
|
3210
3281
|
up(config?: MigratorConfigWithLifecycleHooks): Promise<any>;
|
|
3211
3282
|
down(config?: MigratorConfigWithLifecycleHooks): Promise<any>;
|
|
3283
|
+
to(config?: MigratorConfigWithLifecycleHooks): Promise<any>;
|
|
3284
|
+
before(config?: MigratorConfigWithLifecycleHooks): Promise<any>;
|
|
3212
3285
|
forceFreeMigrationsLock(config?: MigratorConfig): Promise<any>;
|
|
3213
3286
|
}
|
|
3214
3287
|
|
|
@@ -3310,7 +3383,8 @@ declare namespace Knex {
|
|
|
3310
3383
|
};
|
|
3311
3384
|
getPoolSettings(poolConfig: any): any;
|
|
3312
3385
|
initializePool(config?: {}): void;
|
|
3313
|
-
|
|
3386
|
+
initializeExternalPool(externalPool: ConnectionPool): void;
|
|
3387
|
+
pool: Pool<any> | TarnPoolLike | undefined;
|
|
3314
3388
|
acquireConnection(): any;
|
|
3315
3389
|
releaseConnection(connection: any): any;
|
|
3316
3390
|
destroy(callback: any): any;
|