@mikro-orm/knex 6.1.13-dev.4 → 6.1.13-dev.41
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/AbstractSqlConnection.js +8 -2
- package/AbstractSqlDriver.d.ts +5 -5
- package/AbstractSqlDriver.js +21 -10
- package/MonkeyPatchable.d.ts +5 -0
- package/MonkeyPatchable.js +15 -0
- package/README.md +17 -11
- package/SqlEntityManager.d.ts +1 -1
- package/SqlEntityManager.js +1 -2
- package/dialects/index.d.ts +4 -0
- package/dialects/index.js +20 -0
- package/dialects/mssql/MsSqlColumnCompiler.d.ts +4 -0
- package/dialects/mssql/MsSqlColumnCompiler.js +10 -0
- package/dialects/mssql/MsSqlKnexDialect.d.ts +6 -0
- package/dialects/mssql/MsSqlKnexDialect.js +22 -0
- package/dialects/mssql/MsSqlQueryCompiler.d.ts +12 -0
- package/dialects/mssql/MsSqlQueryCompiler.js +94 -0
- package/dialects/mssql/MsSqlTableCompiler.d.ts +9 -0
- package/dialects/mssql/MsSqlTableCompiler.js +40 -0
- package/dialects/mssql/index.d.ts +1 -0
- package/dialects/mssql/index.js +17 -0
- package/dialects/mysql/MariaDbKnexDialect.d.ts +6 -0
- package/dialects/mysql/MariaDbKnexDialect.js +16 -0
- package/dialects/mysql/MySqlColumnCompiler.d.ts +9 -0
- package/dialects/mysql/MySqlColumnCompiler.js +19 -0
- package/dialects/mysql/MySqlConnection.d.ts +8 -0
- package/dialects/mysql/MySqlConnection.js +43 -0
- package/dialects/mysql/MySqlExceptionConverter.d.ts +9 -0
- package/dialects/mysql/MySqlExceptionConverter.js +83 -0
- package/dialects/mysql/MySqlKnexDialect.d.ts +5 -0
- package/dialects/mysql/MySqlKnexDialect.js +21 -0
- package/dialects/mysql/MySqlPlatform.d.ts +31 -0
- package/dialects/mysql/MySqlPlatform.js +88 -0
- package/dialects/mysql/MySqlQueryCompiler.d.ts +5 -0
- package/dialects/mysql/MySqlQueryCompiler.js +23 -0
- package/dialects/mysql/MySqlSchemaHelper.d.ts +43 -0
- package/dialects/mysql/MySqlSchemaHelper.js +297 -0
- package/dialects/mysql/index.d.ts +6 -0
- package/dialects/mysql/index.js +22 -0
- package/dialects/postgresql/PostgreSqlKnexDialect.d.ts +6 -0
- package/dialects/postgresql/PostgreSqlKnexDialect.js +19 -0
- package/dialects/postgresql/PostgreSqlTableCompiler.d.ts +11 -0
- package/dialects/postgresql/PostgreSqlTableCompiler.js +89 -0
- package/dialects/postgresql/index.d.ts +1 -0
- package/dialects/postgresql/index.js +17 -0
- package/dialects/sqlite/BaseSqliteConnection.d.ts +10 -0
- package/dialects/sqlite/BaseSqliteConnection.js +56 -0
- package/dialects/sqlite/BaseSqlitePlatform.d.ts +49 -0
- package/dialects/sqlite/BaseSqlitePlatform.js +78 -0
- package/dialects/sqlite/BaseSqliteSchemaHelper.d.ts +27 -0
- package/dialects/sqlite/BaseSqliteSchemaHelper.js +172 -0
- package/dialects/sqlite/BetterSqliteKnexDialect.d.ts +5 -0
- package/dialects/sqlite/BetterSqliteKnexDialect.js +15 -0
- package/dialects/sqlite/LibSqlKnexDialect.d.ts +6 -0
- package/dialects/sqlite/LibSqlKnexDialect.js +18 -0
- package/dialects/sqlite/SqliteKnexDialect.d.ts +8 -0
- package/dialects/sqlite/SqliteKnexDialect.js +67 -0
- package/dialects/sqlite/SqliteTableCompiler.d.ts +5 -0
- package/dialects/sqlite/SqliteTableCompiler.js +45 -0
- package/dialects/sqlite/index.d.ts +7 -0
- package/dialects/sqlite/index.js +23 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.mjs +17 -0
- package/package.json +2 -2
- package/query/QueryBuilder.d.ts +59 -41
- package/query/QueryBuilder.js +61 -23
- package/query/QueryBuilderHelper.js +8 -3
- package/schema/DatabaseTable.js +21 -4
- package/schema/SchemaComparator.js +16 -3
- package/schema/SchemaHelper.d.ts +5 -1
- package/schema/SchemaHelper.js +20 -2
- package/schema/SqlSchemaGenerator.d.ts +12 -4
- package/schema/SqlSchemaGenerator.js +53 -28
- package/typings.d.ts +2 -1
package/AbstractSqlConnection.js
CHANGED
|
@@ -125,7 +125,13 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
125
125
|
*/
|
|
126
126
|
async loadFile(path) {
|
|
127
127
|
const buf = await (0, fs_extra_1.readFile)(path);
|
|
128
|
-
|
|
128
|
+
try {
|
|
129
|
+
await this.getKnex().raw(buf.toString());
|
|
130
|
+
}
|
|
131
|
+
catch (e) {
|
|
132
|
+
/* istanbul ignore next */
|
|
133
|
+
throw this.platform.getExceptionConverter().convertException(e);
|
|
134
|
+
}
|
|
129
135
|
}
|
|
130
136
|
createKnexClient(type) {
|
|
131
137
|
const driverOptions = this.config.get('driverOptions');
|
|
@@ -145,7 +151,7 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
145
151
|
client: type,
|
|
146
152
|
connection: this.getConnectionOptions(),
|
|
147
153
|
pool: this.config.get('pool'),
|
|
148
|
-
}, this.config.get('driverOptions'));
|
|
154
|
+
}, this.config.get('driverOptions'), this.options.driverOptions);
|
|
149
155
|
const options = config.connection;
|
|
150
156
|
const password = options.password;
|
|
151
157
|
if (!(password instanceof Function)) {
|
package/AbstractSqlDriver.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Knex } from 'knex';
|
|
2
|
-
import { type AnyEntity, type Collection, type Configuration, type ConnectionType, type Constructor, type CountOptions, DatabaseDriver, type DeleteOptions, type Dictionary, type DriverMethodOptions, type EntityData, type EntityDictionary, type EntityField, EntityManagerType, type EntityMetadata, type EntityName, type EntityProperty, type FilterQuery, type FindOneOptions, type FindOptions, type IDatabaseDriver, type LockOptions, type LoggingOptions, type NativeInsertUpdateManyOptions, type NativeInsertUpdateOptions, type ObjectQuery, type Options, type OrderDefinition, type PopulateOptions, type Primary, type QueryOrderMap, type QueryResult, type Transaction, type UpsertManyOptions, type UpsertOptions } from '@mikro-orm/core';
|
|
2
|
+
import { type AnyEntity, type Collection, type Configuration, type ConnectionType, type Constructor, type CountOptions, DatabaseDriver, type DeleteOptions, type Dictionary, type DriverMethodOptions, type EntityData, type EntityDictionary, type EntityField, EntityManagerType, type EntityMetadata, type EntityName, type EntityProperty, type FilterQuery, type FindOneOptions, type FindOptions, type IDatabaseDriver, type LockOptions, type LoggingOptions, type NativeInsertUpdateManyOptions, type NativeInsertUpdateOptions, type ObjectQuery, type Options, type OrderDefinition, type PopulateOptions, type PopulatePath, type Primary, type QueryOrderMap, type QueryResult, type Transaction, type UpsertManyOptions, type UpsertOptions } from '@mikro-orm/core';
|
|
3
3
|
import type { AbstractSqlConnection } from './AbstractSqlConnection';
|
|
4
4
|
import type { AbstractSqlPlatform } from './AbstractSqlPlatform';
|
|
5
5
|
import { QueryBuilder, QueryType } from './query';
|
|
@@ -13,8 +13,8 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
|
|
|
13
13
|
protected constructor(config: Configuration, platform: Platform, connection: Constructor<Connection>, connector: string[]);
|
|
14
14
|
getPlatform(): Platform;
|
|
15
15
|
createEntityManager<D extends IDatabaseDriver = IDatabaseDriver>(useContext?: boolean): D[typeof EntityManagerType];
|
|
16
|
-
find<T extends object, P extends string = never, F extends string =
|
|
17
|
-
findOne<T extends object, P extends string = never, F extends string =
|
|
16
|
+
find<T extends object, P extends string = never, F extends string = PopulatePath.ALL, E extends string = never>(entityName: string, where: FilterQuery<T>, options?: FindOptions<T, P, F, E>): Promise<EntityData<T>[]>;
|
|
17
|
+
findOne<T extends object, P extends string = never, F extends string = PopulatePath.ALL, E extends string = never>(entityName: string, where: FilterQuery<T>, options?: FindOneOptions<T, P, F, E>): Promise<EntityData<T> | null>;
|
|
18
18
|
protected hasToManyJoins<T extends object>(hint: PopulateOptions<T>, meta: EntityMetadata<T>): boolean;
|
|
19
19
|
findVirtual<T extends object>(entityName: string, where: FilterQuery<T>, options: FindOptions<T, any, any, any>): Promise<EntityData<T>[]>;
|
|
20
20
|
countVirtual<T extends object>(entityName: string, where: FilterQuery<T>, options: CountOptions<T, any>): Promise<number>;
|
|
@@ -24,7 +24,7 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
|
|
|
24
24
|
private mapJoinedProps;
|
|
25
25
|
count<T extends object>(entityName: string, where: any, options?: CountOptions<T>): Promise<number>;
|
|
26
26
|
nativeInsert<T extends object>(entityName: string, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>;
|
|
27
|
-
nativeInsertMany<T extends object>(entityName: string, data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T
|
|
27
|
+
nativeInsertMany<T extends object>(entityName: string, data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>, transform?: (sql: string) => string): Promise<QueryResult<T>>;
|
|
28
28
|
nativeUpdate<T extends object>(entityName: string, where: FilterQuery<T>, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T> & UpsertOptions<T>): Promise<QueryResult<T>>;
|
|
29
29
|
nativeUpdateMany<T extends object>(entityName: string, where: FilterQuery<T>[], data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T> & UpsertManyOptions<T>): Promise<QueryResult<T>>;
|
|
30
30
|
nativeDelete<T extends object>(entityName: string, where: FilterQuery<T> | string | any, options?: DeleteOptions<T>): Promise<QueryResult<T>>;
|
|
@@ -55,7 +55,7 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
|
|
|
55
55
|
*/
|
|
56
56
|
mapPropToFieldNames<T extends object>(qb: QueryBuilder<T>, prop: EntityProperty<T>, tableAlias?: string): Field<T>[];
|
|
57
57
|
/** @internal */
|
|
58
|
-
createQueryBuilder<T extends object>(entityName: EntityName<T> | QueryBuilder<T>, ctx?: Transaction<Knex.Transaction>, preferredConnectionType?: ConnectionType, convertCustomTypes?: boolean, loggerContext?: LoggingOptions): QueryBuilder<T>;
|
|
58
|
+
createQueryBuilder<T extends object>(entityName: EntityName<T> | QueryBuilder<T>, ctx?: Transaction<Knex.Transaction>, preferredConnectionType?: ConnectionType, convertCustomTypes?: boolean, loggerContext?: LoggingOptions, alias?: string, em?: SqlEntityManager): QueryBuilder<T>;
|
|
59
59
|
protected resolveConnectionType(args: {
|
|
60
60
|
ctx?: Transaction<Knex.Transaction>;
|
|
61
61
|
connectionType?: ConnectionType;
|
package/AbstractSqlDriver.js
CHANGED
|
@@ -321,7 +321,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
321
321
|
await this.processManyToMany(meta, pk, collections, false, options);
|
|
322
322
|
return res;
|
|
323
323
|
}
|
|
324
|
-
async nativeInsertMany(entityName, data, options = {}) {
|
|
324
|
+
async nativeInsertMany(entityName, data, options = {}, transform) {
|
|
325
325
|
options.processCollections ??= true;
|
|
326
326
|
options.convertCustomTypes ??= true;
|
|
327
327
|
const meta = this.metadata.find(entityName)?.root;
|
|
@@ -340,6 +340,13 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
340
340
|
const tableName = meta ? this.getTableName(meta, options) : this.platform.quoteIdentifier(entityName);
|
|
341
341
|
let sql = `insert into ${tableName} `;
|
|
342
342
|
sql += fields.length > 0 ? '(' + fields.map(k => this.platform.quoteIdentifier(k)).join(', ') + ')' : `(${this.platform.quoteIdentifier(pks[0])})`;
|
|
343
|
+
if (meta && this.platform.usesOutputStatement()) {
|
|
344
|
+
const returningProps = meta.props
|
|
345
|
+
.filter(prop => prop.persist !== false && prop.defaultRaw || prop.autoincrement || prop.generated)
|
|
346
|
+
.filter(prop => !(prop.name in data[0]) || core_1.Utils.isRawSql(data[0][prop.name]));
|
|
347
|
+
const returningFields = core_1.Utils.flatten(returningProps.map(prop => prop.fieldNames));
|
|
348
|
+
sql += returningFields.length > 0 ? ` output ${returningFields.map(field => 'inserted.' + this.platform.quoteIdentifier(field)).join(', ')}` : '';
|
|
349
|
+
}
|
|
343
350
|
if (fields.length > 0 || this.platform.usesDefaultKeyword()) {
|
|
344
351
|
sql += ' values ';
|
|
345
352
|
}
|
|
@@ -406,6 +413,9 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
406
413
|
/* istanbul ignore next */
|
|
407
414
|
sql += returningFields.length > 0 ? ` returning ${returningFields.map(field => this.platform.quoteIdentifier(field)).join(', ')}` : '';
|
|
408
415
|
}
|
|
416
|
+
if (transform) {
|
|
417
|
+
sql = transform(sql);
|
|
418
|
+
}
|
|
409
419
|
const res = await this.execute(sql, params, 'run', options.ctx);
|
|
410
420
|
let pk;
|
|
411
421
|
/* istanbul ignore next */
|
|
@@ -943,17 +953,16 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
943
953
|
}
|
|
944
954
|
if (tableAlias) {
|
|
945
955
|
return prop.fieldNames.map(fieldName => {
|
|
946
|
-
|
|
947
|
-
const alias = this.platform.quoteIdentifier(`${tableAlias}__${fieldName}`);
|
|
948
|
-
return (0, core_1.raw)(`${name} as ${alias}`);
|
|
956
|
+
return `${tableAlias}.${fieldName} as ${tableAlias}__${fieldName}`;
|
|
949
957
|
});
|
|
950
958
|
}
|
|
951
959
|
return prop.fieldNames;
|
|
952
960
|
}
|
|
953
961
|
/** @internal */
|
|
954
|
-
createQueryBuilder(entityName, ctx, preferredConnectionType, convertCustomTypes, loggerContext) {
|
|
955
|
-
|
|
956
|
-
const
|
|
962
|
+
createQueryBuilder(entityName, ctx, preferredConnectionType, convertCustomTypes, loggerContext, alias, em) {
|
|
963
|
+
// do not compute the connectionType if EM is provided as it will be computed from it in the QB later on
|
|
964
|
+
const connectionType = em ? preferredConnectionType : this.resolveConnectionType({ ctx, connectionType: preferredConnectionType });
|
|
965
|
+
const qb = new query_1.QueryBuilder(entityName, this.metadata, this, ctx, alias, connectionType, em, loggerContext);
|
|
957
966
|
if (!convertCustomTypes) {
|
|
958
967
|
qb.unsetFlag(core_1.QueryFlag.CONVERT_CUSTOM_TYPES);
|
|
959
968
|
}
|
|
@@ -963,10 +972,10 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
963
972
|
if (args.ctx) {
|
|
964
973
|
return 'write';
|
|
965
974
|
}
|
|
966
|
-
|
|
975
|
+
if (args.connectionType) {
|
|
967
976
|
return args.connectionType;
|
|
968
977
|
}
|
|
969
|
-
|
|
978
|
+
if (this.config.get('preferReadReplicas')) {
|
|
970
979
|
return 'read';
|
|
971
980
|
}
|
|
972
981
|
return 'write';
|
|
@@ -1083,7 +1092,9 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
1083
1092
|
continue;
|
|
1084
1093
|
}
|
|
1085
1094
|
const order = typeof childOrder === 'object' ? childOrder[propName] : childOrder;
|
|
1086
|
-
|
|
1095
|
+
if (order) {
|
|
1096
|
+
orderBy.push({ [`${propAlias}.${propName}`]: order });
|
|
1097
|
+
}
|
|
1087
1098
|
}
|
|
1088
1099
|
}
|
|
1089
1100
|
return orderBy;
|
package/MonkeyPatchable.d.ts
CHANGED
|
@@ -4,8 +4,13 @@ export declare const MonkeyPatchable: {
|
|
|
4
4
|
MySqlDialect: any;
|
|
5
5
|
MySqlColumnCompiler: any;
|
|
6
6
|
MySqlQueryCompiler: any;
|
|
7
|
+
MsSqlColumnCompiler: any;
|
|
8
|
+
MsSqlTableCompiler: any;
|
|
9
|
+
MsSqlQueryCompiler: any;
|
|
10
|
+
MsSqlDialect: any;
|
|
7
11
|
PostgresDialectTableCompiler: any;
|
|
8
12
|
Sqlite3Dialect: any;
|
|
9
13
|
Sqlite3DialectTableCompiler: any;
|
|
14
|
+
BetterSqlite3Dialect: any;
|
|
10
15
|
TableCompiler: any;
|
|
11
16
|
};
|
package/MonkeyPatchable.js
CHANGED
|
@@ -15,10 +15,20 @@ const mysql_columncompiler_1 = __importDefault(require("knex/lib/dialects/mysql/
|
|
|
15
15
|
// @ts-ignore
|
|
16
16
|
const mysql_querycompiler_1 = __importDefault(require("knex/lib/dialects/mysql/query/mysql-querycompiler"));
|
|
17
17
|
// @ts-ignore
|
|
18
|
+
const mssql_columncompiler_1 = __importDefault(require("knex/lib/dialects/mssql/schema/mssql-columncompiler"));
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
const mssql_tablecompiler_1 = __importDefault(require("knex/lib/dialects/mssql/schema/mssql-tablecompiler"));
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
const mssql_querycompiler_1 = __importDefault(require("knex/lib/dialects/mssql/query/mssql-querycompiler"));
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
const mssql_1 = __importDefault(require("knex/lib/dialects/mssql"));
|
|
25
|
+
// @ts-ignore
|
|
18
26
|
const pg_tablecompiler_1 = __importDefault(require("knex/lib/dialects/postgres/schema/pg-tablecompiler"));
|
|
19
27
|
// @ts-ignore
|
|
20
28
|
const sqlite3_1 = __importDefault(require("knex/lib/dialects/sqlite3"));
|
|
21
29
|
// @ts-ignore
|
|
30
|
+
const better_sqlite3_1 = __importDefault(require("knex/lib/dialects/better-sqlite3"));
|
|
31
|
+
// @ts-ignore
|
|
22
32
|
const sqlite_tablecompiler_1 = __importDefault(require("knex/lib/dialects/sqlite3/schema/sqlite-tablecompiler"));
|
|
23
33
|
// @ts-ignore
|
|
24
34
|
const tablecompiler_1 = __importDefault(require("knex/lib/schema/tablecompiler"));
|
|
@@ -32,8 +42,13 @@ exports.MonkeyPatchable = {
|
|
|
32
42
|
MySqlDialect: mysql_1.default,
|
|
33
43
|
MySqlColumnCompiler: mysql_columncompiler_1.default,
|
|
34
44
|
MySqlQueryCompiler: mysql_querycompiler_1.default,
|
|
45
|
+
MsSqlColumnCompiler: mssql_columncompiler_1.default,
|
|
46
|
+
MsSqlTableCompiler: mssql_tablecompiler_1.default,
|
|
47
|
+
MsSqlQueryCompiler: mssql_querycompiler_1.default,
|
|
48
|
+
MsSqlDialect: mssql_1.default,
|
|
35
49
|
PostgresDialectTableCompiler: pg_tablecompiler_1.default,
|
|
36
50
|
Sqlite3Dialect: sqlite3_1.default,
|
|
37
51
|
Sqlite3DialectTableCompiler: sqlite_tablecompiler_1.default,
|
|
52
|
+
BetterSqlite3Dialect: better_sqlite3_1.default,
|
|
38
53
|
TableCompiler: tablecompiler_1.default,
|
|
39
54
|
};
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<a href="https://mikro-orm.io"><img src="https://raw.githubusercontent.com/mikro-orm/mikro-orm/master/docs/static/img/logo-readme.svg?sanitize=true" alt="MikroORM" /></a>
|
|
3
3
|
</h1>
|
|
4
4
|
|
|
5
|
-
TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-orm.io/docs/unit-of-work/) and [Identity Map](https://mikro-orm.io/docs/identity-map/) patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite databases.
|
|
5
|
+
TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-orm.io/docs/unit-of-work/) and [Identity Map](https://mikro-orm.io/docs/identity-map/) patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite (including libSQL) databases.
|
|
6
6
|
|
|
7
7
|
> Heavily inspired by [Doctrine](https://www.doctrine-project.org/) and [Hibernate](https://hibernate.org/).
|
|
8
8
|
|
|
@@ -175,21 +175,27 @@ First install the module via `yarn` or `npm` and do not forget to install the da
|
|
|
175
175
|
> Since v4, you should install the driver package, but not the db connector itself, e.g. install `@mikro-orm/sqlite`, but not `sqlite3` as that is already included in the driver package.
|
|
176
176
|
|
|
177
177
|
```sh
|
|
178
|
-
yarn add @mikro-orm/core @mikro-orm/mongodb
|
|
179
|
-
yarn add @mikro-orm/core @mikro-orm/mysql
|
|
180
|
-
yarn add @mikro-orm/core @mikro-orm/mariadb
|
|
181
|
-
yarn add @mikro-orm/core @mikro-orm/postgresql
|
|
182
|
-
yarn add @mikro-orm/core @mikro-orm/
|
|
178
|
+
yarn add @mikro-orm/core @mikro-orm/mongodb # for mongo
|
|
179
|
+
yarn add @mikro-orm/core @mikro-orm/mysql # for mysql/mariadb
|
|
180
|
+
yarn add @mikro-orm/core @mikro-orm/mariadb # for mysql/mariadb
|
|
181
|
+
yarn add @mikro-orm/core @mikro-orm/postgresql # for postgresql
|
|
182
|
+
yarn add @mikro-orm/core @mikro-orm/mssql # for mssql
|
|
183
|
+
yarn add @mikro-orm/core @mikro-orm/sqlite # for sqlite
|
|
184
|
+
yarn add @mikro-orm/core @mikro-orm/better-sqlite # for better-sqlite
|
|
185
|
+
yarn add @mikro-orm/core @mikro-orm/libsql # for libsql
|
|
183
186
|
```
|
|
184
187
|
|
|
185
188
|
or
|
|
186
189
|
|
|
187
190
|
```sh
|
|
188
|
-
npm i -s @mikro-orm/core @mikro-orm/mongodb
|
|
189
|
-
npm i -s @mikro-orm/core @mikro-orm/mysql
|
|
190
|
-
npm i -s @mikro-orm/core @mikro-orm/mariadb
|
|
191
|
-
npm i -s @mikro-orm/core @mikro-orm/postgresql
|
|
192
|
-
npm i -s @mikro-orm/core @mikro-orm/
|
|
191
|
+
npm i -s @mikro-orm/core @mikro-orm/mongodb # for mongo
|
|
192
|
+
npm i -s @mikro-orm/core @mikro-orm/mysql # for mysql/mariadb
|
|
193
|
+
npm i -s @mikro-orm/core @mikro-orm/mariadb # for mysql/mariadb
|
|
194
|
+
npm i -s @mikro-orm/core @mikro-orm/postgresql # for postgresql
|
|
195
|
+
npm i -s @mikro-orm/core @mikro-orm/mssql # for mssql
|
|
196
|
+
npm i -s @mikro-orm/core @mikro-orm/sqlite # for sqlite
|
|
197
|
+
npm i -s @mikro-orm/core @mikro-orm/better-sqlite # for better-sqlite
|
|
198
|
+
npm i -s @mikro-orm/core @mikro-orm/libsql # for libsql
|
|
193
199
|
```
|
|
194
200
|
|
|
195
201
|
Next, if you want to use decorators for your entity definition, you will need to enable support for [decorators](https://www.typescriptlang.org/docs/handbook/decorators.html) as well as `esModuleInterop` in `tsconfig.json` via:
|
package/SqlEntityManager.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Knex } from 'knex';
|
|
2
2
|
import { EntityManager, type AnyEntity, type ConnectionType, type EntityData, type EntityName, type EntityRepository, type GetRepository, type QueryResult, type FilterQuery, type LoggingOptions } from '@mikro-orm/core';
|
|
3
3
|
import type { AbstractSqlDriver } from './AbstractSqlDriver';
|
|
4
|
-
import { QueryBuilder } from './query';
|
|
4
|
+
import type { QueryBuilder } from './query';
|
|
5
5
|
import type { SqlEntityRepository } from './SqlEntityRepository';
|
|
6
6
|
/**
|
|
7
7
|
* @inheritDoc
|
package/SqlEntityManager.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SqlEntityManager = void 0;
|
|
4
4
|
const core_1 = require("@mikro-orm/core");
|
|
5
|
-
const query_1 = require("./query");
|
|
6
5
|
/**
|
|
7
6
|
* @inheritDoc
|
|
8
7
|
*/
|
|
@@ -12,7 +11,7 @@ class SqlEntityManager extends core_1.EntityManager {
|
|
|
12
11
|
*/
|
|
13
12
|
createQueryBuilder(entityName, alias, type, loggerContext) {
|
|
14
13
|
const context = this.getContext(false);
|
|
15
|
-
return
|
|
14
|
+
return this.driver.createQueryBuilder(entityName, context.getTransactionContext(), type, true, loggerContext ?? context.loggerContext, alias, this);
|
|
16
15
|
}
|
|
17
16
|
/**
|
|
18
17
|
* Shortcut for `createQueryBuilder()`
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./mssql"), exports);
|
|
18
|
+
__exportStar(require("./mysql"), exports);
|
|
19
|
+
__exportStar(require("./postgresql"), exports);
|
|
20
|
+
__exportStar(require("./sqlite"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MsSqlColumnCompiler = void 0;
|
|
4
|
+
const MonkeyPatchable_1 = require("../../MonkeyPatchable");
|
|
5
|
+
class MsSqlColumnCompiler extends MonkeyPatchable_1.MonkeyPatchable.MsSqlColumnCompiler {
|
|
6
|
+
enu(allowed) {
|
|
7
|
+
return `nvarchar(100) check (${this.formatter.wrap(this.args[0])} in ('${(allowed.join("', '"))}'))`;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.MsSqlColumnCompiler = MsSqlColumnCompiler;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MsSqlKnexDialect = void 0;
|
|
4
|
+
const MonkeyPatchable_1 = require("../../MonkeyPatchable");
|
|
5
|
+
const MsSqlTableCompiler_1 = require("./MsSqlTableCompiler");
|
|
6
|
+
const MsSqlColumnCompiler_1 = require("./MsSqlColumnCompiler");
|
|
7
|
+
const MsSqlQueryCompiler_1 = require("./MsSqlQueryCompiler");
|
|
8
|
+
class MsSqlKnexDialect extends MonkeyPatchable_1.MonkeyPatchable.MsSqlDialect {
|
|
9
|
+
tableCompiler() {
|
|
10
|
+
// eslint-disable-next-line prefer-rest-params
|
|
11
|
+
return new MsSqlTableCompiler_1.MsSqlTableCompiler(this, ...arguments);
|
|
12
|
+
}
|
|
13
|
+
columnCompiler() {
|
|
14
|
+
// eslint-disable-next-line prefer-rest-params
|
|
15
|
+
return new MsSqlColumnCompiler_1.MsSqlColumnCompiler(this, ...arguments);
|
|
16
|
+
}
|
|
17
|
+
queryCompiler() {
|
|
18
|
+
// eslint-disable-next-line prefer-rest-params
|
|
19
|
+
return new MsSqlQueryCompiler_1.MsSqlQueryCompiler(this, ...arguments);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.MsSqlKnexDialect = MsSqlKnexDialect;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MonkeyPatchable } from '../../MonkeyPatchable';
|
|
2
|
+
export declare class MsSqlQueryCompiler extends MonkeyPatchable.MsSqlQueryCompiler {
|
|
3
|
+
constructor(client: any, builder: any, formatter: any);
|
|
4
|
+
insert(this: any): any;
|
|
5
|
+
_mergeAnd(this: any): string;
|
|
6
|
+
_mergeWhenMatched(this: any, columns: any, updates: any): string;
|
|
7
|
+
_mergeWhenNotMatched(this: any, columns: any): string;
|
|
8
|
+
_getParameters(this: any, params: any): any;
|
|
9
|
+
_mergeInsertIsEmpty(this: any, insert: any): boolean;
|
|
10
|
+
_mergeOn(this: any, conflict: any): string;
|
|
11
|
+
_insertWithMerge(this: any): string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MsSqlQueryCompiler = void 0;
|
|
4
|
+
/* istanbul ignore file */
|
|
5
|
+
const MonkeyPatchable_1 = require("../../MonkeyPatchable");
|
|
6
|
+
const core_1 = require("@mikro-orm/core");
|
|
7
|
+
// upsert support from https://github.com/knex/knex/pull/6050
|
|
8
|
+
class MsSqlQueryCompiler extends MonkeyPatchable_1.MonkeyPatchable.MsSqlQueryCompiler {
|
|
9
|
+
constructor(client, builder, formatter) {
|
|
10
|
+
const onConflict = builder._single.onConflict;
|
|
11
|
+
delete builder._single.onConflict;
|
|
12
|
+
super(client, builder, formatter);
|
|
13
|
+
this.single.onConflict = onConflict;
|
|
14
|
+
}
|
|
15
|
+
// Compiles an "insert" query, allowing for multiple
|
|
16
|
+
// inserts using a single query statement.
|
|
17
|
+
insert() {
|
|
18
|
+
if (this.single.onConflict) {
|
|
19
|
+
return this._insertWithMerge();
|
|
20
|
+
}
|
|
21
|
+
return super.insert();
|
|
22
|
+
}
|
|
23
|
+
_mergeAnd() {
|
|
24
|
+
const wheres = this.where();
|
|
25
|
+
if (!wheres) {
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
28
|
+
return `and ${wheres.slice(6)} `;
|
|
29
|
+
}
|
|
30
|
+
_mergeWhenMatched(columns, updates) {
|
|
31
|
+
let columnsData = [];
|
|
32
|
+
if (!updates || Array.isArray(updates)) {
|
|
33
|
+
columnsData = columns
|
|
34
|
+
.map((column) => `${this.formatter.columnize(column)}=tsource.${this.formatter.columnize(column)}`)
|
|
35
|
+
.join(', ');
|
|
36
|
+
}
|
|
37
|
+
if (typeof updates === 'string') {
|
|
38
|
+
columnsData = `${this.formatter.columnize(updates)}=tsource.${this.formatter.columnize(updates)}`;
|
|
39
|
+
}
|
|
40
|
+
if (!Array.isArray(updates) && typeof updates === 'object') {
|
|
41
|
+
columnsData = Object.entries(updates)
|
|
42
|
+
.map(([key, value]) => `${this.tableName}.${this.formatter.columnize(key)}=(${this._getParameters([value])})`);
|
|
43
|
+
}
|
|
44
|
+
const sql = ` when matched ${this._mergeAnd()}then update set ${columnsData}`;
|
|
45
|
+
return sql;
|
|
46
|
+
}
|
|
47
|
+
_mergeWhenNotMatched(columns) {
|
|
48
|
+
const destinationColumns = this.formatter.columnize(columns);
|
|
49
|
+
const sourceColumns = this.formatter.columnizeWithPrefix('tsource.', columns);
|
|
50
|
+
const sql = ` when not matched then insert (${destinationColumns}) values (${sourceColumns})`;
|
|
51
|
+
return sql;
|
|
52
|
+
}
|
|
53
|
+
_getParameters(params) {
|
|
54
|
+
const sql = this.client.parameterize(params, this.client.valueForUndefined, this.builder, this.bindingsHolder);
|
|
55
|
+
return sql;
|
|
56
|
+
}
|
|
57
|
+
_mergeInsertIsEmpty(insert) {
|
|
58
|
+
return (Array.isArray(insert) && insert.length === 0)
|
|
59
|
+
|| (typeof insert === 'object' && core_1.Utils.isEmpty(insert));
|
|
60
|
+
}
|
|
61
|
+
_mergeOn(conflict) {
|
|
62
|
+
let sql = 'on 1=1';
|
|
63
|
+
if (Array.isArray(conflict)) {
|
|
64
|
+
const conflictColumn = this.formatter.columnize(conflict[0]);
|
|
65
|
+
sql = `on ${this.tableName}.${conflictColumn} = tsource.${conflictColumn}`;
|
|
66
|
+
}
|
|
67
|
+
return sql;
|
|
68
|
+
}
|
|
69
|
+
_insertWithMerge() {
|
|
70
|
+
const { insert = [], onConflict, ignore, merge, returning, options = {} } = this.single;
|
|
71
|
+
if (this._mergeInsertIsEmpty(insert)) {
|
|
72
|
+
return '';
|
|
73
|
+
}
|
|
74
|
+
const insertData = this._prepInsert(insert);
|
|
75
|
+
const insertParameters = insertData.values.map((value) => `(${this._getParameters(value)})`).join(', ');
|
|
76
|
+
const sourceColumns = this.formatter.columnize(insertData.columns);
|
|
77
|
+
const returningSql = returning
|
|
78
|
+
? ` ${this._returning('insert', returning, options.includeTriggerModifications)}`
|
|
79
|
+
: '';
|
|
80
|
+
let sql = `merge into ${this.tableName} using (values ${insertParameters}) as tsource(${sourceColumns}) `;
|
|
81
|
+
sql += this._mergeOn(onConflict);
|
|
82
|
+
sql += this._mergeWhenNotMatched(insertData.columns);
|
|
83
|
+
if (!ignore) {
|
|
84
|
+
sql += this._mergeWhenMatched(insertData.columns, merge.updates);
|
|
85
|
+
}
|
|
86
|
+
sql += returningSql;
|
|
87
|
+
if (options.includeTriggerModifications) {
|
|
88
|
+
sql = this._buildTempTable(returning) + sql + this._buildReturningSelect(returning);
|
|
89
|
+
}
|
|
90
|
+
sql = this.with() + sql + ';';
|
|
91
|
+
return sql;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.MsSqlQueryCompiler = MsSqlQueryCompiler;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { MonkeyPatchable } from '../../MonkeyPatchable';
|
|
2
|
+
export declare class MsSqlTableCompiler extends MonkeyPatchable.MsSqlTableCompiler {
|
|
3
|
+
lowerCase: boolean;
|
|
4
|
+
addColumnsPrefix: string;
|
|
5
|
+
dropColumnPrefix: string;
|
|
6
|
+
alterColumnPrefix: string;
|
|
7
|
+
alterColumns(this: any, columns: any, colBuilder: any): void;
|
|
8
|
+
dropForeign(this: any, columns: any, constraintName: any): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MsSqlTableCompiler = void 0;
|
|
4
|
+
const MonkeyPatchable_1 = require("../../MonkeyPatchable");
|
|
5
|
+
class MsSqlTableCompiler extends MonkeyPatchable_1.MonkeyPatchable.MsSqlTableCompiler {
|
|
6
|
+
lowerCase = true;
|
|
7
|
+
addColumnsPrefix = 'add ';
|
|
8
|
+
dropColumnPrefix = 'drop column ';
|
|
9
|
+
alterColumnPrefix = 'alter column ';
|
|
10
|
+
alterColumns(columns, colBuilder) {
|
|
11
|
+
for (let i = 0, l = colBuilder.length; i < l; i++) {
|
|
12
|
+
const builder = colBuilder[i];
|
|
13
|
+
if (builder.modified.defaultTo) {
|
|
14
|
+
const schema = this.schemaNameRaw || 'dbo';
|
|
15
|
+
const baseQuery = `declare @constraint${i} varchar(100) = (select default_constraints.name from sys.all_columns`
|
|
16
|
+
+ ' join sys.tables on all_columns.object_id = tables.object_id'
|
|
17
|
+
+ ' join sys.schemas on tables.schema_id = schemas.schema_id'
|
|
18
|
+
+ ' join sys.default_constraints on all_columns.default_object_id = default_constraints.object_id'
|
|
19
|
+
+ ` where schemas.name = '${schema}' and tables.name = '${this.tableNameRaw}' and all_columns.name = '${builder.getColumnName()}')`
|
|
20
|
+
+ ` if @constraint${i} is not null exec('alter table ${this.tableNameRaw} drop constraint ' + @constraint${i})`;
|
|
21
|
+
this.pushQuery(baseQuery);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// in SQL server only one column can be altered at a time
|
|
25
|
+
columns.sql.forEach((sql) => {
|
|
26
|
+
this.pushQuery({
|
|
27
|
+
sql: `alter table ${this.tableName()} ${this.alterColumnPrefix.toLowerCase()}${sql}`,
|
|
28
|
+
bindings: columns.bindings,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
dropForeign(columns, constraintName) {
|
|
33
|
+
/* istanbul ignore next */
|
|
34
|
+
constraintName = constraintName
|
|
35
|
+
? this.formatter.wrap(constraintName)
|
|
36
|
+
: this._indexCommand('foreign', this.tableNameRaw, columns);
|
|
37
|
+
this.pushQuery(`alter table ${this.tableName()} drop constraint ${constraintName}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.MsSqlTableCompiler = MsSqlTableCompiler;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './MsSqlKnexDialect';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./MsSqlKnexDialect"), exports);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MariaDbKnexDialect = void 0;
|
|
4
|
+
const MySqlKnexDialect_1 = require("./MySqlKnexDialect");
|
|
5
|
+
class MariaDbKnexDialect extends MySqlKnexDialect_1.MySqlKnexDialect {
|
|
6
|
+
get driverName() {
|
|
7
|
+
return 'mariadb';
|
|
8
|
+
}
|
|
9
|
+
_driver() {
|
|
10
|
+
return require('mariadb/callback');
|
|
11
|
+
}
|
|
12
|
+
validateConnection(connection) {
|
|
13
|
+
return connection.isValid();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.MariaDbKnexDialect = MariaDbKnexDialect;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import BaseMySqlColumnCompiler from 'knex/lib/dialects/mysql/schema/mysql-columncompiler';
|
|
2
|
+
export declare class MySqlColumnCompiler extends BaseMySqlColumnCompiler {
|
|
3
|
+
increments(this: any, options?: {
|
|
4
|
+
primaryKey: boolean;
|
|
5
|
+
}): string;
|
|
6
|
+
bigincrements(this: any, options?: {
|
|
7
|
+
primaryKey: boolean;
|
|
8
|
+
}): string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MySqlColumnCompiler = void 0;
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
const mysql_columncompiler_1 = __importDefault(require("knex/lib/dialects/mysql/schema/mysql-columncompiler"));
|
|
9
|
+
class MySqlColumnCompiler extends mysql_columncompiler_1.default {
|
|
10
|
+
// we need the old behaviour to be able to add auto_increment to a column that is already PK
|
|
11
|
+
increments(options = { primaryKey: true }) {
|
|
12
|
+
return 'int unsigned not null auto_increment' + (this.tableCompiler._canBeAddPrimaryKey(options) ? ' primary key' : '');
|
|
13
|
+
}
|
|
14
|
+
/* istanbul ignore next */
|
|
15
|
+
bigincrements(options = { primaryKey: true }) {
|
|
16
|
+
return 'bigint unsigned not null auto_increment' + (this.tableCompiler._canBeAddPrimaryKey(options) ? ' primary key' : '');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.MySqlColumnCompiler = MySqlColumnCompiler;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
2
|
+
import { AbstractSqlConnection } from '../../AbstractSqlConnection';
|
|
3
|
+
export declare class MySqlConnection extends AbstractSqlConnection {
|
|
4
|
+
createKnex(): void;
|
|
5
|
+
getDefaultClientUrl(): string;
|
|
6
|
+
getConnectionOptions(): Knex.MySqlConnectionConfig;
|
|
7
|
+
protected transformRawResult<T>(res: any, method: 'all' | 'get' | 'run'): T;
|
|
8
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MySqlConnection = void 0;
|
|
4
|
+
const MySqlKnexDialect_1 = require("./MySqlKnexDialect");
|
|
5
|
+
const AbstractSqlConnection_1 = require("../../AbstractSqlConnection");
|
|
6
|
+
class MySqlConnection extends AbstractSqlConnection_1.AbstractSqlConnection {
|
|
7
|
+
createKnex() {
|
|
8
|
+
this.client = this.createKnexClient(MySqlKnexDialect_1.MySqlKnexDialect);
|
|
9
|
+
this.connected = true;
|
|
10
|
+
}
|
|
11
|
+
getDefaultClientUrl() {
|
|
12
|
+
return 'mysql://root@127.0.0.1:3306';
|
|
13
|
+
}
|
|
14
|
+
getConnectionOptions() {
|
|
15
|
+
const ret = super.getConnectionOptions();
|
|
16
|
+
if (this.config.get('multipleStatements')) {
|
|
17
|
+
ret.multipleStatements = this.config.get('multipleStatements');
|
|
18
|
+
}
|
|
19
|
+
if (this.config.get('forceUtcTimezone')) {
|
|
20
|
+
ret.timezone = 'Z';
|
|
21
|
+
}
|
|
22
|
+
if (this.config.get('timezone')) {
|
|
23
|
+
ret.timezone = this.config.get('timezone');
|
|
24
|
+
}
|
|
25
|
+
ret.supportBigNumbers = true;
|
|
26
|
+
ret.dateStrings = true;
|
|
27
|
+
return ret;
|
|
28
|
+
}
|
|
29
|
+
transformRawResult(res, method) {
|
|
30
|
+
if (method === 'run' && ['OkPacket', 'ResultSetHeader'].includes(res[0].constructor.name)) {
|
|
31
|
+
return {
|
|
32
|
+
insertId: res[0].insertId,
|
|
33
|
+
affectedRows: res[0].affectedRows,
|
|
34
|
+
rows: [],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (method === 'get') {
|
|
38
|
+
return res[0][0];
|
|
39
|
+
}
|
|
40
|
+
return res[0];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.MySqlConnection = MySqlConnection;
|