@mikro-orm/mssql 7.3.0-dev.17 → 7.3.0-dev.19
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/MsSqlConnection.js +3 -0
- package/MsSqlDriver.js +3 -10
- package/MsSqlPlatform.d.ts +2 -1
- package/MsSqlPlatform.js +5 -1
- package/MsSqlSchemaHelper.d.ts +0 -1
- package/MsSqlSchemaHelper.js +21 -23
- package/package.json +6 -6
package/MsSqlConnection.js
CHANGED
|
@@ -138,6 +138,9 @@ export class MsSqlConnection extends AbstractSqlConnection {
|
|
|
138
138
|
}
|
|
139
139
|
async commit(ctx, eventBroadcaster) {
|
|
140
140
|
if ('savepointName' in ctx) {
|
|
141
|
+
if (!ctx.isRolledBack && 'failedSavepointRollback' in ctx) {
|
|
142
|
+
throw ctx.failedSavepointRollback;
|
|
143
|
+
}
|
|
141
144
|
return;
|
|
142
145
|
}
|
|
143
146
|
return super.commit(ctx, eventBroadcaster);
|
package/MsSqlDriver.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { QueryFlag, Utils,
|
|
1
|
+
import { QueryFlag, Utils, } from '@mikro-orm/core';
|
|
2
2
|
import { AbstractSqlDriver } from '@mikro-orm/sql';
|
|
3
3
|
import { MsSqlConnection } from './MsSqlConnection.js';
|
|
4
4
|
import { MsSqlPlatform } from './MsSqlPlatform.js';
|
|
@@ -31,20 +31,13 @@ export class MsSqlDriver extends AbstractSqlDriver {
|
|
|
31
31
|
sql = this.appendOutputTable(entityName, returningFields, sql, sql.length - 1, options);
|
|
32
32
|
}
|
|
33
33
|
const res = await this.execute(sql, [], 'run', options.ctx);
|
|
34
|
-
|
|
35
|
-
if (pks.length === 1) {
|
|
36
|
-
res.row ??= {};
|
|
37
|
-
res.rows ??= [];
|
|
38
|
-
res.insertId = res.insertId || res.row[pks[0]];
|
|
39
|
-
}
|
|
34
|
+
this.resolveInsertedPrimaryKeys(meta, data, res);
|
|
40
35
|
return res;
|
|
41
36
|
}
|
|
42
37
|
return super.nativeInsertMany(entityName, data, options, sql => {
|
|
43
38
|
if (meta.hasTriggers) {
|
|
44
39
|
// must match the OUTPUT columns of the parent implementation, which resolves STI children to the root
|
|
45
|
-
const returning = this.
|
|
46
|
-
(((prop.persist !== false && prop.defaultRaw) || prop.autoincrement || prop.generated) &&
|
|
47
|
-
(!(prop.name in data[0]) || isRaw(data[0][prop.name]))));
|
|
40
|
+
const returning = this.getInsertReturningProperties(meta.inheritanceType === 'tpt' ? meta : meta.root, data);
|
|
48
41
|
sql = this.appendOutputTable(entityName, returning.flatMap(p => p.fieldNames), sql, sql.indexOf(' values '), options);
|
|
49
42
|
}
|
|
50
43
|
// For TPT children, the parent table owns the identity column.
|
package/MsSqlPlatform.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbstractSqlPlatform, type EntityManager, type EntityMetadata, type IDatabaseDriver, type IPrimaryKey, type MikroORM, MsSqlNativeQueryBuilder, type Primary, QueryOrder, RawQueryFragment, Type } from '@mikro-orm/sql';
|
|
1
|
+
import { AbstractSqlPlatform, type EntityManager, type EntityMetadata, type IDatabaseDriver, type IPrimaryKey, type MikroORM, MsSqlNativeQueryBuilder, type Primary, QueryOrder, RawQueryFragment, type TransformContext, Type } from '@mikro-orm/sql';
|
|
2
2
|
import { MsSqlSchemaHelper } from './MsSqlSchemaHelper.js';
|
|
3
3
|
import { MsSqlExceptionConverter } from './MsSqlExceptionConverter.js';
|
|
4
4
|
import { MsSqlSchemaGenerator } from './MsSqlSchemaGenerator.js';
|
|
@@ -22,6 +22,7 @@ export declare class MsSqlPlatform extends AbstractSqlPlatform {
|
|
|
22
22
|
usesOutputStatement(): boolean;
|
|
23
23
|
convertDateToJSValue(value: string | Date): string;
|
|
24
24
|
convertsJsonAutomatically(): boolean;
|
|
25
|
+
convertJsonToDatabaseValue(value: unknown, context?: TransformContext): unknown;
|
|
25
26
|
indexForeignKeys(): boolean;
|
|
26
27
|
/** SQL Server identifier limit (sysname). */
|
|
27
28
|
getMaxIdentifierLength(): number;
|
package/MsSqlPlatform.js
CHANGED
|
@@ -47,7 +47,6 @@ export class MsSqlPlatform extends AbstractSqlPlatform {
|
|
|
47
47
|
return true;
|
|
48
48
|
}
|
|
49
49
|
convertDateToJSValue(value) {
|
|
50
|
-
/* v8 ignore next */
|
|
51
50
|
if (typeof value === 'string') {
|
|
52
51
|
return value;
|
|
53
52
|
}
|
|
@@ -56,6 +55,11 @@ export class MsSqlPlatform extends AbstractSqlPlatform {
|
|
|
56
55
|
convertsJsonAutomatically() {
|
|
57
56
|
return false;
|
|
58
57
|
}
|
|
58
|
+
convertJsonToDatabaseValue(value, context) {
|
|
59
|
+
const json = super.convertJsonToDatabaseValue(value, context);
|
|
60
|
+
// JSON is stored in `nvarchar(max)`, so write it as a Unicode literal, otherwise non-Latin characters are lost
|
|
61
|
+
return context?.mode === 'hydration' || context?.mode === 'discovery' ? json : new UnicodeString(json);
|
|
62
|
+
}
|
|
59
63
|
indexForeignKeys() {
|
|
60
64
|
return false;
|
|
61
65
|
}
|
package/MsSqlSchemaHelper.d.ts
CHANGED
|
@@ -24,7 +24,6 @@ export declare class MsSqlSchemaHelper extends SchemaHelper {
|
|
|
24
24
|
normalizeDefaultValue(defaultValue: string, length: number, defaultValues?: Dictionary<string[]>, stripQuotes?: boolean): string | number;
|
|
25
25
|
getAllColumns(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>, ctx?: Transaction): Promise<Dictionary<Column[]>>;
|
|
26
26
|
getAllIndexes(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>, ctx?: Transaction): Promise<Dictionary<IndexDef[]>>;
|
|
27
|
-
mapForeignKeys(fks: any[], tableName: string, schemaName?: string): Dictionary;
|
|
28
27
|
getAllForeignKeys(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>, ctx?: Transaction): Promise<Dictionary<Dictionary<ForeignKey>>>;
|
|
29
28
|
private getEnumDefinitions;
|
|
30
29
|
private getChecksSQL;
|
package/MsSqlSchemaHelper.js
CHANGED
|
@@ -93,17 +93,17 @@ export class MsSqlSchemaHelper extends SchemaHelper {
|
|
|
93
93
|
return res.map(row => row.schema_name);
|
|
94
94
|
}
|
|
95
95
|
normalizeDefaultValue(defaultValue, length, defaultValues = {}, stripQuotes = false) {
|
|
96
|
-
let match = /^\((.*)\)
|
|
96
|
+
let match = /^\((.*)\)$/s.exec(defaultValue);
|
|
97
97
|
if (match) {
|
|
98
98
|
defaultValue = match[1];
|
|
99
99
|
}
|
|
100
|
-
match = /^\((.*)\)
|
|
100
|
+
match = /^\((.*)\)$/s.exec(defaultValue);
|
|
101
101
|
if (match) {
|
|
102
102
|
defaultValue = match[1];
|
|
103
103
|
}
|
|
104
|
-
match = /^'(.*)'
|
|
104
|
+
match = /^'(.*)'$/s.exec(defaultValue);
|
|
105
105
|
if (stripQuotes && match) {
|
|
106
|
-
defaultValue = match[1];
|
|
106
|
+
defaultValue = match[1].replaceAll("''", "'");
|
|
107
107
|
}
|
|
108
108
|
return super.normalizeDefaultValue(defaultValue, length, MsSqlSchemaHelper.DEFAULT_VALUES);
|
|
109
109
|
}
|
|
@@ -266,26 +266,24 @@ export class MsSqlSchemaHelper extends SchemaHelper {
|
|
|
266
266
|
}
|
|
267
267
|
return ret;
|
|
268
268
|
}
|
|
269
|
-
mapForeignKeys(fks, tableName, schemaName) {
|
|
270
|
-
const ret = super.mapForeignKeys(fks, tableName, schemaName);
|
|
271
|
-
for (const fk of Utils.values(ret)) {
|
|
272
|
-
fk.columnNames = Utils.unique(fk.columnNames);
|
|
273
|
-
fk.referencedColumnNames = Utils.unique(fk.referencedColumnNames);
|
|
274
|
-
}
|
|
275
|
-
return ret;
|
|
276
|
-
}
|
|
277
269
|
async getAllForeignKeys(connection, tablesBySchemas, ctx) {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
inner join
|
|
287
|
-
|
|
288
|
-
|
|
270
|
+
// `sys.foreign_key_columns` pairs local and referenced columns of composite FKs, `information_schema` can't
|
|
271
|
+
const sql = `select fk.name constraint_name, t.name table_name, s.name schema_name, c.name column_name,
|
|
272
|
+
rs.name referenced_schema_name,
|
|
273
|
+
rc.name referenced_column_name,
|
|
274
|
+
rt.name referenced_table_name,
|
|
275
|
+
replace(fk.update_referential_action_desc, '_', ' ') update_rule,
|
|
276
|
+
replace(fk.delete_referential_action_desc, '_', ' ') delete_rule
|
|
277
|
+
from sys.foreign_keys fk
|
|
278
|
+
inner join sys.foreign_key_columns fkc on fkc.constraint_object_id = fk.object_id
|
|
279
|
+
inner join sys.tables t on t.object_id = fk.parent_object_id
|
|
280
|
+
inner join sys.schemas s on s.schema_id = t.schema_id
|
|
281
|
+
inner join sys.columns c on c.object_id = fkc.parent_object_id and c.column_id = fkc.parent_column_id
|
|
282
|
+
inner join sys.tables rt on rt.object_id = fk.referenced_object_id
|
|
283
|
+
inner join sys.schemas rs on rs.schema_id = rt.schema_id
|
|
284
|
+
inner join sys.columns rc on rc.object_id = fkc.referenced_object_id and rc.column_id = fkc.referenced_column_id
|
|
285
|
+
where (${[...tablesBySchemas.entries()].map(([schema, tables]) => `(t.name in (${tables.map(t => this.platform.quoteValue(t.table_name)).join(',')}) and s.name = '${schema}')`).join(' or ')})
|
|
286
|
+
order by rs.name, rt.name, fkc.constraint_column_id, fk.name`;
|
|
289
287
|
const allFks = await connection.execute(sql, [], 'all', ctx);
|
|
290
288
|
const ret = {};
|
|
291
289
|
for (const fk of allFks) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/mssql",
|
|
3
|
-
"version": "7.3.0-dev.
|
|
3
|
+
"version": "7.3.0-dev.19",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
|
@@ -47,17 +47,17 @@
|
|
|
47
47
|
"copy": "node ../../scripts/copy.mjs"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@mikro-orm/sql": "7.3.0-dev.
|
|
51
|
-
"kysely": "0.29.
|
|
50
|
+
"@mikro-orm/sql": "7.3.0-dev.19",
|
|
51
|
+
"kysely": "0.29.8",
|
|
52
52
|
"tarn": "3.1.2",
|
|
53
|
-
"tedious": "20.
|
|
53
|
+
"tedious": "20.3.8",
|
|
54
54
|
"tsqlstring": "1.0.1"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@mikro-orm/core": "^7.2.
|
|
57
|
+
"@mikro-orm/core": "^7.2.6"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"@mikro-orm/core": "7.3.0-dev.
|
|
60
|
+
"@mikro-orm/core": "7.3.0-dev.19"
|
|
61
61
|
},
|
|
62
62
|
"engines": {
|
|
63
63
|
"node": ">= 22.17.0"
|