@mikro-orm/sql 7.2.13-dev.11 → 7.2.13-dev.13

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/sql",
3
- "version": "7.2.13-dev.11",
3
+ "version": "7.2.13-dev.13",
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
  "keywords": [
6
6
  "data-mapper",
@@ -53,7 +53,7 @@
53
53
  "@mikro-orm/core": "^7.2.12"
54
54
  },
55
55
  "peerDependencies": {
56
- "@mikro-orm/core": "7.2.13-dev.11"
56
+ "@mikro-orm/core": "7.2.13-dev.13"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">= 22.17.0"
@@ -33,8 +33,11 @@ export class DatabaseTable {
33
33
  this.#platform = platform;
34
34
  }
35
35
  getQuotedName() {
36
- const schema = this.getShortestName() === this.name ? undefined : this.schema;
37
- return this.#platform.quoteQualifiedName(this.name, schema);
36
+ // a dot in the name can be a `database.schema.table` qualifier, it is kept inside the identifier in the default schema only
37
+ if (this.schema && this.schema !== this.#platform.getDefaultSchemaName()) {
38
+ return this.#platform.quoteIdentifier(this.getShortestName()).replaceAll('\\?', '?');
39
+ }
40
+ return this.#platform.quoteQualifiedName(this.name);
38
41
  }
39
42
  getColumns() {
40
43
  return Object.values(this.#columns);
@@ -301,12 +301,15 @@ export class SchemaComparator {
301
301
  }
302
302
  /** Engines drop length/precision modifiers and use different aliases for the same logical type — canonicalise both sides. */
303
303
  normaliseParamType(type) {
304
- const lengthMatch = /^([^()]+)\(([^)]*)\)\s*$/.exec(type);
305
- const base = (lengthMatch ? lengthMatch[1] : type).trim().toLowerCase();
304
+ const lower = type.trim().toLowerCase();
305
+ const array = /\[\d*\]$/.test(lower);
306
+ const element = array ? lower.slice(0, lower.indexOf('[')) : lower;
307
+ const open = element.indexOf('(');
308
+ const close = element.indexOf(')', open);
309
+ const stripped = open < 0 || close < 0 ? element : element.slice(0, open) + element.slice(close + 1);
310
+ const base = stripped.replace(/\s+/g, ' ').trim();
306
311
  const aliased = SchemaComparator.PARAM_TYPE_ALIASES[base] ?? base;
307
- const length = lengthMatch ? Number.parseInt(lengthMatch[2].split(',')[0].trim(), 10) : NaN;
308
- const options = Number.isFinite(length) ? { length } : {};
309
- return this.#platform.normalizeColumnType(aliased, options).toLowerCase();
312
+ return this.#platform.normalizeColumnType(aliased, {}).toLowerCase() + (array ? '[]' : '');
310
313
  }
311
314
  static PARAM_TYPE_ALIASES = {
312
315
  int: 'integer',
@@ -315,7 +318,11 @@ export class SchemaComparator {
315
318
  int2: 'smallint',
316
319
  bool: 'boolean',
317
320
  'character varying': 'varchar',
321
+ character: 'char',
318
322
  bpchar: 'char',
323
+ 'bit varying': 'varbit',
324
+ 'time without time zone': 'time',
325
+ 'timestamp without time zone': 'timestamp',
319
326
  float8: 'double precision',
320
327
  float4: 'real',
321
328
  // Oracle's USER_ARGUMENTS reports `REF CURSOR`; users declare `sys_refcursor`.
@@ -189,6 +189,8 @@ export declare abstract class SchemaHelper {
189
189
  /** Returns SQL to create a foreign key constraint on a table. */
190
190
  createForeignKey(table: DatabaseTable, foreignKey: ForeignKey, alterTable?: boolean, inline?: boolean): string;
191
191
  splitTableName(name: string, skipDefaultSchema?: boolean): [string | undefined, string];
192
+ /** Splits a developer-supplied name on the last dot, the qualifier can have more parts (`database.schema`). */
193
+ splitQualifiedName(name: string): [string | undefined, string];
192
194
  getReferencedTableName(referencedTableName: string, schema?: string): string;
193
195
  createIndex(index: IndexDef, table: DatabaseTable, createPrimary?: boolean): string;
194
196
  createCheck(table: DatabaseTable, check: CheckDef): string;
@@ -224,7 +226,7 @@ export declare abstract class SchemaHelper {
224
226
  get options(): NonNullable<Options['schemaGenerator']>;
225
227
  protected processComment(comment: string): string;
226
228
  protected quote(...keys: (string | undefined)[]): string;
227
- /** Quotes a table or view name held separately from its schema, a dot in either stays inside the identifier. */
229
+ /** A dot in the name stays inside the identifier in the default schema only, elsewhere it can be a `database.schema.table` qualifier. */
228
230
  protected quoteTableName(name: string, schema?: string): string;
229
231
  dropForeignKey(tableName: string, constraintName: string): string;
230
232
  dropIndex(table: string, index: IndexDef, oldIndexName?: string): string;
@@ -885,6 +885,11 @@ export class SchemaHelper {
885
885
  }
886
886
  return [schemaName, tableName];
887
887
  }
888
+ /** Splits a developer-supplied name on the last dot, the qualifier can have more parts (`database.schema`). */
889
+ splitQualifiedName(name) {
890
+ const index = name.lastIndexOf('.');
891
+ return index === -1 ? [undefined, name] : [name.substring(0, index), name.substring(index + 1)];
892
+ }
888
893
  getReferencedTableName(referencedTableName, schema) {
889
894
  const [schemaName, tableName] = this.splitTableName(referencedTableName);
890
895
  schema = schemaName ?? schema ?? this.platform.getConfig().get('schema');
@@ -1025,9 +1030,12 @@ export class SchemaHelper {
1025
1030
  // DDL is not a query template, so question marks need no escaping there
1026
1031
  return this.platform.quoteIdentifier(keys.filter(Boolean).join('.')).replaceAll('\\?', '?');
1027
1032
  }
1028
- /** Quotes a table or view name held separately from its schema, a dot in either stays inside the identifier. */
1033
+ /** A dot in the name stays inside the identifier in the default schema only, elsewhere it can be a `database.schema.table` qualifier. */
1029
1034
  quoteTableName(name, schema) {
1030
- return this.platform.quoteQualifiedName(name, schema === this.platform.getDefaultSchemaName() ? undefined : schema);
1035
+ if (schema && schema !== this.platform.getDefaultSchemaName()) {
1036
+ return this.quote(schema, name);
1037
+ }
1038
+ return this.platform.quoteQualifiedName(name);
1031
1039
  }
1032
1040
  dropForeignKey(tableName, constraintName) {
1033
1041
  return `alter table ${this.quote(tableName)} drop foreign key ${this.quote(constraintName)}`;
@@ -201,7 +201,7 @@ export class SqlSchemaGenerator extends AbstractSchemaGenerator {
201
201
  }
202
202
  }
203
203
  if (options.dropMigrationsTable) {
204
- const [schema, name] = this.helper.splitTableName(this.config.get('migrations').tableName);
204
+ const [schema, name] = this.helper.splitQualifiedName(this.config.get('migrations').tableName);
205
205
  this.append(ret, this.helper.dropTableIfExists(name, schema ?? this.config.get('schema')));
206
206
  }
207
207
  return this.wrapSchema(ret, options);
@@ -521,7 +521,7 @@ export class SqlSchemaGenerator extends AbstractSchemaGenerator {
521
521
  return false;
522
522
  }
523
523
  async dropTableIfExists(name, schema) {
524
- const [schemaName, tableName] = schema ? [schema, name] : this.helper.splitTableName(name);
524
+ const [schemaName, tableName] = this.helper.splitQualifiedName(schema ? `${schema}.${name}` : name);
525
525
  const sql = this.helper.dropTableIfExists(tableName, schemaName);
526
526
  return this.execute(sql);
527
527
  }