@mikro-orm/mssql 7.0.0-dev.169 → 7.0.0-dev.170

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.
@@ -10,6 +10,8 @@ export declare class MsSqlSchemaHelper extends SchemaHelper {
10
10
  enableForeignKeysSQL(): string;
11
11
  getDatabaseExistsSQL(name: string): string;
12
12
  getListTablesSQL(): string;
13
+ getListViewsSQL(): string;
14
+ loadViews(schema: DatabaseSchema, connection: AbstractSqlConnection): Promise<void>;
13
15
  getNamespaces(connection: AbstractSqlConnection): Promise<string[]>;
14
16
  normalizeDefaultValue(defaultValue: string, length: number, defaultValues?: Dictionary<string[]>, stripQuotes?: boolean): string | number;
15
17
  getAllColumns(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>): Promise<Dictionary<Column[]>>;
@@ -35,6 +37,7 @@ export declare class MsSqlSchemaHelper extends SchemaHelper {
35
37
  createIndex(index: IndexDef, table: DatabaseTable, createPrimary?: boolean): string;
36
38
  dropForeignKey(tableName: string, constraintName: string): string;
37
39
  dropTableIfExists(name: string, schema?: string): string;
40
+ dropViewIfExists(name: string, schema?: string): string;
38
41
  getAddColumnsSQL(table: DatabaseTable, columns: Column[]): string[];
39
42
  appendComments(table: DatabaseTable): string[];
40
43
  inferLengthFromColumnType(type: string): number | undefined;
@@ -25,6 +25,24 @@ export class MsSqlSchemaHelper extends SchemaHelper {
25
25
  left join sys.extended_properties ep on ep.major_id = t.id and ep.name = 'MS_Description' and ep.minor_id = 0
26
26
  order by schema_name(t2.schema_id), t.name`;
27
27
  }
28
+ getListViewsSQL() {
29
+ return `select v.name as view_name, schema_name(v.schema_id) as schema_name, m.definition as view_definition
30
+ from sys.views v
31
+ inner join sys.sql_modules m on v.object_id = m.object_id
32
+ order by schema_name(v.schema_id), v.name`;
33
+ }
34
+ async loadViews(schema, connection) {
35
+ const views = await connection.execute(this.getListViewsSQL());
36
+ for (const view of views) {
37
+ // Extract SELECT statement from CREATE VIEW ... AS SELECT ...
38
+ const match = view.view_definition?.match(/\bAS\s+(.+)$/is);
39
+ const definition = match?.[1]?.trim();
40
+ if (definition) {
41
+ const schemaName = view.schema_name === this.platform.getDefaultSchemaName() ? undefined : view.schema_name;
42
+ schema.addView(view.view_name, schemaName, definition);
43
+ }
44
+ }
45
+ }
28
46
  async getNamespaces(connection) {
29
47
  const sql = `select name as schema_name from sys.schemas order by name`;
30
48
  const res = await connection.execute(sql);
@@ -418,6 +436,10 @@ export class MsSqlSchemaHelper extends SchemaHelper {
418
436
  }
419
437
  return `if object_id('${this.quote(schema, name)}', 'U') is not null drop table ${this.quote(schema, name)}`;
420
438
  }
439
+ dropViewIfExists(name, schema) {
440
+ const viewName = this.quote(this.getTableName(name, schema));
441
+ return `if object_id('${viewName}', 'V') is not null drop view ${viewName}`;
442
+ }
421
443
  getAddColumnsSQL(table, columns) {
422
444
  const adds = columns.map(column => {
423
445
  return `${this.createTableColumn(column, table)}`;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mikro-orm/mssql",
3
3
  "type": "module",
4
- "version": "7.0.0-dev.169",
4
+ "version": "7.0.0-dev.170",
5
5
  "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.",
6
6
  "exports": {
7
7
  "./package.json": "./package.json",
@@ -50,7 +50,7 @@
50
50
  "access": "public"
51
51
  },
52
52
  "dependencies": {
53
- "@mikro-orm/sql": "7.0.0-dev.169",
53
+ "@mikro-orm/sql": "7.0.0-dev.170",
54
54
  "kysely": "0.28.10",
55
55
  "tarn": "3.0.2",
56
56
  "tedious": "19.2.0",
@@ -60,6 +60,6 @@
60
60
  "@mikro-orm/core": "^6.6.4"
61
61
  },
62
62
  "peerDependencies": {
63
- "@mikro-orm/core": "7.0.0-dev.169"
63
+ "@mikro-orm/core": "7.0.0-dev.170"
64
64
  }
65
65
  }