@mikro-orm/knex 7.0.0-dev.1 → 7.0.0-dev.10
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.d.ts +2 -2
- package/AbstractSqlConnection.js +33 -31
- package/AbstractSqlDriver.d.ts +14 -12
- package/AbstractSqlDriver.js +198 -186
- package/AbstractSqlPlatform.d.ts +4 -4
- package/AbstractSqlPlatform.js +17 -21
- package/PivotCollectionPersister.d.ts +1 -1
- package/PivotCollectionPersister.js +5 -8
- package/SqlEntityManager.d.ts +4 -3
- package/SqlEntityManager.js +2 -6
- package/SqlEntityRepository.d.ts +2 -2
- package/SqlEntityRepository.js +2 -6
- package/dialects/index.d.ts +4 -4
- package/dialects/index.js +4 -20
- package/dialects/mssql/MsSqlNativeQueryBuilder.d.ts +1 -1
- package/dialects/mssql/MsSqlNativeQueryBuilder.js +29 -29
- package/dialects/mssql/index.d.ts +1 -1
- package/dialects/mssql/index.js +1 -17
- package/dialects/mysql/MySqlExceptionConverter.js +16 -19
- package/dialects/mysql/MySqlNativeQueryBuilder.d.ts +1 -1
- package/dialects/mysql/MySqlNativeQueryBuilder.js +13 -17
- package/dialects/mysql/MySqlPlatform.d.ts +5 -5
- package/dialects/mysql/MySqlPlatform.js +16 -20
- package/dialects/mysql/MySqlSchemaHelper.d.ts +5 -5
- package/dialects/mysql/MySqlSchemaHelper.js +8 -12
- package/dialects/mysql/index.d.ts +4 -4
- package/dialects/mysql/index.js +4 -20
- package/dialects/postgresql/PostgreSqlNativeQueryBuilder.d.ts +1 -1
- package/dialects/postgresql/PostgreSqlNativeQueryBuilder.js +2 -6
- package/dialects/postgresql/index.d.ts +1 -1
- package/dialects/postgresql/index.js +1 -17
- package/dialects/sqlite/BaseSqliteConnection.d.ts +2 -2
- package/dialects/sqlite/BaseSqliteConnection.js +14 -12
- package/dialects/sqlite/BaseSqlitePlatform.d.ts +4 -5
- package/dialects/sqlite/BaseSqlitePlatform.js +11 -19
- package/dialects/sqlite/SqliteExceptionConverter.js +16 -19
- package/dialects/sqlite/SqliteNativeQueryBuilder.d.ts +1 -1
- package/dialects/sqlite/SqliteNativeQueryBuilder.js +2 -6
- package/dialects/sqlite/SqliteSchemaHelper.d.ts +5 -5
- package/dialects/sqlite/SqliteSchemaHelper.js +22 -26
- package/dialects/sqlite/index.d.ts +5 -5
- package/dialects/sqlite/index.js +5 -21
- package/index.d.ts +11 -11
- package/index.js +13 -34
- package/package.json +7 -16
- package/query/ArrayCriteriaNode.d.ts +2 -2
- package/query/ArrayCriteriaNode.js +2 -6
- package/query/CriteriaNode.d.ts +1 -1
- package/query/CriteriaNode.js +25 -33
- package/query/CriteriaNodeFactory.d.ts +1 -1
- package/query/CriteriaNodeFactory.js +17 -21
- package/query/NativeQueryBuilder.d.ts +2 -2
- package/query/NativeQueryBuilder.js +33 -37
- package/query/ObjectCriteriaNode.d.ts +2 -2
- package/query/ObjectCriteriaNode.js +43 -43
- package/query/QueryBuilder.d.ts +17 -15
- package/query/QueryBuilder.js +204 -193
- package/query/QueryBuilderHelper.d.ts +4 -4
- package/query/QueryBuilderHelper.js +86 -96
- package/query/ScalarCriteriaNode.d.ts +2 -2
- package/query/ScalarCriteriaNode.js +12 -16
- package/query/enums.js +4 -7
- package/query/index.d.ts +9 -9
- package/query/index.js +9 -25
- package/schema/DatabaseSchema.d.ts +3 -3
- package/schema/DatabaseSchema.js +7 -11
- package/schema/DatabaseTable.d.ts +3 -3
- package/schema/DatabaseTable.js +44 -33
- package/schema/SchemaComparator.d.ts +4 -4
- package/schema/SchemaComparator.js +15 -19
- package/schema/SchemaHelper.d.ts +5 -5
- package/schema/SchemaHelper.js +22 -26
- package/schema/SqlSchemaGenerator.d.ts +4 -4
- package/schema/SqlSchemaGenerator.js +23 -36
- package/schema/index.d.ts +5 -5
- package/schema/index.js +5 -21
- package/typings.d.ts +7 -4
- package/typings.js +1 -2
- package/index.mjs +0 -232
package/AbstractSqlPlatform.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type Constructor, type EntityManager, type EntityRepository, type IDatabaseDriver, type IsolationLevel, type MikroORM, Platform } from '@mikro-orm/core';
|
|
2
|
-
import { SqlSchemaGenerator } from './schema/SqlSchemaGenerator';
|
|
3
|
-
import { type SchemaHelper } from './schema/SchemaHelper';
|
|
4
|
-
import type { IndexDef } from './typings';
|
|
5
|
-
import { NativeQueryBuilder } from './query/NativeQueryBuilder';
|
|
2
|
+
import { SqlSchemaGenerator } from './schema/SqlSchemaGenerator.js';
|
|
3
|
+
import { type SchemaHelper } from './schema/SchemaHelper.js';
|
|
4
|
+
import type { IndexDef } from './typings.js';
|
|
5
|
+
import { NativeQueryBuilder } from './query/NativeQueryBuilder.js';
|
|
6
6
|
export declare abstract class AbstractSqlPlatform extends Platform {
|
|
7
7
|
protected readonly schemaHelper?: SchemaHelper;
|
|
8
8
|
usesPivotTable(): boolean;
|
package/AbstractSqlPlatform.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const SqlSchemaGenerator_1 = require("./schema/SqlSchemaGenerator");
|
|
8
|
-
const NativeQueryBuilder_1 = require("./query/NativeQueryBuilder");
|
|
9
|
-
class AbstractSqlPlatform extends core_1.Platform {
|
|
1
|
+
import SqlString from 'sqlstring';
|
|
2
|
+
import { isRaw, JsonProperty, Platform, raw, Utils, } from '@mikro-orm/core';
|
|
3
|
+
import { SqlEntityRepository } from './SqlEntityRepository.js';
|
|
4
|
+
import { SqlSchemaGenerator } from './schema/SqlSchemaGenerator.js';
|
|
5
|
+
import { NativeQueryBuilder } from './query/NativeQueryBuilder.js';
|
|
6
|
+
export class AbstractSqlPlatform extends Platform {
|
|
10
7
|
schemaHelper;
|
|
11
8
|
usesPivotTable() {
|
|
12
9
|
return true;
|
|
@@ -15,23 +12,23 @@ class AbstractSqlPlatform extends core_1.Platform {
|
|
|
15
12
|
return true;
|
|
16
13
|
}
|
|
17
14
|
getRepositoryClass() {
|
|
18
|
-
return
|
|
15
|
+
return SqlEntityRepository;
|
|
19
16
|
}
|
|
20
17
|
getSchemaHelper() {
|
|
21
18
|
return this.schemaHelper;
|
|
22
19
|
}
|
|
23
20
|
/** @inheritDoc */
|
|
24
21
|
lookupExtensions(orm) {
|
|
25
|
-
|
|
22
|
+
SqlSchemaGenerator.register(orm);
|
|
26
23
|
}
|
|
27
|
-
/*
|
|
24
|
+
/* v8 ignore next 3: kept for type inference only */
|
|
28
25
|
getSchemaGenerator(driver, em) {
|
|
29
|
-
return new
|
|
26
|
+
return new SqlSchemaGenerator(em ?? driver);
|
|
30
27
|
}
|
|
31
|
-
/*
|
|
28
|
+
/* v8 ignore next 4 */
|
|
32
29
|
/** @internal */
|
|
33
30
|
createNativeQueryBuilder() {
|
|
34
|
-
return new
|
|
31
|
+
return new NativeQueryBuilder(this);
|
|
35
32
|
}
|
|
36
33
|
getBeginTransactionSQL(options) {
|
|
37
34
|
if (options?.isolationLevel) {
|
|
@@ -55,16 +52,16 @@ class AbstractSqlPlatform extends core_1.Platform {
|
|
|
55
52
|
return `release savepoint ${savepointName}`;
|
|
56
53
|
}
|
|
57
54
|
quoteValue(value) {
|
|
58
|
-
if (
|
|
55
|
+
if (isRaw(value)) {
|
|
59
56
|
return this.formatQuery(value.sql, value.params);
|
|
60
57
|
}
|
|
61
|
-
if (
|
|
58
|
+
if (Utils.isPlainObject(value) || value?.[JsonProperty]) {
|
|
62
59
|
return this.escape(JSON.stringify(value));
|
|
63
60
|
}
|
|
64
61
|
return this.escape(value);
|
|
65
62
|
}
|
|
66
63
|
escape(value) {
|
|
67
|
-
return
|
|
64
|
+
return SqlString.escape(value, true, this.timezone);
|
|
68
65
|
}
|
|
69
66
|
getSearchJsonPropertySQL(path, type, aliased) {
|
|
70
67
|
return this.getSearchJsonPropertyKey(path.split('->'), type, aliased);
|
|
@@ -73,9 +70,9 @@ class AbstractSqlPlatform extends core_1.Platform {
|
|
|
73
70
|
const [a, ...b] = path;
|
|
74
71
|
const quoteKey = (key) => key.match(/^[a-z]\w*$/i) ? key : `"${key}"`;
|
|
75
72
|
if (aliased) {
|
|
76
|
-
return
|
|
73
|
+
return raw(alias => `json_extract(${this.quoteIdentifier(`${alias}.${a}`)}, '$.${b.map(quoteKey).join('.')}')`);
|
|
77
74
|
}
|
|
78
|
-
return
|
|
75
|
+
return raw(`json_extract(${this.quoteIdentifier(a)}, '$.${b.map(quoteKey).join('.')}')`);
|
|
79
76
|
}
|
|
80
77
|
getJsonIndexDefinition(index) {
|
|
81
78
|
return index.columnNames
|
|
@@ -105,4 +102,3 @@ class AbstractSqlPlatform extends core_1.Platform {
|
|
|
105
102
|
return [`${column} ${direction.toLowerCase()}`];
|
|
106
103
|
}
|
|
107
104
|
}
|
|
108
|
-
exports.AbstractSqlPlatform = AbstractSqlPlatform;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type EntityMetadata, type EntityProperty, type Primary, type Transaction } from '@mikro-orm/core';
|
|
2
|
-
import { type AbstractSqlDriver } from './AbstractSqlDriver';
|
|
2
|
+
import { type AbstractSqlDriver } from './AbstractSqlDriver.js';
|
|
3
3
|
export declare class PivotCollectionPersister<Entity extends object> {
|
|
4
4
|
private readonly meta;
|
|
5
5
|
private readonly driver;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PivotCollectionPersister = void 0;
|
|
4
|
-
const core_1 = require("@mikro-orm/core");
|
|
1
|
+
import { Utils, } from '@mikro-orm/core';
|
|
5
2
|
class InsertStatement {
|
|
6
3
|
keys;
|
|
7
4
|
data;
|
|
@@ -36,7 +33,7 @@ class DeleteStatement {
|
|
|
36
33
|
return cond;
|
|
37
34
|
}
|
|
38
35
|
}
|
|
39
|
-
class PivotCollectionPersister {
|
|
36
|
+
export class PivotCollectionPersister {
|
|
40
37
|
meta;
|
|
41
38
|
driver;
|
|
42
39
|
ctx;
|
|
@@ -113,7 +110,6 @@ class PivotCollectionPersister {
|
|
|
113
110
|
items[insert.order] = insert.getData();
|
|
114
111
|
}
|
|
115
112
|
items = items.filter(i => i);
|
|
116
|
-
/* istanbul ignore else */
|
|
117
113
|
if (this.platform.allowsMultiInsert()) {
|
|
118
114
|
for (let i = 0; i < items.length; i += this.batchSize) {
|
|
119
115
|
const chunk = items.slice(i, i + this.batchSize);
|
|
@@ -124,15 +120,16 @@ class PivotCollectionPersister {
|
|
|
124
120
|
processCollections: false,
|
|
125
121
|
});
|
|
126
122
|
}
|
|
123
|
+
/* v8 ignore start */
|
|
127
124
|
}
|
|
128
125
|
else {
|
|
129
|
-
await
|
|
126
|
+
await Utils.runSerial(items, item => {
|
|
130
127
|
return this.driver.createQueryBuilder(this.meta.className, this.ctx, 'write')
|
|
131
128
|
.withSchema(this.schema)
|
|
132
129
|
.insert(item)
|
|
133
130
|
.execute('run', false);
|
|
134
131
|
});
|
|
135
132
|
}
|
|
133
|
+
/* v8 ignore stop */
|
|
136
134
|
}
|
|
137
135
|
}
|
|
138
|
-
exports.PivotCollectionPersister = PivotCollectionPersister;
|
package/SqlEntityManager.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { EntityManager, type AnyEntity, type ConnectionType, type EntityData, type EntityName, type EntityRepository, type GetRepository, type QueryResult, type FilterQuery, type LoggingOptions, type RawQueryFragment } from '@mikro-orm/core';
|
|
2
|
-
import type { AbstractSqlDriver } from './AbstractSqlDriver';
|
|
3
|
-
import type { NativeQueryBuilder
|
|
4
|
-
import type {
|
|
2
|
+
import type { AbstractSqlDriver } from './AbstractSqlDriver.js';
|
|
3
|
+
import type { NativeQueryBuilder } from './query/NativeQueryBuilder.js';
|
|
4
|
+
import type { QueryBuilder } from './query/QueryBuilder.js';
|
|
5
|
+
import type { SqlEntityRepository } from './SqlEntityRepository.js';
|
|
5
6
|
/**
|
|
6
7
|
* @inheritDoc
|
|
7
8
|
*/
|
package/SqlEntityManager.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SqlEntityManager = void 0;
|
|
4
|
-
const core_1 = require("@mikro-orm/core");
|
|
1
|
+
import { EntityManager, } from '@mikro-orm/core';
|
|
5
2
|
/**
|
|
6
3
|
* @inheritDoc
|
|
7
4
|
*/
|
|
8
|
-
class SqlEntityManager extends
|
|
5
|
+
export class SqlEntityManager extends EntityManager {
|
|
9
6
|
/**
|
|
10
7
|
* Creates a QueryBuilder instance
|
|
11
8
|
*/
|
|
@@ -36,4 +33,3 @@ class SqlEntityManager extends core_1.EntityManager {
|
|
|
36
33
|
return where;
|
|
37
34
|
}
|
|
38
35
|
}
|
|
39
|
-
exports.SqlEntityManager = SqlEntityManager;
|
package/SqlEntityRepository.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EntityRepository, type EntityName } from '@mikro-orm/core';
|
|
2
|
-
import type { SqlEntityManager } from './SqlEntityManager';
|
|
3
|
-
import type { QueryBuilder } from './query';
|
|
2
|
+
import type { SqlEntityManager } from './SqlEntityManager.js';
|
|
3
|
+
import type { QueryBuilder } from './query/QueryBuilder.js';
|
|
4
4
|
export declare class SqlEntityRepository<Entity extends object> extends EntityRepository<Entity> {
|
|
5
5
|
protected readonly em: SqlEntityManager;
|
|
6
6
|
constructor(em: SqlEntityManager, entityName: EntityName<Entity>);
|
package/SqlEntityRepository.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.SqlEntityRepository = void 0;
|
|
4
|
-
const core_1 = require("@mikro-orm/core");
|
|
5
|
-
class SqlEntityRepository extends core_1.EntityRepository {
|
|
1
|
+
import { EntityRepository } from '@mikro-orm/core';
|
|
2
|
+
export class SqlEntityRepository extends EntityRepository {
|
|
6
3
|
em;
|
|
7
4
|
constructor(em, entityName) {
|
|
8
5
|
super(em, entityName);
|
|
@@ -27,4 +24,3 @@ class SqlEntityRepository extends core_1.EntityRepository {
|
|
|
27
24
|
return this.em;
|
|
28
25
|
}
|
|
29
26
|
}
|
|
30
|
-
exports.SqlEntityRepository = SqlEntityRepository;
|
package/dialects/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './mssql';
|
|
2
|
-
export * from './mysql';
|
|
3
|
-
export * from './postgresql';
|
|
4
|
-
export * from './sqlite';
|
|
1
|
+
export * from './mssql/index.js';
|
|
2
|
+
export * from './mysql/index.js';
|
|
3
|
+
export * from './postgresql/index.js';
|
|
4
|
+
export * from './sqlite/index.js';
|
package/dialects/index.js
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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);
|
|
1
|
+
export * from './mssql/index.js';
|
|
2
|
+
export * from './mysql/index.js';
|
|
3
|
+
export * from './postgresql/index.js';
|
|
4
|
+
export * from './sqlite/index.js';
|
|
@@ -1,57 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const core_1 = require("@mikro-orm/core");
|
|
5
|
-
const NativeQueryBuilder_1 = require("../../query/NativeQueryBuilder");
|
|
6
|
-
const enums_1 = require("../../query/enums");
|
|
1
|
+
import { LockMode, QueryFlag, RawQueryFragment, Utils } from '@mikro-orm/core';
|
|
2
|
+
import { NativeQueryBuilder } from '../../query/NativeQueryBuilder.js';
|
|
3
|
+
import { QueryType } from '../../query/enums.js';
|
|
7
4
|
/** @internal */
|
|
8
|
-
class MsSqlNativeQueryBuilder extends
|
|
5
|
+
export class MsSqlNativeQueryBuilder extends NativeQueryBuilder {
|
|
9
6
|
compile() {
|
|
10
7
|
if (!this.type) {
|
|
11
8
|
throw new Error('No query type provided');
|
|
12
9
|
}
|
|
13
10
|
this.parts.length = 0;
|
|
14
11
|
this.params.length = 0;
|
|
15
|
-
if (this.options.flags?.has(
|
|
12
|
+
if (this.options.flags?.has(QueryFlag.IDENTITY_INSERT)) {
|
|
16
13
|
this.parts.push(`set identity_insert ${this.getTableName()} on;`);
|
|
17
14
|
}
|
|
18
15
|
if (this.options.comment) {
|
|
19
16
|
this.parts.push(...this.options.comment.map(comment => `/* ${comment} */`));
|
|
20
17
|
}
|
|
21
|
-
if (this.options.onConflict && !
|
|
18
|
+
if (this.options.onConflict && !Utils.isEmpty(Utils.asArray(this.options.data)[0])) {
|
|
22
19
|
this.compileUpsert();
|
|
23
20
|
}
|
|
24
21
|
else {
|
|
25
22
|
switch (this.type) {
|
|
26
|
-
case
|
|
27
|
-
case
|
|
23
|
+
case QueryType.SELECT:
|
|
24
|
+
case QueryType.COUNT:
|
|
28
25
|
this.compileSelect();
|
|
29
26
|
break;
|
|
30
|
-
case
|
|
27
|
+
case QueryType.INSERT:
|
|
31
28
|
this.compileInsert();
|
|
32
29
|
break;
|
|
33
|
-
case
|
|
30
|
+
case QueryType.UPDATE:
|
|
34
31
|
this.compileUpdate();
|
|
35
32
|
break;
|
|
36
|
-
case
|
|
33
|
+
case QueryType.DELETE:
|
|
37
34
|
this.compileDelete();
|
|
38
35
|
break;
|
|
39
|
-
case
|
|
36
|
+
case QueryType.TRUNCATE:
|
|
40
37
|
this.compileTruncate();
|
|
41
38
|
break;
|
|
42
39
|
}
|
|
43
|
-
if ([
|
|
40
|
+
if ([QueryType.INSERT, QueryType.UPDATE, QueryType.DELETE].includes(this.type)) {
|
|
44
41
|
this.parts[this.parts.length - 1] += '; select @@rowcount;';
|
|
45
42
|
}
|
|
46
43
|
}
|
|
47
|
-
if (this.options.flags?.has(
|
|
44
|
+
if (this.options.flags?.has(QueryFlag.IDENTITY_INSERT)) {
|
|
48
45
|
this.parts.push(`set identity_insert ${this.getTableName()} off;`);
|
|
49
46
|
}
|
|
50
47
|
return this.combineParts();
|
|
51
48
|
}
|
|
52
49
|
compileUpsert() {
|
|
53
50
|
const clause = this.options.onConflict;
|
|
54
|
-
const dataAsArray =
|
|
51
|
+
const dataAsArray = Utils.asArray(this.options.data);
|
|
55
52
|
const keys = Object.keys(dataAsArray[0]);
|
|
56
53
|
const values = keys.map(() => '?');
|
|
57
54
|
const parts = [];
|
|
@@ -63,14 +60,16 @@ class MsSqlNativeQueryBuilder extends NativeQueryBuilder_1.NativeQueryBuilder {
|
|
|
63
60
|
}
|
|
64
61
|
this.parts.push(`merge into ${this.getTableName()}`);
|
|
65
62
|
this.parts.push(`using (values ${parts.join(', ')}) as tsource(${keys.map(key => this.quote(key)).join(', ')})`);
|
|
66
|
-
if (clause.fields instanceof
|
|
63
|
+
if (clause.fields instanceof RawQueryFragment) {
|
|
67
64
|
this.parts.push(clause.fields.sql);
|
|
68
65
|
this.params.push(...clause.fields.params);
|
|
69
66
|
}
|
|
70
67
|
else if (clause.fields.length > 0) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
const fields = clause.fields.map(field => {
|
|
69
|
+
const col = this.quote(field);
|
|
70
|
+
return `${this.getTableName()}.${col} = tsource.${col}`;
|
|
71
|
+
});
|
|
72
|
+
this.parts.push(`on ${fields.join(' and ')}`);
|
|
74
73
|
}
|
|
75
74
|
const sourceColumns = keys.map(field => `tsource.${this.quote(field)}`).join(', ');
|
|
76
75
|
const destinationColumns = keys.map(field => this.quote(field)).join(', ');
|
|
@@ -83,7 +82,9 @@ class MsSqlNativeQueryBuilder extends NativeQueryBuilder_1.NativeQueryBuilder {
|
|
|
83
82
|
}
|
|
84
83
|
this.parts.push('then update set');
|
|
85
84
|
if (!clause.merge || Array.isArray(clause.merge)) {
|
|
86
|
-
const parts = keys
|
|
85
|
+
const parts = keys
|
|
86
|
+
.filter(field => !Array.isArray(clause.fields) || !clause.fields.includes(field))
|
|
87
|
+
.map((column) => `${this.quote(column)} = tsource.${this.quote(column)}`);
|
|
87
88
|
this.parts.push(parts.join(', '));
|
|
88
89
|
}
|
|
89
90
|
else if (typeof clause.merge === 'object') {
|
|
@@ -128,7 +129,7 @@ class MsSqlNativeQueryBuilder extends NativeQueryBuilder_1.NativeQueryBuilder {
|
|
|
128
129
|
this.parts.push(`order by ${this.options.orderBy}`);
|
|
129
130
|
}
|
|
130
131
|
if (this.options.offset != null) {
|
|
131
|
-
/*
|
|
132
|
+
/* v8 ignore next 3 */
|
|
132
133
|
if (!this.options.orderBy) {
|
|
133
134
|
throw new Error('Order by clause is required for pagination');
|
|
134
135
|
}
|
|
@@ -141,14 +142,14 @@ class MsSqlNativeQueryBuilder extends NativeQueryBuilder_1.NativeQueryBuilder {
|
|
|
141
142
|
}
|
|
142
143
|
}
|
|
143
144
|
addLockClause() {
|
|
144
|
-
if (!this.options.lockMode || ![
|
|
145
|
+
if (!this.options.lockMode || ![LockMode.PESSIMISTIC_READ, LockMode.PESSIMISTIC_WRITE].includes(this.options.lockMode)) {
|
|
145
146
|
return;
|
|
146
147
|
}
|
|
147
148
|
const map = {
|
|
148
|
-
[
|
|
149
|
-
[
|
|
149
|
+
[LockMode.PESSIMISTIC_READ]: 'with (holdlock)',
|
|
150
|
+
[LockMode.PESSIMISTIC_WRITE]: 'with (updlock)',
|
|
150
151
|
};
|
|
151
|
-
if (this.options.lockMode !==
|
|
152
|
+
if (this.options.lockMode !== LockMode.OPTIMISTIC) {
|
|
152
153
|
this.parts.push(map[this.options.lockMode]);
|
|
153
154
|
}
|
|
154
155
|
}
|
|
@@ -158,4 +159,3 @@ class MsSqlNativeQueryBuilder extends NativeQueryBuilder_1.NativeQueryBuilder {
|
|
|
158
159
|
this.parts.push(sql);
|
|
159
160
|
}
|
|
160
161
|
}
|
|
161
|
-
exports.MsSqlNativeQueryBuilder = MsSqlNativeQueryBuilder;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './MsSqlNativeQueryBuilder';
|
|
1
|
+
export * from './MsSqlNativeQueryBuilder.js';
|
package/dialects/mssql/index.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
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("./MsSqlNativeQueryBuilder"), exports);
|
|
1
|
+
export * from './MsSqlNativeQueryBuilder.js';
|
|
@@ -1,47 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.MySqlExceptionConverter = void 0;
|
|
4
|
-
const core_1 = require("@mikro-orm/core");
|
|
5
|
-
class MySqlExceptionConverter extends core_1.ExceptionConverter {
|
|
6
|
-
/* istanbul ignore next */
|
|
1
|
+
import { DeadlockException, LockWaitTimeoutException, TableExistsException, TableNotFoundException, ForeignKeyConstraintViolationException, UniqueConstraintViolationException, InvalidFieldNameException, NonUniqueFieldNameException, SyntaxErrorException, ConnectionException, NotNullConstraintViolationException, ExceptionConverter, CheckConstraintViolationException, } from '@mikro-orm/core';
|
|
2
|
+
export class MySqlExceptionConverter extends ExceptionConverter {
|
|
7
3
|
/**
|
|
8
4
|
* @link http://dev.mysql.com/doc/refman/5.7/en/error-messages-client.html
|
|
9
5
|
* @link http://dev.mysql.com/doc/refman/5.7/en/error-messages-server.html
|
|
10
6
|
* @link https://github.com/doctrine/dbal/blob/master/src/Driver/AbstractMySQLDriver.php
|
|
11
7
|
*/
|
|
12
8
|
convertException(exception) {
|
|
9
|
+
/* v8 ignore start */
|
|
13
10
|
switch (exception.errno) {
|
|
14
11
|
case 1213:
|
|
15
|
-
return new
|
|
12
|
+
return new DeadlockException(exception);
|
|
16
13
|
case 1205:
|
|
17
|
-
return new
|
|
14
|
+
return new LockWaitTimeoutException(exception);
|
|
18
15
|
case 1050:
|
|
19
|
-
return new
|
|
16
|
+
return new TableExistsException(exception);
|
|
20
17
|
case 1051:
|
|
21
18
|
case 1146:
|
|
22
|
-
return new
|
|
19
|
+
return new TableNotFoundException(exception);
|
|
23
20
|
case 1216:
|
|
24
21
|
case 1217:
|
|
25
22
|
case 1451:
|
|
26
23
|
case 1452:
|
|
27
24
|
case 1701:
|
|
28
|
-
return new
|
|
25
|
+
return new ForeignKeyConstraintViolationException(exception);
|
|
29
26
|
case 3819:
|
|
30
27
|
case 4025:
|
|
31
|
-
return new
|
|
28
|
+
return new CheckConstraintViolationException(exception);
|
|
32
29
|
case 1062:
|
|
33
30
|
case 1557:
|
|
34
31
|
case 1569:
|
|
35
32
|
case 1586:
|
|
36
|
-
return new
|
|
33
|
+
return new UniqueConstraintViolationException(exception);
|
|
37
34
|
case 1054:
|
|
38
35
|
case 1166:
|
|
39
36
|
case 1611:
|
|
40
|
-
return new
|
|
37
|
+
return new InvalidFieldNameException(exception);
|
|
41
38
|
case 1052:
|
|
42
39
|
case 1060:
|
|
43
40
|
case 1110:
|
|
44
|
-
return new
|
|
41
|
+
return new NonUniqueFieldNameException(exception);
|
|
45
42
|
case 1064:
|
|
46
43
|
case 1149:
|
|
47
44
|
case 1287:
|
|
@@ -54,7 +51,7 @@ class MySqlExceptionConverter extends core_1.ExceptionConverter {
|
|
|
54
51
|
case 1541:
|
|
55
52
|
case 1554:
|
|
56
53
|
case 1626:
|
|
57
|
-
return new
|
|
54
|
+
return new SyntaxErrorException(exception);
|
|
58
55
|
case 1044:
|
|
59
56
|
case 1045:
|
|
60
57
|
case 1046:
|
|
@@ -67,7 +64,7 @@ class MySqlExceptionConverter extends core_1.ExceptionConverter {
|
|
|
67
64
|
case 1429:
|
|
68
65
|
case 2002:
|
|
69
66
|
case 2005:
|
|
70
|
-
return new
|
|
67
|
+
return new ConnectionException(exception);
|
|
71
68
|
case 1048:
|
|
72
69
|
case 1121:
|
|
73
70
|
case 1138:
|
|
@@ -76,9 +73,9 @@ class MySqlExceptionConverter extends core_1.ExceptionConverter {
|
|
|
76
73
|
case 1263:
|
|
77
74
|
case 1364:
|
|
78
75
|
case 1566:
|
|
79
|
-
return new
|
|
76
|
+
return new NotNullConstraintViolationException(exception);
|
|
80
77
|
}
|
|
78
|
+
/* v8 ignore stop */
|
|
81
79
|
return super.convertException(exception);
|
|
82
80
|
}
|
|
83
81
|
}
|
|
84
|
-
exports.MySqlExceptionConverter = MySqlExceptionConverter;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NativeQueryBuilder } from '../../query/NativeQueryBuilder';
|
|
1
|
+
import { NativeQueryBuilder } from '../../query/NativeQueryBuilder.js';
|
|
2
2
|
/** @internal */
|
|
3
3
|
export declare class MySqlNativeQueryBuilder extends NativeQueryBuilder {
|
|
4
4
|
protected compileInsert(): void;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.MySqlNativeQueryBuilder = void 0;
|
|
4
|
-
const core_1 = require("@mikro-orm/core");
|
|
5
|
-
const NativeQueryBuilder_1 = require("../../query/NativeQueryBuilder");
|
|
1
|
+
import { LockMode, RawQueryFragment, Utils } from '@mikro-orm/core';
|
|
2
|
+
import { NativeQueryBuilder } from '../../query/NativeQueryBuilder.js';
|
|
6
3
|
/** @internal */
|
|
7
|
-
class MySqlNativeQueryBuilder extends
|
|
4
|
+
export class MySqlNativeQueryBuilder extends NativeQueryBuilder {
|
|
8
5
|
compileInsert() {
|
|
9
6
|
if (!this.options.data) {
|
|
10
7
|
throw new Error('No data provided');
|
|
@@ -27,14 +24,14 @@ class MySqlNativeQueryBuilder extends NativeQueryBuilder_1.NativeQueryBuilder {
|
|
|
27
24
|
return;
|
|
28
25
|
}
|
|
29
26
|
const map = {
|
|
30
|
-
[
|
|
31
|
-
[
|
|
32
|
-
[
|
|
33
|
-
[
|
|
34
|
-
[
|
|
35
|
-
[
|
|
27
|
+
[LockMode.PESSIMISTIC_READ]: 'lock in share mode',
|
|
28
|
+
[LockMode.PESSIMISTIC_WRITE]: 'for update',
|
|
29
|
+
[LockMode.PESSIMISTIC_PARTIAL_WRITE]: 'for update skip locked',
|
|
30
|
+
[LockMode.PESSIMISTIC_WRITE_OR_FAIL]: 'for update nowait',
|
|
31
|
+
[LockMode.PESSIMISTIC_PARTIAL_READ]: 'lock in share mode skip locked',
|
|
32
|
+
[LockMode.PESSIMISTIC_READ_OR_FAIL]: 'lock in share mode nowait',
|
|
36
33
|
};
|
|
37
|
-
if (this.options.lockMode !==
|
|
34
|
+
if (this.options.lockMode !== LockMode.OPTIMISTIC) {
|
|
38
35
|
this.parts.push(map[this.options.lockMode]);
|
|
39
36
|
}
|
|
40
37
|
}
|
|
@@ -45,7 +42,7 @@ class MySqlNativeQueryBuilder extends NativeQueryBuilder_1.NativeQueryBuilder {
|
|
|
45
42
|
}
|
|
46
43
|
if (clause.merge) {
|
|
47
44
|
this.parts.push('on duplicate key update');
|
|
48
|
-
if (
|
|
45
|
+
if (Utils.isObject(clause.merge)) {
|
|
49
46
|
const fields = Object.keys(clause.merge).map(field => {
|
|
50
47
|
this.params.push(clause.merge[field]);
|
|
51
48
|
return `${this.quote(field)} = ?`;
|
|
@@ -53,7 +50,7 @@ class MySqlNativeQueryBuilder extends NativeQueryBuilder_1.NativeQueryBuilder {
|
|
|
53
50
|
this.parts.push(fields.join(', '));
|
|
54
51
|
}
|
|
55
52
|
else if (clause.merge.length === 0) {
|
|
56
|
-
const dataAsArray =
|
|
53
|
+
const dataAsArray = Utils.asArray(this.options.data);
|
|
57
54
|
const keys = Object.keys(dataAsArray[0]);
|
|
58
55
|
this.parts.push(keys.map(key => `${this.quote(key)} = values(${this.quote(key)})`).join(', '));
|
|
59
56
|
}
|
|
@@ -68,7 +65,7 @@ class MySqlNativeQueryBuilder extends NativeQueryBuilder_1.NativeQueryBuilder {
|
|
|
68
65
|
return;
|
|
69
66
|
}
|
|
70
67
|
this.parts.push('on conflict');
|
|
71
|
-
if (clause.fields instanceof
|
|
68
|
+
if (clause.fields instanceof RawQueryFragment) {
|
|
72
69
|
this.parts.push(clause.fields.sql);
|
|
73
70
|
this.params.push(...clause.fields.params);
|
|
74
71
|
}
|
|
@@ -78,4 +75,3 @@ class MySqlNativeQueryBuilder extends NativeQueryBuilder_1.NativeQueryBuilder {
|
|
|
78
75
|
}
|
|
79
76
|
}
|
|
80
77
|
}
|
|
81
|
-
exports.MySqlNativeQueryBuilder = MySqlNativeQueryBuilder;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type SimpleColumnMeta, type Type, type TransformContext, type IsolationLevel } from '@mikro-orm/core';
|
|
2
|
-
import { MySqlSchemaHelper } from './MySqlSchemaHelper';
|
|
3
|
-
import { MySqlExceptionConverter } from './MySqlExceptionConverter';
|
|
4
|
-
import { AbstractSqlPlatform } from '../../AbstractSqlPlatform';
|
|
5
|
-
import type { IndexDef } from '../../typings';
|
|
6
|
-
import { MySqlNativeQueryBuilder } from './MySqlNativeQueryBuilder';
|
|
2
|
+
import { MySqlSchemaHelper } from './MySqlSchemaHelper.js';
|
|
3
|
+
import { MySqlExceptionConverter } from './MySqlExceptionConverter.js';
|
|
4
|
+
import { AbstractSqlPlatform } from '../../AbstractSqlPlatform.js';
|
|
5
|
+
import type { IndexDef } from '../../typings.js';
|
|
6
|
+
import { MySqlNativeQueryBuilder } from './MySqlNativeQueryBuilder.js';
|
|
7
7
|
export declare class MySqlPlatform extends AbstractSqlPlatform {
|
|
8
8
|
protected readonly schemaHelper: MySqlSchemaHelper;
|
|
9
9
|
protected readonly exceptionConverter: MySqlExceptionConverter;
|