@mikro-orm/mssql 6.3.5-dev.16 → 6.3.5-dev.18

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.
@@ -18,7 +18,7 @@ export declare class MsSqlPlatform extends AbstractSqlPlatform {
18
18
  getDateTimeTypeDeclarationSQL(column: {
19
19
  length?: number;
20
20
  }): string;
21
- getTimeTypeDeclarationSQL(): string;
21
+ getDefaultDateTimeLength(): number;
22
22
  getFloatDeclarationSQL(): string;
23
23
  getDoubleDeclarationSQL(): string;
24
24
  getBooleanTypeDeclarationSQL(): string;
@@ -35,6 +35,11 @@ export declare class MsSqlPlatform extends AbstractSqlPlatform {
35
35
  unsigned?: boolean;
36
36
  autoincrement?: boolean;
37
37
  }): string;
38
+ normalizeColumnType(type: string, options?: {
39
+ length?: number;
40
+ precision?: number;
41
+ scale?: number;
42
+ }): string;
38
43
  getDefaultMappedType(type: string): Type<unknown>;
39
44
  getDefaultSchemaName(): string | undefined;
40
45
  getUuidTypeDeclarationSQL(column: {
package/MsSqlPlatform.js CHANGED
@@ -51,8 +51,8 @@ class MsSqlPlatform extends knex_1.AbstractSqlPlatform {
51
51
  /* istanbul ignore next */
52
52
  return 'datetime2' + (column.length != null ? `(${column.length})` : '');
53
53
  }
54
- getTimeTypeDeclarationSQL() {
55
- return 'time';
54
+ getDefaultDateTimeLength() {
55
+ return 7;
56
56
  }
57
57
  getFloatDeclarationSQL() {
58
58
  return 'float(24)';
@@ -85,7 +85,21 @@ class MsSqlPlatform extends knex_1.AbstractSqlPlatform {
85
85
  /* istanbul ignore next */
86
86
  return this.getSmallIntTypeDeclarationSQL(column);
87
87
  }
88
+ normalizeColumnType(type, options = {}) {
89
+ const simpleType = this.extractSimpleType(type);
90
+ if (['decimal', 'numeric'].includes(simpleType)) {
91
+ return this.getDecimalTypeDeclarationSQL(options);
92
+ }
93
+ if (['real'].includes(simpleType)) {
94
+ return this.getFloatDeclarationSQL();
95
+ }
96
+ return super.normalizeColumnType(type, options);
97
+ }
88
98
  getDefaultMappedType(type) {
99
+ if (type.startsWith('float')) {
100
+ const len = type.match(/float\((\d+)\)/)?.[1] ?? 24;
101
+ return +len > 24 ? knex_1.Type.getType(knex_1.DoubleType) : knex_1.Type.getType(knex_1.FloatType);
102
+ }
89
103
  const normalizedType = this.extractSimpleType(type);
90
104
  if (normalizedType !== 'uuid' && ['string', 'nvarchar'].includes(normalizedType)) {
91
105
  return knex_1.Type.getType(UnicodeStringType_1.UnicodeStringType);
@@ -59,7 +59,8 @@ class MsSqlSchemaHelper extends knex_1.SchemaHelper {
59
59
  cmp.is_persisted as is_persisted,
60
60
  numeric_precision as numeric_precision,
61
61
  numeric_scale as numeric_scale,
62
- coalesce(datetime_precision, character_maximum_length) length,
62
+ datetime_precision as datetime_precision,
63
+ character_maximum_length as character_maximum_length,
63
64
  columnproperty(sc.object_id, column_name, 'IsIdentity') is_identity
64
65
  from information_schema.columns ic
65
66
  inner join sys.columns sc on sc.name = ic.column_name and sc.object_id = object_id(ic.table_schema + '.' + ic.table_name)
@@ -78,12 +79,21 @@ class MsSqlSchemaHelper extends knex_1.SchemaHelper {
78
79
  /* istanbul ignore next */
79
80
  const generated = col.generation_expression ? `${col.generation_expression}${col.is_persisted ? ' persisted' : ''}` : undefined;
80
81
  let type = col.data_type;
81
- if (col.length != null && !type.endsWith(`(${col.length})`)) {
82
- type += `(${col.length})`;
82
+ if (['varchar', 'nvarchar', 'char', 'nchar', 'varbinary'].includes(col.data_type)) {
83
+ col.length = col.character_maximum_length;
84
+ }
85
+ if (['timestamp', 'datetime', 'datetime2', 'time', 'datetimeoffset'].includes(col.data_type)) {
86
+ col.length = col.datetime_precision;
87
+ }
88
+ if (col.length != null && !type.endsWith(`(${col.length})`) && !['text', 'date'].includes(type)) {
89
+ type += `(${col.length === -1 ? 'max' : col.length})`;
83
90
  }
84
91
  if (type === 'numeric' && col.numeric_precision != null && col.numeric_scale != null) {
85
92
  type += `(${col.numeric_precision},${col.numeric_scale})`;
86
93
  }
94
+ if (type === 'float' && col.numeric_precision != null) {
95
+ type += `(${col.numeric_precision})`;
96
+ }
87
97
  ret[key] ??= [];
88
98
  ret[key].push({
89
99
  name: col.column_name,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/mssql",
3
- "version": "6.3.5-dev.16",
3
+ "version": "6.3.5-dev.18",
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.3.5-dev.16",
61
+ "@mikro-orm/knex": "6.3.5-dev.18",
62
62
  "tedious": "18.3.0",
63
63
  "tsqlstring": "1.0.1"
64
64
  },
@@ -66,6 +66,6 @@
66
66
  "@mikro-orm/core": "^6.3.4"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.3.5-dev.16"
69
+ "@mikro-orm/core": "6.3.5-dev.18"
70
70
  }
71
71
  }