@mikro-orm/mssql 7.0.7-dev.9 → 7.0.8-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/MsSqlSchemaHelper.d.ts +8 -8
- package/MsSqlSchemaHelper.js +17 -17
- package/package.json +5 -5
package/MsSqlSchemaHelper.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AbstractSqlConnection, type CheckDef, type Column, type DatabaseSchema, type DatabaseTable, type Dictionary, type ForeignKey, type IndexDef, SchemaHelper, type Table, type TableDifference, type Type } from '@mikro-orm/sql';
|
|
1
|
+
import { type AbstractSqlConnection, type CheckDef, type Column, type DatabaseSchema, type DatabaseTable, type Dictionary, type ForeignKey, type IndexDef, SchemaHelper, type Table, type TableDifference, type Transaction, type Type } from '@mikro-orm/sql';
|
|
2
2
|
/** Schema introspection helper for Microsoft SQL Server. */
|
|
3
3
|
export declare class MsSqlSchemaHelper extends SchemaHelper {
|
|
4
4
|
static readonly DEFAULT_VALUES: {
|
|
@@ -13,17 +13,17 @@ export declare class MsSqlSchemaHelper extends SchemaHelper {
|
|
|
13
13
|
getDatabaseExistsSQL(name: string): string;
|
|
14
14
|
getListTablesSQL(): string;
|
|
15
15
|
getListViewsSQL(): string;
|
|
16
|
-
loadViews(schema: DatabaseSchema, connection: AbstractSqlConnection): Promise<void>;
|
|
17
|
-
getNamespaces(connection: AbstractSqlConnection): Promise<string[]>;
|
|
16
|
+
loadViews(schema: DatabaseSchema, connection: AbstractSqlConnection, schemaName?: string, ctx?: Transaction): Promise<void>;
|
|
17
|
+
getNamespaces(connection: AbstractSqlConnection, ctx?: Transaction): Promise<string[]>;
|
|
18
18
|
normalizeDefaultValue(defaultValue: string, length: number, defaultValues?: Dictionary<string[]>, stripQuotes?: boolean): string | number;
|
|
19
|
-
getAllColumns(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]
|
|
20
|
-
getAllIndexes(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]
|
|
19
|
+
getAllColumns(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>, ctx?: Transaction): Promise<Dictionary<Column[]>>;
|
|
20
|
+
getAllIndexes(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>, ctx?: Transaction): Promise<Dictionary<IndexDef[]>>;
|
|
21
21
|
mapForeignKeys(fks: any[], tableName: string, schemaName?: string): Dictionary;
|
|
22
|
-
getAllForeignKeys(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]
|
|
22
|
+
getAllForeignKeys(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>, ctx?: Transaction): Promise<Dictionary<Dictionary<ForeignKey>>>;
|
|
23
23
|
private getEnumDefinitions;
|
|
24
24
|
private getChecksSQL;
|
|
25
|
-
getAllChecks(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]
|
|
26
|
-
loadInformationSchema(schema: DatabaseSchema, connection: AbstractSqlConnection, tables: Table[]): Promise<void>;
|
|
25
|
+
getAllChecks(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>, ctx?: Transaction): Promise<Dictionary<CheckDef[]>>;
|
|
26
|
+
loadInformationSchema(schema: DatabaseSchema, connection: AbstractSqlConnection, tables: Table[], schemas?: string[], ctx?: Transaction): Promise<void>;
|
|
27
27
|
getPreAlterTable(tableDiff: TableDifference, safe: boolean): string[];
|
|
28
28
|
getPostAlterTable(tableDiff: TableDifference, safe: boolean): string[];
|
|
29
29
|
getCreateNamespaceSQL(name: string): string;
|
package/MsSqlSchemaHelper.js
CHANGED
|
@@ -36,8 +36,8 @@ export class MsSqlSchemaHelper extends SchemaHelper {
|
|
|
36
36
|
inner join sys.sql_modules m on v.object_id = m.object_id
|
|
37
37
|
order by schema_name(v.schema_id), v.name`;
|
|
38
38
|
}
|
|
39
|
-
async loadViews(schema, connection) {
|
|
40
|
-
const views = await connection.execute(this.getListViewsSQL());
|
|
39
|
+
async loadViews(schema, connection, schemaName, ctx) {
|
|
40
|
+
const views = await connection.execute(this.getListViewsSQL(), [], 'all', ctx);
|
|
41
41
|
for (const view of views) {
|
|
42
42
|
// Extract SELECT statement from CREATE VIEW ... AS SELECT ...
|
|
43
43
|
const match = /\bAS\s+(.+)$/is.exec(view.view_definition);
|
|
@@ -48,9 +48,9 @@ export class MsSqlSchemaHelper extends SchemaHelper {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
async getNamespaces(connection) {
|
|
51
|
+
async getNamespaces(connection, ctx) {
|
|
52
52
|
const sql = `select name as schema_name from sys.schemas order by name`;
|
|
53
|
-
const res = await connection.execute(sql);
|
|
53
|
+
const res = await connection.execute(sql, [], 'all', ctx);
|
|
54
54
|
return res.map(row => row.schema_name);
|
|
55
55
|
}
|
|
56
56
|
normalizeDefaultValue(defaultValue, length, defaultValues = {}, stripQuotes = false) {
|
|
@@ -68,7 +68,7 @@ export class MsSqlSchemaHelper extends SchemaHelper {
|
|
|
68
68
|
}
|
|
69
69
|
return super.normalizeDefaultValue(defaultValue, length, MsSqlSchemaHelper.DEFAULT_VALUES);
|
|
70
70
|
}
|
|
71
|
-
async getAllColumns(connection, tablesBySchemas) {
|
|
71
|
+
async getAllColumns(connection, tablesBySchemas, ctx) {
|
|
72
72
|
const sql = `select table_name as table_name,
|
|
73
73
|
table_schema as schema_name,
|
|
74
74
|
column_name as column_name,
|
|
@@ -91,7 +91,7 @@ export class MsSqlSchemaHelper extends SchemaHelper {
|
|
|
91
91
|
left join sys.default_constraints t5 on sc.default_object_id = t5.object_id
|
|
92
92
|
where (${[...tablesBySchemas.entries()].map(([schema, tables]) => `(ic.table_name in (${tables.map(t => this.platform.quoteValue(t.table_name)).join(',')}) and ic.table_schema = '${schema}')`).join(' or ')})
|
|
93
93
|
order by ordinal_position`;
|
|
94
|
-
const allColumns = await connection.execute(sql);
|
|
94
|
+
const allColumns = await connection.execute(sql, [], 'all', ctx);
|
|
95
95
|
const str = (val) => (val != null ? '' + val : val);
|
|
96
96
|
const ret = {};
|
|
97
97
|
for (const col of allColumns) {
|
|
@@ -140,7 +140,7 @@ export class MsSqlSchemaHelper extends SchemaHelper {
|
|
|
140
140
|
}
|
|
141
141
|
return ret;
|
|
142
142
|
}
|
|
143
|
-
async getAllIndexes(connection, tablesBySchemas) {
|
|
143
|
+
async getAllIndexes(connection, tablesBySchemas, ctx) {
|
|
144
144
|
const sql = `select t.name as table_name,
|
|
145
145
|
ind.name as index_name,
|
|
146
146
|
is_unique as is_unique,
|
|
@@ -160,7 +160,7 @@ export class MsSqlSchemaHelper extends SchemaHelper {
|
|
|
160
160
|
where
|
|
161
161
|
(${[...tablesBySchemas.entries()].map(([schema, tables]) => `(t.name in (${tables.map(t => this.platform.quoteValue(t.table_name)).join(',')}) and schema_name(t.schema_id) = '${schema}')`).join(' OR ')})
|
|
162
162
|
order by t.name, ind.name, ic.is_included_column, ic.key_ordinal`;
|
|
163
|
-
const allIndexes = await connection.execute(sql);
|
|
163
|
+
const allIndexes = await connection.execute(sql, [], 'all', ctx);
|
|
164
164
|
const ret = {};
|
|
165
165
|
for (const index of allIndexes) {
|
|
166
166
|
const key = this.getTableKey(index);
|
|
@@ -212,7 +212,7 @@ export class MsSqlSchemaHelper extends SchemaHelper {
|
|
|
212
212
|
}
|
|
213
213
|
return ret;
|
|
214
214
|
}
|
|
215
|
-
async getAllForeignKeys(connection, tablesBySchemas) {
|
|
215
|
+
async getAllForeignKeys(connection, tablesBySchemas, ctx) {
|
|
216
216
|
const sql = `select ccu.constraint_name, ccu.table_name, ccu.table_schema schema_name, ccu.column_name,
|
|
217
217
|
kcu.constraint_schema referenced_schema_name,
|
|
218
218
|
kcu.column_name referenced_column_name,
|
|
@@ -224,7 +224,7 @@ export class MsSqlSchemaHelper extends SchemaHelper {
|
|
|
224
224
|
inner join information_schema.key_column_usage kcu on kcu.constraint_name = rc.unique_constraint_name and rc.unique_constraint_schema = kcu.constraint_schema
|
|
225
225
|
where (${[...tablesBySchemas.entries()].map(([schema, tables]) => `(ccu.table_name in (${tables.map(t => this.platform.quoteValue(t.table_name)).join(',')}) and ccu.table_schema = '${schema}')`).join(' or ')})
|
|
226
226
|
order by kcu.table_schema, kcu.table_name, kcu.ordinal_position, kcu.constraint_name`;
|
|
227
|
-
const allFks = await connection.execute(sql);
|
|
227
|
+
const allFks = await connection.execute(sql, [], 'all', ctx);
|
|
228
228
|
const ret = {};
|
|
229
229
|
for (const fk of allFks) {
|
|
230
230
|
const key = this.getTableKey(fk);
|
|
@@ -268,9 +268,9 @@ export class MsSqlSchemaHelper extends SchemaHelper {
|
|
|
268
268
|
where (${[...tablesBySchemas.entries()].map(([schema, tables]) => `t.name in (${tables.map(t => this.platform.quoteValue(t.table_name)).join(',')}) and schema_name(t.schema_id) = '${schema}'`).join(' or ')})
|
|
269
269
|
order by con.name`;
|
|
270
270
|
}
|
|
271
|
-
async getAllChecks(connection, tablesBySchemas) {
|
|
271
|
+
async getAllChecks(connection, tablesBySchemas, ctx) {
|
|
272
272
|
const sql = this.getChecksSQL(tablesBySchemas);
|
|
273
|
-
const allChecks = await connection.execute(sql);
|
|
273
|
+
const allChecks = await connection.execute(sql, [], 'all', ctx);
|
|
274
274
|
const ret = {};
|
|
275
275
|
for (const check of allChecks) {
|
|
276
276
|
const key = this.getTableKey(check);
|
|
@@ -285,15 +285,15 @@ export class MsSqlSchemaHelper extends SchemaHelper {
|
|
|
285
285
|
}
|
|
286
286
|
return ret;
|
|
287
287
|
}
|
|
288
|
-
async loadInformationSchema(schema, connection, tables) {
|
|
288
|
+
async loadInformationSchema(schema, connection, tables, schemas, ctx) {
|
|
289
289
|
if (tables.length === 0) {
|
|
290
290
|
return;
|
|
291
291
|
}
|
|
292
292
|
const tablesBySchema = this.getTablesGroupedBySchemas(tables);
|
|
293
|
-
const columns = await this.getAllColumns(connection, tablesBySchema);
|
|
294
|
-
const indexes = await this.getAllIndexes(connection, tablesBySchema);
|
|
295
|
-
const checks = await this.getAllChecks(connection, tablesBySchema);
|
|
296
|
-
const fks = await this.getAllForeignKeys(connection, tablesBySchema);
|
|
293
|
+
const columns = await this.getAllColumns(connection, tablesBySchema, ctx);
|
|
294
|
+
const indexes = await this.getAllIndexes(connection, tablesBySchema, ctx);
|
|
295
|
+
const checks = await this.getAllChecks(connection, tablesBySchema, ctx);
|
|
296
|
+
const fks = await this.getAllForeignKeys(connection, tablesBySchema, ctx);
|
|
297
297
|
for (const t of tables) {
|
|
298
298
|
const key = this.getTableKey(t);
|
|
299
299
|
const table = schema.addTable(t.table_name, t.schema_name, t.table_comment);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/mssql",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.8-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.0.
|
|
51
|
-
"kysely": "0.28.
|
|
50
|
+
"@mikro-orm/sql": "7.0.8-dev.0",
|
|
51
|
+
"kysely": "0.28.15",
|
|
52
52
|
"tarn": "3.0.2",
|
|
53
53
|
"tedious": "19.2.1",
|
|
54
54
|
"tsqlstring": "1.0.1"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@mikro-orm/core": "^7.0.
|
|
57
|
+
"@mikro-orm/core": "^7.0.7"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"@mikro-orm/core": "7.0.
|
|
60
|
+
"@mikro-orm/core": "7.0.8-dev.0"
|
|
61
61
|
},
|
|
62
62
|
"engines": {
|
|
63
63
|
"node": ">= 22.17.0"
|