@mikro-orm/mssql 6.2.10-dev.11 → 6.2.10-dev.111

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.
@@ -16,6 +16,7 @@ class MsSqlConnection extends knex_1.AbstractSqlConnection {
16
16
  options: {
17
17
  enableArithAbort: true,
18
18
  fallbackToDefaultDb: true,
19
+ useUTC: this.config.get('forceUtcTimezone'),
19
20
  },
20
21
  };
21
22
  /* istanbul ignore next */
package/MsSqlMikroORM.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defineMsSqlConfig = exports.MsSqlMikroORM = void 0;
3
+ exports.MsSqlMikroORM = void 0;
4
+ exports.defineMsSqlConfig = defineMsSqlConfig;
4
5
  const core_1 = require("@mikro-orm/core");
5
6
  const MsSqlDriver_1 = require("./MsSqlDriver");
6
7
  /**
@@ -26,4 +27,3 @@ exports.MsSqlMikroORM = MsSqlMikroORM;
26
27
  function defineMsSqlConfig(options) {
27
28
  return (0, core_1.defineConfig)({ driver: MsSqlDriver_1.MsSqlDriver, ...options });
28
29
  }
29
- exports.defineMsSqlConfig = defineMsSqlConfig;
@@ -7,6 +7,8 @@ export declare class MsSqlPlatform extends AbstractSqlPlatform {
7
7
  protected readonly exceptionConverter: MsSqlExceptionConverter;
8
8
  /** @inheritDoc */
9
9
  lookupExtensions(orm: MikroORM): void;
10
+ /** @inheritDoc */
11
+ init(orm: MikroORM): void;
10
12
  usesOutputStatement(): boolean;
11
13
  convertDateToJSValue(value: string | Date): string;
12
14
  convertsJsonAutomatically(): boolean;
@@ -23,16 +25,18 @@ export declare class MsSqlPlatform extends AbstractSqlPlatform {
23
25
  getRegExpOperator(): string;
24
26
  getBlobDeclarationSQL(): string;
25
27
  getJsonDeclarationSQL(): string;
28
+ getVarcharTypeDeclarationSQL(column: {
29
+ length?: number;
30
+ }): string;
26
31
  getEnumTypeDeclarationSQL(column: {
27
- fieldNames: string[];
28
32
  items?: unknown[];
33
+ fieldNames: string[];
29
34
  length?: number;
35
+ unsigned?: boolean;
36
+ autoincrement?: boolean;
30
37
  }): string;
31
38
  getDefaultMappedType(type: string): Type<unknown>;
32
39
  getDefaultSchemaName(): string | undefined;
33
- getVarcharTypeDeclarationSQL(column: {
34
- length?: number;
35
- }): string;
36
40
  getUuidTypeDeclarationSQL(column: {
37
41
  length?: number;
38
42
  }): string;
package/MsSqlPlatform.js CHANGED
@@ -10,6 +10,7 @@ const tsqlstring_1 = __importDefault(require("tsqlstring"));
10
10
  const MsSqlSchemaHelper_1 = require("./MsSqlSchemaHelper");
11
11
  const MsSqlExceptionConverter_1 = require("./MsSqlExceptionConverter");
12
12
  const MsSqlSchemaGenerator_1 = require("./MsSqlSchemaGenerator");
13
+ const UnicodeCharacterType_1 = require("./UnicodeCharacterType");
13
14
  const UnicodeStringType_1 = require("./UnicodeStringType");
14
15
  class MsSqlPlatform extends knex_1.AbstractSqlPlatform {
15
16
  schemaHelper = new MsSqlSchemaHelper_1.MsSqlSchemaHelper(this);
@@ -18,6 +19,12 @@ class MsSqlPlatform extends knex_1.AbstractSqlPlatform {
18
19
  lookupExtensions(orm) {
19
20
  MsSqlSchemaGenerator_1.MsSqlSchemaGenerator.register(orm);
20
21
  }
22
+ /** @inheritDoc */
23
+ init(orm) {
24
+ super.init(orm);
25
+ // do not double escape backslash inside strings
26
+ tsqlstring_1.default.CHARS_GLOBAL_REGEXP = /[\0\b\f\t\n\r\v\x1a']/g; // eslint-disable-line no-control-regex
27
+ }
21
28
  usesOutputStatement() {
22
29
  return true;
23
30
  }
@@ -26,7 +33,7 @@ class MsSqlPlatform extends knex_1.AbstractSqlPlatform {
26
33
  if (typeof value === 'string') {
27
34
  return value;
28
35
  }
29
- return value.toISOString().substring(0, 10);
36
+ return tsqlstring_1.default.dateToString(value.toISOString(), this.timezone ?? 'local').substring(1, 11);
30
37
  }
31
38
  convertsJsonAutomatically() {
32
39
  return false;
@@ -65,9 +72,15 @@ class MsSqlPlatform extends knex_1.AbstractSqlPlatform {
65
72
  getJsonDeclarationSQL() {
66
73
  return 'nvarchar(max)';
67
74
  }
75
+ getVarcharTypeDeclarationSQL(column) {
76
+ if (column.length === -1) {
77
+ return 'varchar(max)';
78
+ }
79
+ return super.getVarcharTypeDeclarationSQL(column);
80
+ }
68
81
  getEnumTypeDeclarationSQL(column) {
69
82
  if (column.items?.every(item => knex_1.Utils.isString(item))) {
70
- return this.getVarcharTypeDeclarationSQL({ length: 100, ...column });
83
+ return knex_1.Type.getType(UnicodeStringType_1.UnicodeStringType).getColumnType({ length: 100, ...column }, this);
71
84
  }
72
85
  /* istanbul ignore next */
73
86
  return this.getSmallIntTypeDeclarationSQL(column);
@@ -77,6 +90,9 @@ class MsSqlPlatform extends knex_1.AbstractSqlPlatform {
77
90
  if (normalizedType !== 'uuid' && ['string', 'nvarchar'].includes(normalizedType)) {
78
91
  return knex_1.Type.getType(UnicodeStringType_1.UnicodeStringType);
79
92
  }
93
+ if (['character', 'nchar'].includes(normalizedType)) {
94
+ return knex_1.Type.getType(UnicodeCharacterType_1.UnicodeCharacterType);
95
+ }
80
96
  const map = {
81
97
  int: 'integer',
82
98
  bit: 'boolean',
@@ -90,9 +106,6 @@ class MsSqlPlatform extends knex_1.AbstractSqlPlatform {
90
106
  getDefaultSchemaName() {
91
107
  return 'dbo';
92
108
  }
93
- getVarcharTypeDeclarationSQL(column) {
94
- return `nvarchar(${column.length ?? 255})`;
95
- }
96
109
  getUuidTypeDeclarationSQL(column) {
97
110
  return 'uniqueidentifier';
98
111
  }
@@ -153,13 +166,13 @@ class MsSqlPlatform extends knex_1.AbstractSqlPlatform {
153
166
  }
154
167
  /* istanbul ignore if */
155
168
  if (knex_1.Utils.isPlainObject(value) || value?.[knex_1.JsonProperty]) {
156
- return tsqlstring_1.default.escape(JSON.stringify(value), true, this.timezone);
169
+ return tsqlstring_1.default.escape(JSON.stringify(value), true, this.timezone ?? 'local');
157
170
  }
158
171
  if (value instanceof Buffer) {
159
172
  return `0x${value.toString('hex')}`;
160
173
  }
161
174
  if (value instanceof Date) {
162
- return tsqlstring_1.default.dateToString(value.toISOString(), 'Z');
175
+ return tsqlstring_1.default.dateToString(value.toISOString(), this.timezone ?? 'local');
163
176
  }
164
177
  return tsqlstring_1.default.escape(value);
165
178
  }
@@ -341,14 +341,14 @@ class MsSqlSchemaHelper extends knex_1.SchemaHelper {
341
341
  return super.createTableColumn(table, column, fromTable, changedProperties);
342
342
  }
343
343
  inferLengthFromColumnType(type) {
344
- const match = type.match(/n?varchar\((-?\d+|max)\)/);
344
+ const match = type.match(/^(\w+)\s*\(\s*(-?\d+|max)\s*\)/);
345
345
  if (!match) {
346
- return undefined;
346
+ return;
347
347
  }
348
- if (match[1] === 'max') {
348
+ if (match[2] === 'max') {
349
349
  return -1;
350
350
  }
351
- return +match[1];
351
+ return +match[2];
352
352
  }
353
353
  wrap(val, type) {
354
354
  const stringType = type instanceof knex_1.StringType || type instanceof knex_1.TextType || type instanceof knex_1.EnumType || type instanceof UnicodeStringType_1.UnicodeStringType;
@@ -0,0 +1,6 @@
1
+ import type { Platform, EntityProperty } from '@mikro-orm/core';
2
+ import { UnicodeStringType } from './UnicodeStringType';
3
+ export declare class UnicodeCharacterType extends UnicodeStringType {
4
+ getColumnType(prop: EntityProperty, platform: Platform): string;
5
+ getDefaultLength(platform: Platform): number;
6
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnicodeCharacterType = void 0;
4
+ const UnicodeStringType_1 = require("./UnicodeStringType");
5
+ class UnicodeCharacterType extends UnicodeStringType_1.UnicodeStringType {
6
+ getColumnType(prop, platform) {
7
+ const length = prop.length === -1 ? 'max' : (prop.length ?? this.getDefaultLength(platform));
8
+ return `nchar(${length})`;
9
+ }
10
+ getDefaultLength(platform) {
11
+ return platform.getDefaultCharLength();
12
+ }
13
+ }
14
+ exports.UnicodeCharacterType = UnicodeCharacterType;
@@ -1,4 +1,4 @@
1
- import { Type, type EntityProperty } from '@mikro-orm/core';
1
+ import { type Platform, Type } from '@mikro-orm/core';
2
2
  export declare class UnicodeString {
3
3
  readonly value: string;
4
4
  constructor(value: string);
@@ -8,9 +8,12 @@ export declare class UnicodeString {
8
8
  [Symbol.toPrimitive](): string;
9
9
  }
10
10
  export declare class UnicodeStringType extends Type<string | null, string | null> {
11
- getColumnType(prop: EntityProperty): string;
11
+ getColumnType(prop: {
12
+ length?: number;
13
+ }, platform: Platform): string;
12
14
  convertToJSValue(value: string | null | UnicodeString): string | null;
13
15
  convertToDatabaseValue(value: string | null): string | null;
14
16
  get runtimeType(): string;
15
17
  toJSON(value: string | null | UnicodeString): string | null;
18
+ getDefaultLength(platform: Platform): number;
16
19
  }
@@ -22,8 +22,8 @@ class UnicodeString {
22
22
  }
23
23
  exports.UnicodeString = UnicodeString;
24
24
  class UnicodeStringType extends core_1.Type {
25
- getColumnType(prop) {
26
- const length = prop.length === -1 ? 'max' : (prop.length ?? 255);
25
+ getColumnType(prop, platform) {
26
+ const length = prop.length === -1 ? 'max' : (prop.length ?? this.getDefaultLength(platform));
27
27
  return `nvarchar(${length})`;
28
28
  }
29
29
  convertToJSValue(value) {
@@ -45,5 +45,8 @@ class UnicodeStringType extends core_1.Type {
45
45
  toJSON(value) {
46
46
  return this.convertToJSValue(value);
47
47
  }
48
+ getDefaultLength(platform) {
49
+ return platform.getDefaultVarcharLength();
50
+ }
48
51
  }
49
52
  exports.UnicodeStringType = UnicodeStringType;
package/index.mjs CHANGED
@@ -33,6 +33,7 @@ export const ChangeSet = mod.ChangeSet;
33
33
  export const ChangeSetComputer = mod.ChangeSetComputer;
34
34
  export const ChangeSetPersister = mod.ChangeSetPersister;
35
35
  export const ChangeSetType = mod.ChangeSetType;
36
+ export const CharacterType = mod.CharacterType;
36
37
  export const Check = mod.Check;
37
38
  export const CheckConstraintViolationException = mod.CheckConstraintViolationException;
38
39
  export const Collection = mod.Collection;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/mssql",
3
- "version": "6.2.10-dev.11",
3
+ "version": "6.2.10-dev.111",
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,14 +58,14 @@
58
58
  "access": "public"
59
59
  },
60
60
  "dependencies": {
61
- "@mikro-orm/knex": "6.2.10-dev.11",
62
- "tedious": "18.2.0",
61
+ "@mikro-orm/knex": "6.2.10-dev.111",
62
+ "tedious": "18.2.4",
63
63
  "tsqlstring": "1.0.1"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@mikro-orm/core": "^6.2.9"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.2.10-dev.11"
69
+ "@mikro-orm/core": "6.2.10-dev.111"
70
70
  }
71
71
  }