@mikro-orm/mssql 6.6.11-dev.0 → 6.6.11-dev.2
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 +7 -6
- package/MsSqlSchemaHelper.js +15 -15
- package/package.json +3 -3
package/MsSqlSchemaHelper.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type AbstractSqlConnection, type CheckDef, type Column, type DatabaseSchema, type DatabaseTable, type Dictionary, type ForeignKey, type IndexDef, type Knex, SchemaHelper, type Table, type TableDifference, type Type } from '@mikro-orm/knex';
|
|
2
|
+
import type { Transaction } from '@mikro-orm/core';
|
|
2
3
|
export declare class MsSqlSchemaHelper extends SchemaHelper {
|
|
3
4
|
static readonly DEFAULT_VALUES: {
|
|
4
5
|
true: string[];
|
|
@@ -10,16 +11,16 @@ export declare class MsSqlSchemaHelper extends SchemaHelper {
|
|
|
10
11
|
enableForeignKeysSQL(): string;
|
|
11
12
|
getDatabaseExistsSQL(name: string): string;
|
|
12
13
|
getListTablesSQL(): string;
|
|
13
|
-
getNamespaces(connection: AbstractSqlConnection): Promise<string[]>;
|
|
14
|
+
getNamespaces(connection: AbstractSqlConnection, ctx?: Transaction): Promise<string[]>;
|
|
14
15
|
normalizeDefaultValue(defaultValue: string, length: number, defaultValues?: Dictionary<string[]>, stripQuotes?: boolean): string | number;
|
|
15
|
-
getAllColumns(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]
|
|
16
|
-
getAllIndexes(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]
|
|
16
|
+
getAllColumns(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>, ctx?: Transaction): Promise<Dictionary<Column[]>>;
|
|
17
|
+
getAllIndexes(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>, ctx?: Transaction): Promise<Dictionary<IndexDef[]>>;
|
|
17
18
|
mapForeignKeys(fks: any[], tableName: string, schemaName?: string): Dictionary;
|
|
18
|
-
getAllForeignKeys(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]
|
|
19
|
+
getAllForeignKeys(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>, ctx?: Transaction): Promise<Dictionary<Dictionary<ForeignKey>>>;
|
|
19
20
|
getEnumDefinitions(connection: AbstractSqlConnection, checks: CheckDef[], tableName?: string, schemaName?: string): Promise<Dictionary<string[]>>;
|
|
20
21
|
private getChecksSQL;
|
|
21
|
-
getAllChecks(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]
|
|
22
|
-
loadInformationSchema(schema: DatabaseSchema, connection: AbstractSqlConnection, tables: Table[]): Promise<void>;
|
|
22
|
+
getAllChecks(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>, ctx?: Transaction): Promise<Dictionary<CheckDef[]>>;
|
|
23
|
+
loadInformationSchema(schema: DatabaseSchema, connection: AbstractSqlConnection, tables: Table[], schemas?: string[], ctx?: Transaction): Promise<void>;
|
|
23
24
|
getPreAlterTable(tableDiff: TableDifference, safe: boolean): string;
|
|
24
25
|
getPostAlterTable(tableDiff: TableDifference, safe: boolean): string;
|
|
25
26
|
getCreateNamespaceSQL(name: string): string;
|
package/MsSqlSchemaHelper.js
CHANGED
|
@@ -28,9 +28,9 @@ class MsSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
28
28
|
left join sys.extended_properties ep on ep.major_id = t.id and ep.name = 'MS_Description' and ep.minor_id = 0
|
|
29
29
|
order by schema_name(t2.schema_id), t.name`;
|
|
30
30
|
}
|
|
31
|
-
async getNamespaces(connection) {
|
|
31
|
+
async getNamespaces(connection, ctx) {
|
|
32
32
|
const sql = `select name as schema_name from sys.schemas order by name`;
|
|
33
|
-
const res = await connection.execute(sql);
|
|
33
|
+
const res = await connection.execute(sql, [], 'all', ctx);
|
|
34
34
|
return res.map(row => row.schema_name);
|
|
35
35
|
}
|
|
36
36
|
normalizeDefaultValue(defaultValue, length, defaultValues = {}, stripQuotes = false) {
|
|
@@ -48,7 +48,7 @@ class MsSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
48
48
|
}
|
|
49
49
|
return super.normalizeDefaultValue(defaultValue, length, MsSqlSchemaHelper.DEFAULT_VALUES);
|
|
50
50
|
}
|
|
51
|
-
async getAllColumns(connection, tablesBySchemas) {
|
|
51
|
+
async getAllColumns(connection, tablesBySchemas, ctx) {
|
|
52
52
|
const sql = `select table_name as table_name,
|
|
53
53
|
table_schema as schema_name,
|
|
54
54
|
column_name as column_name,
|
|
@@ -69,7 +69,7 @@ class MsSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
69
69
|
left join sys.extended_properties t4 on t4.major_id = object_id(ic.table_schema + '.' + ic.table_name) and t4.name = 'MS_Description' and t4.minor_id = sc.column_id
|
|
70
70
|
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 ')})
|
|
71
71
|
order by ordinal_position`;
|
|
72
|
-
const allColumns = await connection.execute(sql);
|
|
72
|
+
const allColumns = await connection.execute(sql, [], 'all', ctx);
|
|
73
73
|
const str = (val) => val != null ? '' + val : val;
|
|
74
74
|
const ret = {};
|
|
75
75
|
for (const col of allColumns) {
|
|
@@ -113,7 +113,7 @@ class MsSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
113
113
|
}
|
|
114
114
|
return ret;
|
|
115
115
|
}
|
|
116
|
-
async getAllIndexes(connection, tablesBySchemas) {
|
|
116
|
+
async getAllIndexes(connection, tablesBySchemas, ctx) {
|
|
117
117
|
const sql = `select t.name as table_name,
|
|
118
118
|
ind.name as index_name,
|
|
119
119
|
is_unique as is_unique,
|
|
@@ -128,7 +128,7 @@ class MsSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
128
128
|
where
|
|
129
129
|
(${[...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 ')})
|
|
130
130
|
order by t.name, ind.name, ind.index_id`;
|
|
131
|
-
const allIndexes = await connection.execute(sql);
|
|
131
|
+
const allIndexes = await connection.execute(sql, [], 'all', ctx);
|
|
132
132
|
const ret = {};
|
|
133
133
|
for (const index of allIndexes) {
|
|
134
134
|
const key = this.getTableKey(index);
|
|
@@ -159,7 +159,7 @@ class MsSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
159
159
|
}
|
|
160
160
|
return ret;
|
|
161
161
|
}
|
|
162
|
-
async getAllForeignKeys(connection, tablesBySchemas) {
|
|
162
|
+
async getAllForeignKeys(connection, tablesBySchemas, ctx) {
|
|
163
163
|
const sql = `select ccu.constraint_name, ccu.table_name, ccu.table_schema schema_name, ccu.column_name,
|
|
164
164
|
kcu.constraint_schema referenced_schema_name,
|
|
165
165
|
kcu.column_name referenced_column_name,
|
|
@@ -171,7 +171,7 @@ class MsSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
171
171
|
inner join information_schema.key_column_usage kcu on kcu.constraint_name = rc.unique_constraint_name and rc.unique_constraint_schema = kcu.constraint_schema
|
|
172
172
|
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 ')})
|
|
173
173
|
order by kcu.table_schema, kcu.table_name, kcu.ordinal_position, kcu.constraint_name`;
|
|
174
|
-
const allFks = await connection.execute(sql);
|
|
174
|
+
const allFks = await connection.execute(sql, [], 'all', ctx);
|
|
175
175
|
const ret = {};
|
|
176
176
|
for (const fk of allFks) {
|
|
177
177
|
const key = this.getTableKey(fk);
|
|
@@ -217,9 +217,9 @@ class MsSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
217
217
|
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 ')})
|
|
218
218
|
order by con.name`;
|
|
219
219
|
}
|
|
220
|
-
async getAllChecks(connection, tablesBySchemas) {
|
|
220
|
+
async getAllChecks(connection, tablesBySchemas, ctx) {
|
|
221
221
|
const sql = this.getChecksSQL(tablesBySchemas);
|
|
222
|
-
const allChecks = await connection.execute(sql);
|
|
222
|
+
const allChecks = await connection.execute(sql, [], 'all', ctx);
|
|
223
223
|
const ret = {};
|
|
224
224
|
for (const check of allChecks) {
|
|
225
225
|
const key = this.getTableKey(check);
|
|
@@ -233,15 +233,15 @@ class MsSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
233
233
|
}
|
|
234
234
|
return ret;
|
|
235
235
|
}
|
|
236
|
-
async loadInformationSchema(schema, connection, tables) {
|
|
236
|
+
async loadInformationSchema(schema, connection, tables, schemas, ctx) {
|
|
237
237
|
if (tables.length === 0) {
|
|
238
238
|
return;
|
|
239
239
|
}
|
|
240
240
|
const tablesBySchema = this.getTablesGroupedBySchemas(tables);
|
|
241
|
-
const columns = await this.getAllColumns(connection, tablesBySchema);
|
|
242
|
-
const indexes = await this.getAllIndexes(connection, tablesBySchema);
|
|
243
|
-
const checks = await this.getAllChecks(connection, tablesBySchema);
|
|
244
|
-
const fks = await this.getAllForeignKeys(connection, tablesBySchema);
|
|
241
|
+
const columns = await this.getAllColumns(connection, tablesBySchema, ctx);
|
|
242
|
+
const indexes = await this.getAllIndexes(connection, tablesBySchema, ctx);
|
|
243
|
+
const checks = await this.getAllChecks(connection, tablesBySchema, ctx);
|
|
244
|
+
const fks = await this.getAllForeignKeys(connection, tablesBySchema, ctx);
|
|
245
245
|
for (const t of tables) {
|
|
246
246
|
const key = this.getTableKey(t);
|
|
247
247
|
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": "6.6.11-dev.
|
|
3
|
+
"version": "6.6.11-dev.2",
|
|
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
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"access": "public"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@mikro-orm/knex": "6.6.11-dev.
|
|
61
|
+
"@mikro-orm/knex": "6.6.11-dev.2",
|
|
62
62
|
"tedious": "19.2.1",
|
|
63
63
|
"tsqlstring": "1.0.1"
|
|
64
64
|
},
|
|
@@ -66,6 +66,6 @@
|
|
|
66
66
|
"@mikro-orm/core": "^6.6.10"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "6.6.11-dev.
|
|
69
|
+
"@mikro-orm/core": "6.6.11-dev.2"
|
|
70
70
|
}
|
|
71
71
|
}
|