@mikro-orm/mssql 7.0.5 → 7.0.6-dev.1

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.
@@ -2,22 +2,22 @@ import { QueryFlag, Utils } from '@mikro-orm/core';
2
2
  import { QueryBuilder } from '@mikro-orm/sql';
3
3
  /** Query builder with MSSQL-specific behavior such as identity insert handling. */
4
4
  export class MsSqlQueryBuilder extends QueryBuilder {
5
- insert(data) {
6
- this.checkIdentityInsert(data);
7
- if (!this.hasFlag(QueryFlag.IDENTITY_INSERT) && this.metadata.has(this.mainAlias.entityName)) {
8
- const meta = this.mainAlias.meta;
9
- if (meta.hasTriggers) {
10
- this.setFlag(QueryFlag.OUTPUT_TABLE);
11
- }
5
+ insert(data) {
6
+ this.checkIdentityInsert(data);
7
+ if (!this.hasFlag(QueryFlag.IDENTITY_INSERT) && this.metadata.has(this.mainAlias.entityName)) {
8
+ const meta = this.mainAlias.meta;
9
+ if (meta.hasTriggers) {
10
+ this.setFlag(QueryFlag.OUTPUT_TABLE);
11
+ }
12
+ }
13
+ return super.insert(data);
12
14
  }
13
- return super.insert(data);
14
- }
15
- checkIdentityInsert(data) {
16
- const meta = this.mainAlias.meta;
17
- const dataKeys = Utils.unique(Utils.asArray(data).flatMap(d => Utils.keys(d)));
18
- const hasAutoincrement = dataKeys.some(x => meta.properties[x]?.autoincrement);
19
- if (hasAutoincrement) {
20
- this.setFlag(QueryFlag.IDENTITY_INSERT);
15
+ checkIdentityInsert(data) {
16
+ const meta = this.mainAlias.meta;
17
+ const dataKeys = Utils.unique(Utils.asArray(data).flatMap(d => Utils.keys(d)));
18
+ const hasAutoincrement = dataKeys.some(x => meta.properties[x]?.autoincrement);
19
+ if (hasAutoincrement) {
20
+ this.setFlag(QueryFlag.IDENTITY_INSERT);
21
+ }
21
22
  }
22
- }
23
23
  }
@@ -2,7 +2,7 @@ import { type ClearDatabaseOptions, type DropSchemaOptions, type MikroORM, Schem
2
2
  import type { MsSqlDriver } from './MsSqlDriver.js';
3
3
  /** Schema generator with MSSQL-specific behavior for clearing and dropping schemas. */
4
4
  export declare class MsSqlSchemaGenerator extends SchemaGenerator {
5
- static register(orm: MikroORM<MsSqlDriver>): void;
6
- clear(options?: ClearDatabaseOptions): Promise<void>;
7
- getDropSchemaSQL(options?: Omit<DropSchemaOptions, 'dropDb'>): Promise<string>;
5
+ static register(orm: MikroORM<MsSqlDriver>): void;
6
+ clear(options?: ClearDatabaseOptions): Promise<void>;
7
+ getDropSchemaSQL(options?: Omit<DropSchemaOptions, 'dropDb'>): Promise<string>;
8
8
  }
@@ -1,28 +1,28 @@
1
1
  import { SchemaGenerator } from '@mikro-orm/sql';
2
2
  /** Schema generator with MSSQL-specific behavior for clearing and dropping schemas. */
3
3
  export class MsSqlSchemaGenerator extends SchemaGenerator {
4
- static register(orm) {
5
- orm.config.registerExtension('@mikro-orm/schema-generator', () => new MsSqlSchemaGenerator(orm.em));
6
- }
7
- async clear(options) {
8
- // truncate by default, so no value is considered as true
9
- /* v8 ignore next */
10
- if (options?.truncate === false) {
11
- return super.clear(options);
4
+ static register(orm) {
5
+ orm.config.registerExtension('@mikro-orm/schema-generator', () => new MsSqlSchemaGenerator(orm.em));
12
6
  }
13
- // https://stackoverflow.com/questions/253849/cannot-truncate-table-because-it-is-being-referenced-by-a-foreign-key-constraint
14
- for (const meta of this.getOrderedMetadata(options?.schema).reverse()) {
15
- const res = await this.driver.nativeDelete(meta.class, {}, options);
16
- if (meta.getPrimaryProps().some(pk => pk.autoincrement)) {
17
- const tableName = this.driver.getTableName(meta, { schema: options?.schema }, false);
18
- await this.execute(`dbcc checkident ('${tableName}', reseed, ${res.affectedRows > 0 ? 0 : 1})`, {
19
- ctx: this.em?.getTransactionContext(),
20
- });
21
- }
7
+ async clear(options) {
8
+ // truncate by default, so no value is considered as true
9
+ /* v8 ignore next */
10
+ if (options?.truncate === false) {
11
+ return super.clear(options);
12
+ }
13
+ // https://stackoverflow.com/questions/253849/cannot-truncate-table-because-it-is-being-referenced-by-a-foreign-key-constraint
14
+ for (const meta of this.getOrderedMetadata(options?.schema).reverse()) {
15
+ const res = await this.driver.nativeDelete(meta.class, {}, options);
16
+ if (meta.getPrimaryProps().some(pk => pk.autoincrement)) {
17
+ const tableName = this.driver.getTableName(meta, { schema: options?.schema }, false);
18
+ await this.execute(`dbcc checkident ('${tableName}', reseed, ${res.affectedRows > 0 ? 0 : 1})`, {
19
+ ctx: this.em?.getTransactionContext(),
20
+ });
21
+ }
22
+ }
23
+ this.clearIdentityMap();
24
+ }
25
+ async getDropSchemaSQL(options = {}) {
26
+ return super.getDropSchemaSQL({ dropForeignKeys: true, ...options });
22
27
  }
23
- this.clearIdentityMap();
24
- }
25
- async getDropSchemaSQL(options = {}) {
26
- return super.getDropSchemaSQL({ dropForeignKeys: true, ...options });
27
- }
28
28
  }
@@ -1,85 +1,55 @@
1
- import {
2
- type AbstractSqlConnection,
3
- type CheckDef,
4
- type Column,
5
- type DatabaseSchema,
6
- type DatabaseTable,
7
- type Dictionary,
8
- type ForeignKey,
9
- type IndexDef,
10
- SchemaHelper,
11
- type Table,
12
- type TableDifference,
13
- type Type,
14
- } 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 Type } from '@mikro-orm/sql';
15
2
  /** Schema introspection helper for Microsoft SQL Server. */
16
3
  export declare class MsSqlSchemaHelper extends SchemaHelper {
17
- static readonly DEFAULT_VALUES: {
18
- true: string[];
19
- false: string[];
20
- 'getdate()': string[];
21
- };
22
- getManagementDbName(): string;
23
- getDropDatabaseSQL(name: string): string;
24
- disableForeignKeysSQL(): string;
25
- enableForeignKeysSQL(): string;
26
- getDatabaseExistsSQL(name: string): string;
27
- getListTablesSQL(): string;
28
- getListViewsSQL(): string;
29
- loadViews(schema: DatabaseSchema, connection: AbstractSqlConnection): Promise<void>;
30
- getNamespaces(connection: AbstractSqlConnection): Promise<string[]>;
31
- normalizeDefaultValue(
32
- defaultValue: string,
33
- length: number,
34
- defaultValues?: Dictionary<string[]>,
35
- stripQuotes?: boolean,
36
- ): string | number;
37
- getAllColumns(
38
- connection: AbstractSqlConnection,
39
- tablesBySchemas: Map<string | undefined, Table[]>,
40
- ): Promise<Dictionary<Column[]>>;
41
- getAllIndexes(
42
- connection: AbstractSqlConnection,
43
- tablesBySchemas: Map<string | undefined, Table[]>,
44
- ): Promise<Dictionary<IndexDef[]>>;
45
- mapForeignKeys(fks: any[], tableName: string, schemaName?: string): Dictionary;
46
- getAllForeignKeys(
47
- connection: AbstractSqlConnection,
48
- tablesBySchemas: Map<string | undefined, Table[]>,
49
- ): Promise<Dictionary<Dictionary<ForeignKey>>>;
50
- private getEnumDefinitions;
51
- private getChecksSQL;
52
- getAllChecks(
53
- connection: AbstractSqlConnection,
54
- tablesBySchemas: Map<string | undefined, Table[]>,
55
- ): Promise<Dictionary<CheckDef[]>>;
56
- loadInformationSchema(schema: DatabaseSchema, connection: AbstractSqlConnection, tables: Table[]): Promise<void>;
57
- getPreAlterTable(tableDiff: TableDifference, safe: boolean): string[];
58
- getPostAlterTable(tableDiff: TableDifference, safe: boolean): string[];
59
- getCreateNamespaceSQL(name: string): string;
60
- getDropNamespaceSQL(name: string): string;
61
- getDropIndexSQL(tableName: string, index: IndexDef): string;
62
- dropIndex(table: string, index: IndexDef, oldIndexName?: string): string;
63
- getDropColumnsSQL(tableName: string, columns: Column[], schemaName?: string): string;
64
- private getDropDefaultsSQL;
65
- getRenameColumnSQL(tableName: string, oldColumnName: string, to: Column, schemaName?: string): string;
66
- createTableColumn(column: Column, table: DatabaseTable, changedProperties?: Set<string>): string | undefined;
67
- alterTableColumn(column: Column, table: DatabaseTable, changedProperties: Set<string>): string[];
68
- getCreateIndexSQL(tableName: string, index: IndexDef, partialExpression?: boolean): string;
69
- /**
70
- * Build the column list for a MSSQL index.
71
- */
72
- protected getIndexColumns(index: IndexDef): string;
73
- /**
74
- * Get MSSQL-specific index WITH options like fill factor.
75
- */
76
- private getMsSqlIndexSuffix;
77
- createIndex(index: IndexDef, table: DatabaseTable, createPrimary?: boolean): string;
78
- dropForeignKey(tableName: string, constraintName: string): string;
79
- dropTableIfExists(name: string, schema?: string): string;
80
- dropViewIfExists(name: string, schema?: string): string;
81
- getAddColumnsSQL(table: DatabaseTable, columns: Column[]): string[];
82
- appendComments(table: DatabaseTable): string[];
83
- inferLengthFromColumnType(type: string): number | undefined;
84
- protected wrap(val: string | undefined, type: Type<unknown>): string | undefined;
4
+ static readonly DEFAULT_VALUES: {
5
+ true: string[];
6
+ false: string[];
7
+ 'getdate()': string[];
8
+ };
9
+ getManagementDbName(): string;
10
+ getDropDatabaseSQL(name: string): string;
11
+ disableForeignKeysSQL(): string;
12
+ enableForeignKeysSQL(): string;
13
+ getDatabaseExistsSQL(name: string): string;
14
+ getListTablesSQL(): string;
15
+ getListViewsSQL(): string;
16
+ loadViews(schema: DatabaseSchema, connection: AbstractSqlConnection): Promise<void>;
17
+ getNamespaces(connection: AbstractSqlConnection): Promise<string[]>;
18
+ normalizeDefaultValue(defaultValue: string, length: number, defaultValues?: Dictionary<string[]>, stripQuotes?: boolean): string | number;
19
+ getAllColumns(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>): Promise<Dictionary<Column[]>>;
20
+ getAllIndexes(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>): Promise<Dictionary<IndexDef[]>>;
21
+ mapForeignKeys(fks: any[], tableName: string, schemaName?: string): Dictionary;
22
+ getAllForeignKeys(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>): Promise<Dictionary<Dictionary<ForeignKey>>>;
23
+ private getEnumDefinitions;
24
+ private getChecksSQL;
25
+ getAllChecks(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>): Promise<Dictionary<CheckDef[]>>;
26
+ loadInformationSchema(schema: DatabaseSchema, connection: AbstractSqlConnection, tables: Table[]): Promise<void>;
27
+ getPreAlterTable(tableDiff: TableDifference, safe: boolean): string[];
28
+ getPostAlterTable(tableDiff: TableDifference, safe: boolean): string[];
29
+ getCreateNamespaceSQL(name: string): string;
30
+ getDropNamespaceSQL(name: string): string;
31
+ getDropIndexSQL(tableName: string, index: IndexDef): string;
32
+ dropIndex(table: string, index: IndexDef, oldIndexName?: string): string;
33
+ getDropColumnsSQL(tableName: string, columns: Column[], schemaName?: string): string;
34
+ private getDropDefaultsSQL;
35
+ getRenameColumnSQL(tableName: string, oldColumnName: string, to: Column, schemaName?: string): string;
36
+ createTableColumn(column: Column, table: DatabaseTable, changedProperties?: Set<string>): string | undefined;
37
+ alterTableColumn(column: Column, table: DatabaseTable, changedProperties: Set<string>): string[];
38
+ getCreateIndexSQL(tableName: string, index: IndexDef, partialExpression?: boolean): string;
39
+ /**
40
+ * Build the column list for a MSSQL index.
41
+ */
42
+ protected getIndexColumns(index: IndexDef): string;
43
+ /**
44
+ * Get MSSQL-specific index WITH options like fill factor.
45
+ */
46
+ private getMsSqlIndexSuffix;
47
+ createIndex(index: IndexDef, table: DatabaseTable, createPrimary?: boolean): string;
48
+ dropForeignKey(tableName: string, constraintName: string): string;
49
+ dropTableIfExists(name: string, schema?: string): string;
50
+ dropViewIfExists(name: string, schema?: string): string;
51
+ getAddColumnsSQL(table: DatabaseTable, columns: Column[]): string[];
52
+ appendComments(table: DatabaseTable): string[];
53
+ inferLengthFromColumnType(type: string): number | undefined;
54
+ protected wrap(val: string | undefined, type: Type<unknown>): string | undefined;
85
55
  }