@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.
@@ -1,92 +1,75 @@
1
- import {
2
- AbstractSqlPlatform,
3
- type EntityManager,
4
- type EntityMetadata,
5
- type IDatabaseDriver,
6
- type IPrimaryKey,
7
- type MikroORM,
8
- MsSqlNativeQueryBuilder,
9
- type Primary,
10
- QueryOrder,
11
- RawQueryFragment,
12
- Type,
13
- } from '@mikro-orm/sql';
1
+ import { AbstractSqlPlatform, type EntityManager, type EntityMetadata, type IDatabaseDriver, type IPrimaryKey, type MikroORM, MsSqlNativeQueryBuilder, type Primary, QueryOrder, RawQueryFragment, Type } from '@mikro-orm/sql';
14
2
  import { MsSqlSchemaHelper } from './MsSqlSchemaHelper.js';
15
3
  import { MsSqlExceptionConverter } from './MsSqlExceptionConverter.js';
16
4
  import { MsSqlSchemaGenerator } from './MsSqlSchemaGenerator.js';
17
5
  import type { MsSqlDriver } from './MsSqlDriver.js';
18
6
  /** Platform implementation for Microsoft SQL Server. */
19
7
  export declare class MsSqlPlatform extends AbstractSqlPlatform {
20
- #private;
21
- protected readonly schemaHelper: MsSqlSchemaHelper;
22
- protected readonly exceptionConverter: MsSqlExceptionConverter;
23
- /** @inheritDoc */
24
- lookupExtensions(orm: MikroORM<MsSqlDriver>): void;
25
- /** @inheritDoc */
26
- init(orm: MikroORM): void;
27
- getRollbackToSavepointSQL(savepointName: string): string;
28
- getSavepointSQL(savepointName: string): string;
29
- /** @internal */
30
- createNativeQueryBuilder(): MsSqlNativeQueryBuilder;
31
- usesOutputStatement(): boolean;
32
- convertDateToJSValue(value: string | Date): string;
33
- convertsJsonAutomatically(): boolean;
34
- indexForeignKeys(): boolean;
35
- supportsSchemas(): boolean;
36
- getCurrentTimestampSQL(length: number): string;
37
- getDateTimeTypeDeclarationSQL(column: { length?: number }): string;
38
- getDefaultDateTimeLength(): number;
39
- getFloatDeclarationSQL(): string;
40
- getDoubleDeclarationSQL(): string;
41
- getBooleanTypeDeclarationSQL(): string;
42
- getRegExpOperator(): string;
43
- getBlobDeclarationSQL(): string;
44
- getJsonDeclarationSQL(): string;
45
- getVarcharTypeDeclarationSQL(column: { length?: number }): string;
46
- getEnumTypeDeclarationSQL(column: {
47
- items?: unknown[];
48
- fieldNames: string[];
49
- length?: number;
50
- unsigned?: boolean;
51
- autoincrement?: boolean;
52
- }): string;
53
- normalizeColumnType(
54
- type: string,
55
- options: {
56
- length?: number;
57
- precision?: number;
58
- scale?: number;
59
- },
60
- ): string;
61
- getDefaultMappedType(type: string): Type<unknown>;
62
- getDefaultSchemaName(): string | undefined;
63
- getUuidTypeDeclarationSQL(column: { length?: number }): string;
64
- validateMetadata(meta: EntityMetadata): void;
65
- getSearchJsonPropertyKey(path: string[], type: string, aliased: boolean, value?: unknown): string | RawQueryFragment;
66
- getJsonArrayFromSQL(
67
- column: string,
68
- alias: string,
69
- properties: {
70
- name: string;
71
- type: string;
72
- }[],
73
- ): string;
74
- normalizePrimaryKey<T extends number | string = number | string>(data: Primary<T> | IPrimaryKey | string): T;
75
- usesEnumCheckConstraints(): boolean;
76
- supportsMultipleCascadePaths(): boolean;
77
- supportsMultipleStatements(): boolean;
78
- quoteIdentifier(
79
- id:
80
- | string
81
- | {
82
- toString: () => string;
83
- },
84
- ): string;
85
- escape(value: any): string;
86
- getSchemaGenerator(driver: IDatabaseDriver, em?: EntityManager): MsSqlSchemaGenerator;
87
- allowsComparingTuples(): boolean;
88
- /** @internal MSSQL collation names are not quoted. */
89
- quoteCollation(collation: string): string;
90
- getOrderByExpression(column: string, direction: QueryOrder, collation?: string): string[];
91
- getDefaultClientUrl(): string;
8
+ #private;
9
+ protected readonly schemaHelper: MsSqlSchemaHelper;
10
+ protected readonly exceptionConverter: MsSqlExceptionConverter;
11
+ /** @inheritDoc */
12
+ lookupExtensions(orm: MikroORM<MsSqlDriver>): void;
13
+ /** @inheritDoc */
14
+ init(orm: MikroORM): void;
15
+ getRollbackToSavepointSQL(savepointName: string): string;
16
+ getSavepointSQL(savepointName: string): string;
17
+ /** @internal */
18
+ createNativeQueryBuilder(): MsSqlNativeQueryBuilder;
19
+ usesOutputStatement(): boolean;
20
+ convertDateToJSValue(value: string | Date): string;
21
+ convertsJsonAutomatically(): boolean;
22
+ indexForeignKeys(): boolean;
23
+ supportsSchemas(): boolean;
24
+ getCurrentTimestampSQL(length: number): string;
25
+ getDateTimeTypeDeclarationSQL(column: {
26
+ length?: number;
27
+ }): string;
28
+ getDefaultDateTimeLength(): number;
29
+ getFloatDeclarationSQL(): string;
30
+ getDoubleDeclarationSQL(): string;
31
+ getBooleanTypeDeclarationSQL(): string;
32
+ getRegExpOperator(): string;
33
+ getBlobDeclarationSQL(): string;
34
+ getJsonDeclarationSQL(): string;
35
+ getVarcharTypeDeclarationSQL(column: {
36
+ length?: number;
37
+ }): string;
38
+ getEnumTypeDeclarationSQL(column: {
39
+ items?: unknown[];
40
+ fieldNames: string[];
41
+ length?: number;
42
+ unsigned?: boolean;
43
+ autoincrement?: boolean;
44
+ }): string;
45
+ normalizeColumnType(type: string, options: {
46
+ length?: number;
47
+ precision?: number;
48
+ scale?: number;
49
+ }): string;
50
+ getDefaultMappedType(type: string): Type<unknown>;
51
+ getDefaultSchemaName(): string | undefined;
52
+ getUuidTypeDeclarationSQL(column: {
53
+ length?: number;
54
+ }): string;
55
+ validateMetadata(meta: EntityMetadata): void;
56
+ getSearchJsonPropertyKey(path: string[], type: string, aliased: boolean, value?: unknown): string | RawQueryFragment;
57
+ getJsonArrayFromSQL(column: string, alias: string, properties: {
58
+ name: string;
59
+ type: string;
60
+ }[]): string;
61
+ normalizePrimaryKey<T extends number | string = number | string>(data: Primary<T> | IPrimaryKey | string): T;
62
+ usesEnumCheckConstraints(): boolean;
63
+ supportsMultipleCascadePaths(): boolean;
64
+ supportsMultipleStatements(): boolean;
65
+ quoteIdentifier(id: string | {
66
+ toString: () => string;
67
+ }): string;
68
+ escape(value: any): string;
69
+ getSchemaGenerator(driver: IDatabaseDriver, em?: EntityManager): MsSqlSchemaGenerator;
70
+ allowsComparingTuples(): boolean;
71
+ /** @internal MSSQL collation names are not quoted. */
72
+ quoteCollation(collation: string): string;
73
+ getOrderByExpression(column: string, direction: QueryOrder, collation?: string): string[];
74
+ getDefaultClientUrl(): string;
92
75
  }
package/MsSqlPlatform.js CHANGED
@@ -1,14 +1,4 @@
1
- import {
2
- AbstractSqlPlatform,
3
- ALIAS_REPLACEMENT,
4
- DoubleType,
5
- FloatType,
6
- MsSqlNativeQueryBuilder,
7
- QueryOrder,
8
- raw,
9
- RawQueryFragment,
10
- Type,
11
- } from '@mikro-orm/sql';
1
+ import { AbstractSqlPlatform, ALIAS_REPLACEMENT, DoubleType, FloatType, MsSqlNativeQueryBuilder, QueryOrder, raw, RawQueryFragment, Type, } from '@mikro-orm/sql';
12
2
  // @ts-expect-error no types available
13
3
  import SqlString from 'tsqlstring';
14
4
  import { MsSqlSchemaHelper } from './MsSqlSchemaHelper.js';
@@ -18,232 +8,227 @@ import { UnicodeCharacterType } from './UnicodeCharacterType.js';
18
8
  import { UnicodeString, UnicodeStringType } from './UnicodeStringType.js';
19
9
  /** Platform implementation for Microsoft SQL Server. */
20
10
  export class MsSqlPlatform extends AbstractSqlPlatform {
21
- schemaHelper = new MsSqlSchemaHelper(this);
22
- exceptionConverter = new MsSqlExceptionConverter();
23
- #jsonTypeCasts = {
24
- string: 'nvarchar(max)',
25
- number: 'float',
26
- bigint: 'bigint',
27
- boolean: 'bit',
28
- };
29
- /** @inheritDoc */
30
- lookupExtensions(orm) {
31
- MsSqlSchemaGenerator.register(orm);
32
- }
33
- /** @inheritDoc */
34
- init(orm) {
35
- super.init(orm);
36
- // do not double escape backslash inside strings
37
- SqlString.CHARS_GLOBAL_REGEXP = /'/g;
38
- }
39
- getRollbackToSavepointSQL(savepointName) {
40
- return `rollback transaction ${this.quoteIdentifier(savepointName)}`;
41
- }
42
- getSavepointSQL(savepointName) {
43
- return `save transaction ${this.quoteIdentifier(savepointName)}`;
44
- }
45
- /** @internal */
46
- createNativeQueryBuilder() {
47
- return new MsSqlNativeQueryBuilder(this);
48
- }
49
- usesOutputStatement() {
50
- return true;
51
- }
52
- convertDateToJSValue(value) {
53
- /* v8 ignore next */
54
- if (typeof value === 'string') {
55
- return value;
56
- }
57
- return SqlString.dateToString(value.toISOString(), this.timezone ?? 'local').substring(1, 11);
58
- }
59
- convertsJsonAutomatically() {
60
- return false;
61
- }
62
- indexForeignKeys() {
63
- return false;
64
- }
65
- supportsSchemas() {
66
- return true;
67
- }
68
- getCurrentTimestampSQL(length) {
69
- return `current_timestamp`;
70
- }
71
- getDateTimeTypeDeclarationSQL(column) {
72
- /* v8 ignore next */
73
- return 'datetime2' + (column.length != null ? `(${column.length})` : '');
74
- }
75
- getDefaultDateTimeLength() {
76
- return 7;
77
- }
78
- getFloatDeclarationSQL() {
79
- return 'float(24)';
80
- }
81
- getDoubleDeclarationSQL() {
82
- return 'float(53)';
83
- }
84
- getBooleanTypeDeclarationSQL() {
85
- return 'bit';
86
- }
87
- getRegExpOperator() {
88
- throw new Error('Not supported');
89
- }
90
- getBlobDeclarationSQL() {
91
- return 'varbinary(max)';
92
- }
93
- getJsonDeclarationSQL() {
94
- return 'nvarchar(max)';
95
- }
96
- getVarcharTypeDeclarationSQL(column) {
97
- if (column.length === -1) {
98
- return 'varchar(max)';
99
- }
100
- return super.getVarcharTypeDeclarationSQL(column);
101
- }
102
- getEnumTypeDeclarationSQL(column) {
103
- if (column.items?.every(item => typeof item === 'string')) {
104
- return Type.getType(UnicodeStringType).getColumnType({ length: 100, ...column }, this);
105
- }
106
- /* v8 ignore next */
107
- return this.getSmallIntTypeDeclarationSQL(column);
108
- }
109
- normalizeColumnType(type, options) {
110
- const simpleType = this.extractSimpleType(type);
111
- if (['decimal', 'numeric'].includes(simpleType)) {
112
- return this.getDecimalTypeDeclarationSQL(options);
113
- }
114
- if (['real'].includes(simpleType)) {
115
- return this.getFloatDeclarationSQL();
116
- }
117
- return super.normalizeColumnType(type, options);
118
- }
119
- getDefaultMappedType(type) {
120
- if (type.startsWith('float')) {
121
- const len = /float\((\d+)\)/.exec(type)?.[1] ?? 24;
122
- return +len > 24 ? Type.getType(DoubleType) : Type.getType(FloatType);
123
- }
124
- const normalizedType = this.extractSimpleType(type);
125
- if (normalizedType !== 'uuid' && ['string', 'nvarchar'].includes(normalizedType)) {
126
- return Type.getType(UnicodeStringType);
127
- }
128
- if (['character', 'nchar'].includes(normalizedType)) {
129
- return Type.getType(UnicodeCharacterType);
130
- }
131
- const map = {
132
- int: 'integer',
133
- bit: 'boolean',
134
- real: 'float',
135
- uniqueidentifier: 'uuid',
136
- varbinary: 'blob',
137
- datetime2: 'datetime',
138
- smalldatetime: 'datetime',
11
+ schemaHelper = new MsSqlSchemaHelper(this);
12
+ exceptionConverter = new MsSqlExceptionConverter();
13
+ #jsonTypeCasts = {
14
+ string: 'nvarchar(max)',
15
+ number: 'float',
16
+ bigint: 'bigint',
17
+ boolean: 'bit',
139
18
  };
140
- return super.getDefaultMappedType(map[normalizedType] ?? type);
141
- }
142
- getDefaultSchemaName() {
143
- return 'dbo';
144
- }
145
- getUuidTypeDeclarationSQL(column) {
146
- return 'uniqueidentifier';
147
- }
148
- validateMetadata(meta) {
149
- for (const prop of meta.props) {
150
- if (
151
- (prop.runtimeType === 'string' || ['string', 'nvarchar'].includes(prop.type)) &&
152
- !['uuid'].includes(prop.type) &&
153
- !prop.columnTypes[0].startsWith('varchar')
154
- ) {
155
- prop.customType ??= new UnicodeStringType();
156
- prop.customType.prop = prop;
157
- prop.customType.platform = this;
158
- prop.customType.meta = meta;
159
- }
160
- }
161
- }
162
- getSearchJsonPropertyKey(path, type, aliased, value) {
163
- const [a, ...b] = path;
164
- /* v8 ignore next */
165
- const root = this.quoteIdentifier(aliased ? `${ALIAS_REPLACEMENT}.${a}` : a);
166
- const types = {
167
- boolean: 'bit',
168
- };
169
- const cast = key => raw(type in types ? `cast(${key} as ${types[type]})` : key);
170
- /* v8 ignore next */
171
- if (path.length === 0) {
172
- return cast(`json_value(${root}, '$.${b.map(this.quoteJsonKey).join('.')}')`);
173
- }
174
- return cast(`json_value(${root}, '$.${b.map(this.quoteJsonKey).join('.')}')`);
175
- }
176
- getJsonArrayFromSQL(column, alias, properties) {
177
- const columns = properties
178
- .map(
179
- p =>
180
- `${this.quoteIdentifier(p.name)} ${this.#jsonTypeCasts[p.type] ?? 'nvarchar(max)'} '$.${this.quoteJsonKey(p.name)}'`,
181
- )
182
- .join(', ');
183
- return `openjson(${column}) with (${columns}) as ${this.quoteIdentifier(alias)}`;
184
- }
185
- normalizePrimaryKey(data) {
186
- /* v8 ignore next */
187
- if (data instanceof UnicodeString) {
188
- return data.value;
189
- }
190
- return data;
191
- }
192
- usesEnumCheckConstraints() {
193
- return true;
194
- }
195
- supportsMultipleCascadePaths() {
196
- return false;
197
- }
198
- supportsMultipleStatements() {
199
- return true;
200
- }
201
- quoteIdentifier(id) {
202
- if (RawQueryFragment.isKnownFragment(id)) {
203
- return super.quoteIdentifier(id);
204
- }
205
- return `[${id.toString().replace('.', `].[`)}]`;
206
- }
207
- escape(value) {
208
- if (value instanceof UnicodeString) {
209
- return `N${SqlString.escape(value.value)}`;
210
- }
211
- if (value instanceof Buffer) {
212
- return `0x${value.toString('hex')}`;
213
- }
214
- if (value instanceof Date) {
215
- return SqlString.dateToString(value.toISOString(), this.timezone ?? 'local');
216
- }
217
- return SqlString.escape(value);
218
- }
219
- /* v8 ignore next: kept for type inference only */
220
- getSchemaGenerator(driver, em) {
221
- return new MsSqlSchemaGenerator(em ?? driver);
222
- }
223
- allowsComparingTuples() {
224
- return false;
225
- }
226
- /** @internal MSSQL collation names are not quoted. */
227
- quoteCollation(collation) {
228
- this.validateCollationName(collation);
229
- return collation;
230
- }
231
- getOrderByExpression(column, direction, collation) {
232
- const col = collation ? `${column} collate ${this.quoteCollation(collation)}` : column;
233
- switch (direction.toUpperCase()) {
234
- case QueryOrder.ASC_NULLS_FIRST:
235
- return [`case when ${column} is null then 0 else 1 end, ${col} asc`];
236
- case QueryOrder.ASC_NULLS_LAST:
237
- return [`case when ${column} is null then 1 else 0 end, ${col} asc`];
238
- case QueryOrder.DESC_NULLS_FIRST:
239
- return [`case when ${column} is null then 0 else 1 end, ${col} desc`];
240
- case QueryOrder.DESC_NULLS_LAST:
241
- return [`case when ${column} is null then 1 else 0 end, ${col} desc`];
242
- default:
243
- return [`${col} ${direction.toLowerCase()}`];
244
- }
245
- }
246
- getDefaultClientUrl() {
247
- return 'mssql://sa@localhost:1433';
248
- }
19
+ /** @inheritDoc */
20
+ lookupExtensions(orm) {
21
+ MsSqlSchemaGenerator.register(orm);
22
+ }
23
+ /** @inheritDoc */
24
+ init(orm) {
25
+ super.init(orm);
26
+ // do not double escape backslash inside strings
27
+ SqlString.CHARS_GLOBAL_REGEXP = /'/g;
28
+ }
29
+ getRollbackToSavepointSQL(savepointName) {
30
+ return `rollback transaction ${this.quoteIdentifier(savepointName)}`;
31
+ }
32
+ getSavepointSQL(savepointName) {
33
+ return `save transaction ${this.quoteIdentifier(savepointName)}`;
34
+ }
35
+ /** @internal */
36
+ createNativeQueryBuilder() {
37
+ return new MsSqlNativeQueryBuilder(this);
38
+ }
39
+ usesOutputStatement() {
40
+ return true;
41
+ }
42
+ convertDateToJSValue(value) {
43
+ /* v8 ignore next */
44
+ if (typeof value === 'string') {
45
+ return value;
46
+ }
47
+ return SqlString.dateToString(value.toISOString(), this.timezone ?? 'local').substring(1, 11);
48
+ }
49
+ convertsJsonAutomatically() {
50
+ return false;
51
+ }
52
+ indexForeignKeys() {
53
+ return false;
54
+ }
55
+ supportsSchemas() {
56
+ return true;
57
+ }
58
+ getCurrentTimestampSQL(length) {
59
+ return `current_timestamp`;
60
+ }
61
+ getDateTimeTypeDeclarationSQL(column) {
62
+ /* v8 ignore next */
63
+ return 'datetime2' + (column.length != null ? `(${column.length})` : '');
64
+ }
65
+ getDefaultDateTimeLength() {
66
+ return 7;
67
+ }
68
+ getFloatDeclarationSQL() {
69
+ return 'float(24)';
70
+ }
71
+ getDoubleDeclarationSQL() {
72
+ return 'float(53)';
73
+ }
74
+ getBooleanTypeDeclarationSQL() {
75
+ return 'bit';
76
+ }
77
+ getRegExpOperator() {
78
+ throw new Error('Not supported');
79
+ }
80
+ getBlobDeclarationSQL() {
81
+ return 'varbinary(max)';
82
+ }
83
+ getJsonDeclarationSQL() {
84
+ return 'nvarchar(max)';
85
+ }
86
+ getVarcharTypeDeclarationSQL(column) {
87
+ if (column.length === -1) {
88
+ return 'varchar(max)';
89
+ }
90
+ return super.getVarcharTypeDeclarationSQL(column);
91
+ }
92
+ getEnumTypeDeclarationSQL(column) {
93
+ if (column.items?.every(item => typeof item === 'string')) {
94
+ return Type.getType(UnicodeStringType).getColumnType({ length: 100, ...column }, this);
95
+ }
96
+ /* v8 ignore next */
97
+ return this.getSmallIntTypeDeclarationSQL(column);
98
+ }
99
+ normalizeColumnType(type, options) {
100
+ const simpleType = this.extractSimpleType(type);
101
+ if (['decimal', 'numeric'].includes(simpleType)) {
102
+ return this.getDecimalTypeDeclarationSQL(options);
103
+ }
104
+ if (['real'].includes(simpleType)) {
105
+ return this.getFloatDeclarationSQL();
106
+ }
107
+ return super.normalizeColumnType(type, options);
108
+ }
109
+ getDefaultMappedType(type) {
110
+ if (type.startsWith('float')) {
111
+ const len = /float\((\d+)\)/.exec(type)?.[1] ?? 24;
112
+ return +len > 24 ? Type.getType(DoubleType) : Type.getType(FloatType);
113
+ }
114
+ const normalizedType = this.extractSimpleType(type);
115
+ if (normalizedType !== 'uuid' && ['string', 'nvarchar'].includes(normalizedType)) {
116
+ return Type.getType(UnicodeStringType);
117
+ }
118
+ if (['character', 'nchar'].includes(normalizedType)) {
119
+ return Type.getType(UnicodeCharacterType);
120
+ }
121
+ const map = {
122
+ int: 'integer',
123
+ bit: 'boolean',
124
+ real: 'float',
125
+ uniqueidentifier: 'uuid',
126
+ varbinary: 'blob',
127
+ datetime2: 'datetime',
128
+ smalldatetime: 'datetime',
129
+ };
130
+ return super.getDefaultMappedType(map[normalizedType] ?? type);
131
+ }
132
+ getDefaultSchemaName() {
133
+ return 'dbo';
134
+ }
135
+ getUuidTypeDeclarationSQL(column) {
136
+ return 'uniqueidentifier';
137
+ }
138
+ validateMetadata(meta) {
139
+ for (const prop of meta.props) {
140
+ if ((prop.runtimeType === 'string' || ['string', 'nvarchar'].includes(prop.type)) &&
141
+ !['uuid'].includes(prop.type) &&
142
+ !prop.columnTypes[0].startsWith('varchar')) {
143
+ prop.customType ??= new UnicodeStringType();
144
+ prop.customType.prop = prop;
145
+ prop.customType.platform = this;
146
+ prop.customType.meta = meta;
147
+ }
148
+ }
149
+ }
150
+ getSearchJsonPropertyKey(path, type, aliased, value) {
151
+ const [a, ...b] = path;
152
+ /* v8 ignore next */
153
+ const root = this.quoteIdentifier(aliased ? `${ALIAS_REPLACEMENT}.${a}` : a);
154
+ const types = {
155
+ boolean: 'bit',
156
+ };
157
+ const cast = (key) => raw(type in types ? `cast(${key} as ${types[type]})` : key);
158
+ /* v8 ignore next */
159
+ if (path.length === 0) {
160
+ return cast(`json_value(${root}, '$.${b.map(this.quoteJsonKey).join('.')}')`);
161
+ }
162
+ return cast(`json_value(${root}, '$.${b.map(this.quoteJsonKey).join('.')}')`);
163
+ }
164
+ getJsonArrayFromSQL(column, alias, properties) {
165
+ const columns = properties
166
+ .map(p => `${this.quoteIdentifier(p.name)} ${this.#jsonTypeCasts[p.type] ?? 'nvarchar(max)'} '$.${this.quoteJsonKey(p.name)}'`)
167
+ .join(', ');
168
+ return `openjson(${column}) with (${columns}) as ${this.quoteIdentifier(alias)}`;
169
+ }
170
+ normalizePrimaryKey(data) {
171
+ /* v8 ignore next */
172
+ if (data instanceof UnicodeString) {
173
+ return data.value;
174
+ }
175
+ return data;
176
+ }
177
+ usesEnumCheckConstraints() {
178
+ return true;
179
+ }
180
+ supportsMultipleCascadePaths() {
181
+ return false;
182
+ }
183
+ supportsMultipleStatements() {
184
+ return true;
185
+ }
186
+ quoteIdentifier(id) {
187
+ if (RawQueryFragment.isKnownFragment(id)) {
188
+ return super.quoteIdentifier(id);
189
+ }
190
+ return `[${id.toString().replace('.', `].[`)}]`;
191
+ }
192
+ escape(value) {
193
+ if (value instanceof UnicodeString) {
194
+ return `N${SqlString.escape(value.value)}`;
195
+ }
196
+ if (value instanceof Buffer) {
197
+ return `0x${value.toString('hex')}`;
198
+ }
199
+ if (value instanceof Date) {
200
+ return SqlString.dateToString(value.toISOString(), this.timezone ?? 'local');
201
+ }
202
+ return SqlString.escape(value);
203
+ }
204
+ /* v8 ignore next: kept for type inference only */
205
+ getSchemaGenerator(driver, em) {
206
+ return new MsSqlSchemaGenerator(em ?? driver);
207
+ }
208
+ allowsComparingTuples() {
209
+ return false;
210
+ }
211
+ /** @internal MSSQL collation names are not quoted. */
212
+ quoteCollation(collation) {
213
+ this.validateCollationName(collation);
214
+ return collation;
215
+ }
216
+ getOrderByExpression(column, direction, collation) {
217
+ const col = collation ? `${column} collate ${this.quoteCollation(collation)}` : column;
218
+ switch (direction.toUpperCase()) {
219
+ case QueryOrder.ASC_NULLS_FIRST:
220
+ return [`case when ${column} is null then 0 else 1 end, ${col} asc`];
221
+ case QueryOrder.ASC_NULLS_LAST:
222
+ return [`case when ${column} is null then 1 else 0 end, ${col} asc`];
223
+ case QueryOrder.DESC_NULLS_FIRST:
224
+ return [`case when ${column} is null then 0 else 1 end, ${col} desc`];
225
+ case QueryOrder.DESC_NULLS_LAST:
226
+ return [`case when ${column} is null then 1 else 0 end, ${col} desc`];
227
+ default:
228
+ return [`${col} ${direction.toLowerCase()}`];
229
+ }
230
+ }
231
+ getDefaultClientUrl() {
232
+ return 'mssql://sa@localhost:1433';
233
+ }
249
234
  }
@@ -1,14 +1,7 @@
1
1
  import { type AnyEntity, type RequiredEntityData } from '@mikro-orm/core';
2
2
  import { type InsertQueryBuilder, QueryBuilder } from '@mikro-orm/sql';
3
3
  /** Query builder with MSSQL-specific behavior such as identity insert handling. */
4
- export declare class MsSqlQueryBuilder<
5
- Entity extends object = AnyEntity,
6
- RootAlias extends string = never,
7
- Hint extends string = never,
8
- Context extends object = never,
9
- > extends QueryBuilder<Entity, RootAlias, Hint, Context> {
10
- insert(
11
- data: RequiredEntityData<Entity> | RequiredEntityData<Entity>[],
12
- ): InsertQueryBuilder<Entity, RootAlias, Context>;
13
- private checkIdentityInsert;
4
+ export declare class MsSqlQueryBuilder<Entity extends object = AnyEntity, RootAlias extends string = never, Hint extends string = never, Context extends object = never> extends QueryBuilder<Entity, RootAlias, Hint, Context> {
5
+ insert(data: RequiredEntityData<Entity> | RequiredEntityData<Entity>[]): InsertQueryBuilder<Entity, RootAlias, Context>;
6
+ private checkIdentityInsert;
14
7
  }