@proteinjs/db-driver-knex 1.0.13 → 1.0.15
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/.eslintrc.js +20 -0
- package/.prettierignore +3 -0
- package/.prettierrc +8 -0
- package/CHANGELOG.md +12 -19
- package/LICENSE +21 -0
- package/README.md +1 -1
- package/dist/generated/index.js +1 -1
- package/dist/generated/index.js.map +1 -1
- package/dist/src/KnexColumnTypeFactory.d.ts.map +1 -1
- package/dist/src/KnexColumnTypeFactory.js +18 -9
- package/dist/src/KnexColumnTypeFactory.js.map +1 -1
- package/dist/src/KnexConfig.d.ts.map +1 -1
- package/dist/src/KnexDriver.d.ts.map +1 -1
- package/dist/src/KnexDriver.js +7 -4
- package/dist/src/KnexDriver.js.map +1 -1
- package/dist/src/KnexSchemaOperations.d.ts.map +1 -1
- package/dist/src/KnexSchemaOperations.js +26 -11
- package/dist/src/KnexSchemaOperations.js.map +1 -1
- package/dist/src/getColumnFactory.d.ts.map +1 -1
- package/dist/src/getColumnFactory.js +27 -12
- package/dist/src/getColumnFactory.js.map +1 -1
- package/dist/test/Crud.test.js.map +1 -1
- package/dist/test/TableManager.test.js.map +1 -1
- package/generated/index.ts +5 -8
- package/index.ts +1 -1
- package/jest.config.js +8 -17
- package/package.json +51 -45
- package/src/KnexColumnTypeFactory.ts +24 -12
- package/src/KnexConfig.ts +5 -5
- package/src/KnexDriver.ts +69 -66
- package/src/KnexSchemaOperations.ts +114 -91
- package/src/getColumnFactory.ts +67 -49
- package/test/Crud.test.ts +11 -16
- package/test/TableManager.test.ts +11 -17
- package/tsconfig.json +18 -22
package/generated/index.ts
CHANGED
|
@@ -9,11 +9,10 @@ import 'moment';
|
|
|
9
9
|
import 'mysql';
|
|
10
10
|
import 'uuid';
|
|
11
11
|
|
|
12
|
-
|
|
13
12
|
/** Generate Source Graph */
|
|
14
13
|
|
|
15
|
-
const sourceGraph =
|
|
16
|
-
|
|
14
|
+
const sourceGraph =
|
|
15
|
+
'{"options":{"directed":true,"multigraph":false,"compound":false},"nodes":[{"v":"@proteinjs/db-driver-knex/KnexDriver","value":{"packageName":"@proteinjs/db-driver-knex","name":"KnexDriver","filePath":"/home/runner/work/db/db/packages/drivers/knex/src/KnexDriver.ts","qualifiedName":"@proteinjs/db-driver-knex/KnexDriver","isAbstract":false,"isStatic":false,"visibility":"public","properties":[{"name":"KNEX","type":{"packageName":"","name":"knex","filePath":null,"qualifiedName":"/knex","typeParameters":null,"directParents":null},"isOptional":false,"isAbstract":false,"isStatic":true,"visibility":"private"},{"name":"logger","type":null,"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"private"},{"name":"config","type":{"packageName":"@proteinjs/db-driver-knex","name":"KnexConfig","filePath":null,"qualifiedName":"@proteinjs/db-driver-knex/KnexConfig","typeParameters":null,"directParents":null},"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"private"},{"name":"knexConfig","type":{"packageName":"","name":"any","filePath":null,"qualifiedName":"/any","typeParameters":null,"directParents":null},"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"private"}],"methods":[{"name":"getKnex","returnType":{"packageName":"","name":"knex","filePath":null,"qualifiedName":"/knex","typeParameters":null,"directParents":null},"isAsync":false,"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"public","parameters":[]},{"name":"getDbName","returnType":null,"isAsync":false,"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"public","parameters":[]},{"name":"createDbIfNotExists","returnType":{"packageName":"","name":"Promise<void>","filePath":null,"qualifiedName":"/Promise<void>","typeParameters":null,"directParents":null},"isAsync":true,"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"public","parameters":[]},{"name":"dbExists","returnType":{"packageName":"","name":"Promise<boolean>","filePath":null,"qualifiedName":"/Promise<boolean>","typeParameters":null,"directParents":null},"isAsync":true,"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"private","parameters":[{"name":"databaseName","type":{"packageName":"","name":"string","filePath":null,"qualifiedName":"/string","typeParameters":null,"directParents":null}}]},{"name":"start","returnType":null,"isAsync":true,"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"public","parameters":[]},{"name":"stop","returnType":null,"isAsync":true,"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"public","parameters":[]},{"name":"setMaxAllowedPacketSize","returnType":{"packageName":"","name":"Promise<void>","filePath":null,"qualifiedName":"/Promise<void>","typeParameters":null,"directParents":null},"isAsync":true,"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"private","parameters":[]},{"name":"getTableManager","returnType":{"packageName":"@proteinjs/db","name":"TableManager","filePath":null,"qualifiedName":"@proteinjs/db/TableManager","typeParameters":null,"directParents":null},"isAsync":false,"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"public","parameters":[]},{"name":"runQuery","returnType":{"packageName":"","name":"Promise<SerializedRecord[]>","filePath":null,"qualifiedName":"/Promise<SerializedRecord[]>","typeParameters":null,"directParents":null},"isAsync":true,"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"public","parameters":[{"name":"generateStatement","type":{"packageName":"","name":"(config: DbDriverStatementConfig) => Statement","filePath":null,"qualifiedName":"/(config: DbDriverStatementConfig) => Statement","typeParameters":null,"directParents":null}}]},{"name":"runDml","returnType":{"packageName":"","name":"Promise<number>","filePath":null,"qualifiedName":"/Promise<number>","typeParameters":null,"directParents":null},"isAsync":true,"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"public","parameters":[{"name":"generateStatement","type":{"packageName":"","name":"(config: DbDriverStatementConfig) => Statement","filePath":null,"qualifiedName":"/(config: DbDriverStatementConfig) => Statement","typeParameters":null,"directParents":null}}]}],"typeParameters":[],"directParentInterfaces":[{"packageName":"@proteinjs/db","name":"DbDriver","filePath":null,"qualifiedName":"@proteinjs/db/DbDriver","properties":[],"methods":[],"typeParameters":[],"directParents":[]}],"directParentClasses":[],"sourceType":2}},{"v":"@proteinjs/db/DbDriver"},{"v":"@proteinjs/db-driver-knex/KnexSchemaOperations","value":{"packageName":"@proteinjs/db-driver-knex","name":"KnexSchemaOperations","filePath":"/home/runner/work/db/db/packages/drivers/knex/src/KnexSchemaOperations.ts","qualifiedName":"@proteinjs/db-driver-knex/KnexSchemaOperations","isAbstract":false,"isStatic":false,"visibility":"public","properties":[{"name":"logger","type":null,"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"private"},{"name":"knexDriver","type":{"packageName":"@proteinjs/db-driver-knex","name":"KnexDriver","filePath":null,"qualifiedName":"@proteinjs/db-driver-knex/KnexDriver","typeParameters":null,"directParents":null},"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"private"}],"methods":[{"name":"createTable","returnType":null,"isAsync":true,"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"public","parameters":[{"name":"table","type":{"packageName":"","name":"Table<any>","filePath":null,"qualifiedName":"/Table<any>","typeParameters":null,"directParents":null}}]},{"name":"alterTable","returnType":null,"isAsync":true,"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"public","parameters":[{"name":"table","type":{"packageName":"","name":"Table<any>","filePath":null,"qualifiedName":"/Table<any>","typeParameters":null,"directParents":null}},{"name":"tableChanges","type":{"packageName":"@proteinjs/db","name":"TableChanges","filePath":null,"qualifiedName":"@proteinjs/db/TableChanges","typeParameters":null,"directParents":null}}]},{"name":"createColumn","returnType":null,"isAsync":false,"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"private","parameters":[{"name":"column","type":{"packageName":"","name":"Column<any, any>","filePath":null,"qualifiedName":"/Column<any, any>","typeParameters":null,"directParents":null}},{"name":"table","type":{"packageName":"","name":"Table<any>","filePath":null,"qualifiedName":"/Table<any>","typeParameters":null,"directParents":null}},{"name":"tableBuilder","type":{"packageName":"","name":"knex.TableBuilder","filePath":null,"qualifiedName":"/knex.TableBuilder","typeParameters":null,"directParents":null}},{"name":"tableChanges","type":{"packageName":"@proteinjs/db","name":"TableChanges","filePath":null,"qualifiedName":"@proteinjs/db/TableChanges","typeParameters":null,"directParents":null}}]}],"typeParameters":[],"directParentInterfaces":[{"packageName":"@proteinjs/db","name":"SchemaOperations","filePath":null,"qualifiedName":"@proteinjs/db/SchemaOperations","properties":[],"methods":[],"typeParameters":[],"directParents":[]}],"directParentClasses":[],"sourceType":2}},{"v":"@proteinjs/db/SchemaOperations"}],"edges":[{"v":"@proteinjs/db-driver-knex/KnexDriver","w":"@proteinjs/db/DbDriver","value":"implements interface"},{"v":"@proteinjs/db-driver-knex/KnexSchemaOperations","w":"@proteinjs/db/SchemaOperations","value":"implements interface"}]}';
|
|
17
16
|
|
|
18
17
|
/** Generate Source Links */
|
|
19
18
|
|
|
@@ -21,15 +20,13 @@ import { KnexDriver } from '../src/KnexDriver';
|
|
|
21
20
|
import { KnexSchemaOperations } from '../src/KnexSchemaOperations';
|
|
22
21
|
|
|
23
22
|
const sourceLinks = {
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
'@proteinjs/db-driver-knex/KnexDriver': KnexDriver,
|
|
24
|
+
'@proteinjs/db-driver-knex/KnexSchemaOperations': KnexSchemaOperations,
|
|
26
25
|
};
|
|
27
26
|
|
|
28
|
-
|
|
29
27
|
/** Load Source Graph and Links */
|
|
30
28
|
|
|
31
29
|
import { SourceRepository } from '@proteinjs/reflection';
|
|
32
30
|
SourceRepository.merge(sourceGraph, sourceLinks);
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
export * from '../index';
|
|
32
|
+
export * from '../index';
|
package/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './src/KnexDriver';
|
|
2
|
-
export * from './src/KnexConfig';
|
|
2
|
+
export * from './src/KnexConfig';
|
package/jest.config.js
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"ts",
|
|
11
|
-
"tsx",
|
|
12
|
-
"js",
|
|
13
|
-
"jsx",
|
|
14
|
-
"json",
|
|
15
|
-
"node"
|
|
16
|
-
],
|
|
17
|
-
"testEnvironment": "node"
|
|
18
|
-
}
|
|
2
|
+
roots: ['<rootDir>/test'],
|
|
3
|
+
transform: {
|
|
4
|
+
'^.+\\.tsx?$': 'ts-jest',
|
|
5
|
+
},
|
|
6
|
+
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
|
|
7
|
+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
|
|
8
|
+
testEnvironment: 'node',
|
|
9
|
+
};
|
package/package.json
CHANGED
|
@@ -1,46 +1,52 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
|
|
2
|
+
"name": "@proteinjs/db-driver-knex",
|
|
3
|
+
"version": "1.0.15",
|
|
4
|
+
"description": "Db driver for Knex",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/proteinjs/db.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/proteinjs/db/issues"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/proteinjs/db#readme",
|
|
16
|
+
"author": "Brent Bahry",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"scripts": {
|
|
19
|
+
"clean": "rm -rf dist/ node_modules/ generated/",
|
|
20
|
+
"build": "reflection-build && tsc",
|
|
21
|
+
"watch": "reflection-watch",
|
|
22
|
+
"test": "jest"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@proteinjs/db": "^1.0.16",
|
|
26
|
+
"@proteinjs/db-query": "^1.0.9",
|
|
27
|
+
"@proteinjs/reflection": "1.1.1",
|
|
28
|
+
"@proteinjs/util": "1.1.0",
|
|
29
|
+
"knex": "0.21.5",
|
|
30
|
+
"moment": "2.27.0",
|
|
31
|
+
"mysql": "2.18.1",
|
|
32
|
+
"uuid": "8.3.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@proteinjs/reflection-build": "1.0.16",
|
|
36
|
+
"@types/jest": "29.5.5",
|
|
37
|
+
"@types/knex": "0.16.1",
|
|
38
|
+
"@types/node": "14.0.27",
|
|
39
|
+
"@types/uuid": "8.3.0",
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "7.8.0",
|
|
41
|
+
"@typescript-eslint/parser": "7.8.0",
|
|
42
|
+
"eslint": "8.57.0",
|
|
43
|
+
"eslint-config-prettier": "9.1.0",
|
|
44
|
+
"eslint-plugin-prettier": "5.1.3",
|
|
45
|
+
"jest": "29.7.0",
|
|
46
|
+
"ts-jest": "29.1.1",
|
|
47
|
+
"typescript": "5.2.2"
|
|
48
|
+
},
|
|
49
|
+
"main": "./dist/generated/index.js",
|
|
50
|
+
"types": "./dist/generated/index.d.ts",
|
|
51
|
+
"gitHead": "e9b7e3b3073e7a68c97b218444208d2c84f9197d"
|
|
52
|
+
}
|
|
@@ -1,28 +1,40 @@
|
|
|
1
1
|
import { isInstanceOf } from '@proteinjs/util';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
BinaryColumn,
|
|
4
|
+
BooleanColumn,
|
|
5
|
+
Column,
|
|
6
|
+
DateColumn,
|
|
7
|
+
DateTimeColumn,
|
|
8
|
+
DecimalColumn,
|
|
9
|
+
FloatColumn,
|
|
10
|
+
IntegerColumn,
|
|
11
|
+
StringColumn,
|
|
12
|
+
UuidColumn,
|
|
13
|
+
} from '@proteinjs/db';
|
|
3
14
|
|
|
4
15
|
// note: this might be specific to maria db
|
|
5
16
|
export class KnexColumnTypeFactory {
|
|
6
17
|
getType(column: Column<any, any>): string {
|
|
7
|
-
if (isInstanceOf(column, IntegerColumn))
|
|
18
|
+
if (isInstanceOf(column, IntegerColumn)) {
|
|
8
19
|
return (column as IntegerColumn).large ? 'bigint' : 'int';
|
|
9
|
-
else if (isInstanceOf(column, UuidColumn))
|
|
20
|
+
} else if (isInstanceOf(column, UuidColumn)) {
|
|
10
21
|
return 'char';
|
|
11
|
-
else if (isInstanceOf(column, StringColumn))
|
|
22
|
+
} else if (isInstanceOf(column, StringColumn)) {
|
|
12
23
|
return (column as StringColumn).maxLength === 'MAX' ? 'longtext' : 'varchar';
|
|
13
|
-
else if (isInstanceOf(column, FloatColumn))
|
|
24
|
+
} else if (isInstanceOf(column, FloatColumn)) {
|
|
14
25
|
return 'float';
|
|
15
|
-
else if (isInstanceOf(column, DecimalColumn))
|
|
26
|
+
} else if (isInstanceOf(column, DecimalColumn)) {
|
|
16
27
|
return 'decimal';
|
|
17
|
-
else if (isInstanceOf(column, BooleanColumn))
|
|
28
|
+
} else if (isInstanceOf(column, BooleanColumn)) {
|
|
18
29
|
return 'tinyint';
|
|
19
|
-
else if (isInstanceOf(column, DateColumn))
|
|
30
|
+
} else if (isInstanceOf(column, DateColumn)) {
|
|
20
31
|
return 'date';
|
|
21
|
-
else if (isInstanceOf(column, DateTimeColumn))
|
|
32
|
+
} else if (isInstanceOf(column, DateTimeColumn)) {
|
|
22
33
|
return 'datetime';
|
|
23
|
-
else if (isInstanceOf(column, BinaryColumn))
|
|
34
|
+
} else if (isInstanceOf(column, BinaryColumn)) {
|
|
24
35
|
return (column as BinaryColumn).maxLength === 'MAX' ? 'longblob' : 'blob';
|
|
25
|
-
|
|
36
|
+
}
|
|
37
|
+
|
|
26
38
|
throw new Error(`Invalid column type: ${column.constructor.name}, must extend a base column`);
|
|
27
39
|
}
|
|
28
|
-
}
|
|
40
|
+
}
|
package/src/KnexConfig.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type KnexConfig = {
|
|
2
|
-
host: string
|
|
3
|
-
user: string
|
|
4
|
-
password: string
|
|
5
|
-
dbName: string
|
|
6
|
-
}
|
|
2
|
+
host: string;
|
|
3
|
+
user: string;
|
|
4
|
+
password: string;
|
|
5
|
+
dbName: string;
|
|
6
|
+
};
|
package/src/KnexDriver.ts
CHANGED
|
@@ -7,84 +7,87 @@ import { KnexSchemaOperations } from './KnexSchemaOperations';
|
|
|
7
7
|
import { KnexColumnTypeFactory } from './KnexColumnTypeFactory';
|
|
8
8
|
|
|
9
9
|
export class KnexDriver implements DbDriver {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
private static KNEX: knex;
|
|
11
|
+
private logger = new Logger(this.constructor.name);
|
|
12
|
+
private config: KnexConfig;
|
|
13
|
+
private knexConfig: any;
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
constructor(config: KnexConfig) {
|
|
16
|
+
this.config = config;
|
|
17
|
+
this.knexConfig = {
|
|
18
|
+
client: 'mysql',
|
|
19
|
+
connection: {
|
|
20
|
+
host: this.config.host,
|
|
21
|
+
user: this.config.user,
|
|
22
|
+
password: this.config.password,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
getKnex(): knex {
|
|
28
|
+
if (!KnexDriver.KNEX) {
|
|
29
|
+
KnexDriver.KNEX = knex(this.knexConfig);
|
|
30
|
+
}
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
return KnexDriver.KNEX;
|
|
33
|
+
}
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
getDbName() {
|
|
36
|
+
return this.config.dbName as string;
|
|
37
|
+
}
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
async createDbIfNotExists(): Promise<void> {
|
|
40
|
+
if (await this.dbExists(this.getDbName())) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
41
43
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
await this.getKnex().raw(`CREATE DATABASE ${this.getDbName()};`);
|
|
45
|
+
}
|
|
44
46
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
private async dbExists(databaseName: string): Promise<boolean> {
|
|
48
|
+
const result: any = await this.getKnex().raw('SHOW DATABASES;');
|
|
49
|
+
for (const existingDatabase of result[0]) {
|
|
50
|
+
if (existingDatabase['Database'] == databaseName) {
|
|
49
51
|
return true;
|
|
50
|
-
|
|
52
|
+
}
|
|
53
|
+
}
|
|
51
54
|
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
54
57
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
async start() {
|
|
59
|
+
await this.setMaxAllowedPacketSize();
|
|
60
|
+
}
|
|
58
61
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
async stop() {
|
|
63
|
+
await this.getKnex().destroy();
|
|
64
|
+
}
|
|
62
65
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
private async setMaxAllowedPacketSize(): Promise<void> {
|
|
67
|
+
await this.getKnex().raw('SET GLOBAL max_allowed_packet=1073741824;');
|
|
68
|
+
await this.getKnex().destroy();
|
|
69
|
+
KnexDriver.KNEX = knex(this.knexConfig);
|
|
70
|
+
this.logger.info('Set global max_allowed_packet size to 1gb');
|
|
71
|
+
}
|
|
69
72
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
getTableManager(): TableManager {
|
|
74
|
+
const columnTypeFactory = new KnexColumnTypeFactory();
|
|
75
|
+
const schemaOperations = new KnexSchemaOperations(this);
|
|
76
|
+
return new TableManager(this, columnTypeFactory, schemaOperations);
|
|
77
|
+
}
|
|
75
78
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
async runQuery(generateStatement: (config: DbDriverStatementConfig) => Statement): Promise<SerializedRecord[]> {
|
|
80
|
+
const { sql, params } = generateStatement({ useParams: true, prefixTablesWithDb: true });
|
|
81
|
+
try {
|
|
82
|
+
return (await this.getKnex().raw(sql, params as any))[0]; // returns 2 arrays, first is records, second is metadata per record
|
|
83
|
+
} catch (error: any) {
|
|
84
|
+
this.logger.error(`Failed when executing query: ${sql}`);
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
85
88
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
89
|
+
async runDml(generateStatement: (config: DbDriverStatementConfig) => Statement): Promise<number> {
|
|
90
|
+
const { affectedRows } = (await this.runQuery(generateStatement)) as any;
|
|
91
|
+
return affectedRows;
|
|
92
|
+
}
|
|
93
|
+
}
|