@mikro-orm/mssql 7.2.6-dev.9 → 7.2.7-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MsSqlConnection.js +3 -0
- 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/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
|
@@ -20,7 +20,6 @@ export declare class MsSqlSchemaHelper extends SchemaHelper {
|
|
|
20
20
|
normalizeDefaultValue(defaultValue: string, length: number, defaultValues?: Dictionary<string[]>, stripQuotes?: boolean): string | number;
|
|
21
21
|
getAllColumns(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>, ctx?: Transaction): Promise<Dictionary<Column[]>>;
|
|
22
22
|
getAllIndexes(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>, ctx?: Transaction): Promise<Dictionary<IndexDef[]>>;
|
|
23
|
-
mapForeignKeys(fks: any[], tableName: string, schemaName?: string): Dictionary;
|
|
24
23
|
getAllForeignKeys(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>, ctx?: Transaction): Promise<Dictionary<Dictionary<ForeignKey>>>;
|
|
25
24
|
private getEnumDefinitions;
|
|
26
25
|
private getChecksSQL;
|
package/MsSqlSchemaHelper.js
CHANGED
|
@@ -85,17 +85,17 @@ export class MsSqlSchemaHelper extends SchemaHelper {
|
|
|
85
85
|
return res.map(row => row.schema_name);
|
|
86
86
|
}
|
|
87
87
|
normalizeDefaultValue(defaultValue, length, defaultValues = {}, stripQuotes = false) {
|
|
88
|
-
let match = /^\((.*)\)
|
|
88
|
+
let match = /^\((.*)\)$/s.exec(defaultValue);
|
|
89
89
|
if (match) {
|
|
90
90
|
defaultValue = match[1];
|
|
91
91
|
}
|
|
92
|
-
match = /^\((.*)\)
|
|
92
|
+
match = /^\((.*)\)$/s.exec(defaultValue);
|
|
93
93
|
if (match) {
|
|
94
94
|
defaultValue = match[1];
|
|
95
95
|
}
|
|
96
|
-
match = /^'(.*)'
|
|
96
|
+
match = /^'(.*)'$/s.exec(defaultValue);
|
|
97
97
|
if (stripQuotes && match) {
|
|
98
|
-
defaultValue = match[1];
|
|
98
|
+
defaultValue = match[1].replaceAll("''", "'");
|
|
99
99
|
}
|
|
100
100
|
return super.normalizeDefaultValue(defaultValue, length, MsSqlSchemaHelper.DEFAULT_VALUES);
|
|
101
101
|
}
|
|
@@ -254,26 +254,24 @@ export class MsSqlSchemaHelper extends SchemaHelper {
|
|
|
254
254
|
}
|
|
255
255
|
return ret;
|
|
256
256
|
}
|
|
257
|
-
mapForeignKeys(fks, tableName, schemaName) {
|
|
258
|
-
const ret = super.mapForeignKeys(fks, tableName, schemaName);
|
|
259
|
-
for (const fk of Utils.values(ret)) {
|
|
260
|
-
fk.columnNames = Utils.unique(fk.columnNames);
|
|
261
|
-
fk.referencedColumnNames = Utils.unique(fk.referencedColumnNames);
|
|
262
|
-
}
|
|
263
|
-
return ret;
|
|
264
|
-
}
|
|
265
257
|
async getAllForeignKeys(connection, tablesBySchemas, ctx) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
inner join
|
|
275
|
-
|
|
276
|
-
|
|
258
|
+
// `sys.foreign_key_columns` pairs local and referenced columns of composite FKs, `information_schema` can't
|
|
259
|
+
const sql = `select fk.name constraint_name, t.name table_name, s.name schema_name, c.name column_name,
|
|
260
|
+
rs.name referenced_schema_name,
|
|
261
|
+
rc.name referenced_column_name,
|
|
262
|
+
rt.name referenced_table_name,
|
|
263
|
+
replace(fk.update_referential_action_desc, '_', ' ') update_rule,
|
|
264
|
+
replace(fk.delete_referential_action_desc, '_', ' ') delete_rule
|
|
265
|
+
from sys.foreign_keys fk
|
|
266
|
+
inner join sys.foreign_key_columns fkc on fkc.constraint_object_id = fk.object_id
|
|
267
|
+
inner join sys.tables t on t.object_id = fk.parent_object_id
|
|
268
|
+
inner join sys.schemas s on s.schema_id = t.schema_id
|
|
269
|
+
inner join sys.columns c on c.object_id = fkc.parent_object_id and c.column_id = fkc.parent_column_id
|
|
270
|
+
inner join sys.tables rt on rt.object_id = fk.referenced_object_id
|
|
271
|
+
inner join sys.schemas rs on rs.schema_id = rt.schema_id
|
|
272
|
+
inner join sys.columns rc on rc.object_id = fkc.referenced_object_id and rc.column_id = fkc.referenced_column_id
|
|
273
|
+
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 ')})
|
|
274
|
+
order by rs.name, rt.name, fkc.constraint_column_id, fk.name`;
|
|
277
275
|
const allFks = await connection.execute(sql, [], 'all', ctx);
|
|
278
276
|
const ret = {};
|
|
279
277
|
for (const fk of allFks) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/mssql",
|
|
3
|
-
"version": "7.2.
|
|
3
|
+
"version": "7.2.7-dev.0",
|
|
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.2.
|
|
51
|
-
"kysely": "0.29.
|
|
50
|
+
"@mikro-orm/sql": "7.2.7-dev.0",
|
|
51
|
+
"kysely": "0.29.7",
|
|
52
52
|
"tarn": "3.1.2",
|
|
53
|
-
"tedious": "20.3.
|
|
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.2.
|
|
60
|
+
"@mikro-orm/core": "7.2.7-dev.0"
|
|
61
61
|
},
|
|
62
62
|
"engines": {
|
|
63
63
|
"node": ">= 22.17.0"
|