@mikro-orm/mssql 6.2.10-dev.75 → 6.2.10-dev.76

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.
@@ -23,6 +23,9 @@ export declare class MsSqlPlatform extends AbstractSqlPlatform {
23
23
  getRegExpOperator(): string;
24
24
  getBlobDeclarationSQL(): string;
25
25
  getJsonDeclarationSQL(): string;
26
+ getVarcharTypeDeclarationSQL(column: {
27
+ length?: number;
28
+ }): string;
26
29
  getEnumTypeDeclarationSQL(column: {
27
30
  items?: unknown[];
28
31
  fieldNames: 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);
@@ -65,9 +66,15 @@ class MsSqlPlatform extends knex_1.AbstractSqlPlatform {
65
66
  getJsonDeclarationSQL() {
66
67
  return 'nvarchar(max)';
67
68
  }
69
+ getVarcharTypeDeclarationSQL(column) {
70
+ if (column.length === -1) {
71
+ return 'varchar(max)';
72
+ }
73
+ return super.getVarcharTypeDeclarationSQL(column);
74
+ }
68
75
  getEnumTypeDeclarationSQL(column) {
69
76
  if (column.items?.every(item => knex_1.Utils.isString(item))) {
70
- return knex_1.Type.getType(UnicodeStringType_1.UnicodeStringType).getColumnType({ length: 100, ...column });
77
+ return knex_1.Type.getType(UnicodeStringType_1.UnicodeStringType).getColumnType({ length: 100, ...column }, this);
71
78
  }
72
79
  /* istanbul ignore next */
73
80
  return this.getSmallIntTypeDeclarationSQL(column);
@@ -77,6 +84,9 @@ class MsSqlPlatform extends knex_1.AbstractSqlPlatform {
77
84
  if (normalizedType !== 'uuid' && ['string', 'nvarchar'].includes(normalizedType)) {
78
85
  return knex_1.Type.getType(UnicodeStringType_1.UnicodeStringType);
79
86
  }
87
+ if (['character', 'nchar'].includes(normalizedType)) {
88
+ return knex_1.Type.getType(UnicodeCharacterType_1.UnicodeCharacterType);
89
+ }
80
90
  const map = {
81
91
  int: 'integer',
82
92
  bit: 'boolean',
@@ -345,7 +345,7 @@ class MsSqlSchemaHelper extends knex_1.SchemaHelper {
345
345
  if (!match) {
346
346
  return;
347
347
  }
348
- if (match[2] === 'max' && ['varchar', 'nvarchar'].includes(match[1])) {
348
+ if (match[2] === 'max') {
349
349
  return -1;
350
350
  }
351
351
  return +match[2];
@@ -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 } 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);
@@ -10,9 +10,10 @@ export declare class UnicodeString {
10
10
  export declare class UnicodeStringType extends Type<string | null, string | null> {
11
11
  getColumnType(prop: {
12
12
  length?: number;
13
- }): string;
13
+ }, platform: Platform): string;
14
14
  convertToJSValue(value: string | null | UnicodeString): string | null;
15
15
  convertToDatabaseValue(value: string | null): string | null;
16
16
  get runtimeType(): string;
17
17
  toJSON(value: string | null | UnicodeString): string | null;
18
+ getDefaultLength(platform: Platform): number;
18
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.75",
3
+ "version": "6.2.10-dev.76",
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.2.10-dev.75",
61
+ "@mikro-orm/knex": "6.2.10-dev.76",
62
62
  "tedious": "18.2.1",
63
63
  "tsqlstring": "1.0.1"
64
64
  },
@@ -66,6 +66,6 @@
66
66
  "@mikro-orm/core": "^6.2.9"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.2.10-dev.75"
69
+ "@mikro-orm/core": "6.2.10-dev.76"
70
70
  }
71
71
  }