@mikro-orm/postgresql 6.3.8-dev.2 → 6.3.8-dev.3

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.
@@ -17,13 +17,13 @@ export declare class PostgreSqlSchemaHelper extends SchemaHelper {
17
17
  private getIgnoredNamespacesConditionSQL;
18
18
  loadInformationSchema(schema: DatabaseSchema, connection: AbstractSqlConnection, tables: Table[], schemas?: string[]): Promise<void>;
19
19
  getAllIndexes(connection: AbstractSqlConnection, tables: Table[]): Promise<Dictionary<IndexDef[]>>;
20
- getAllColumns(connection: AbstractSqlConnection, tables: Table[], nativeEnums?: Dictionary<{
20
+ getAllColumns(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>, nativeEnums?: Dictionary<{
21
21
  name: string;
22
22
  schema?: string;
23
23
  items: string[];
24
24
  }>): Promise<Dictionary<Column[]>>;
25
- getAllChecks(connection: AbstractSqlConnection, tables: Table[]): Promise<Dictionary<CheckDef[]>>;
26
- getAllForeignKeys(connection: AbstractSqlConnection, tables: Table[]): Promise<Dictionary<Dictionary<ForeignKey>>>;
25
+ getAllChecks(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>): Promise<Dictionary<CheckDef[]>>;
26
+ getAllForeignKeys(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>): Promise<Dictionary<Dictionary<ForeignKey>>>;
27
27
  getNativeEnumDefinitions(connection: AbstractSqlConnection, schemas: string[]): Promise<Dictionary<{
28
28
  name: string;
29
29
  schema?: string;
@@ -58,10 +58,11 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
58
58
  if (tables.length === 0) {
59
59
  return;
60
60
  }
61
- const columns = await this.getAllColumns(connection, tables, nativeEnums);
61
+ const tablesBySchema = this.getTablesGroupedBySchemas(tables);
62
+ const columns = await this.getAllColumns(connection, tablesBySchema, nativeEnums);
62
63
  const indexes = await this.getAllIndexes(connection, tables);
63
- const checks = await this.getAllChecks(connection, tables);
64
- const fks = await this.getAllForeignKeys(connection, tables);
64
+ const checks = await this.getAllChecks(connection, tablesBySchema);
65
+ const fks = await this.getAllForeignKeys(connection, tablesBySchema);
65
66
  for (const t of tables) {
66
67
  const key = this.getTableKey(t);
67
68
  const table = schema.addTable(t.table_name, t.schema_name, t.table_comment);
@@ -100,7 +101,7 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
100
101
  }
101
102
  return ret;
102
103
  }
103
- async getAllColumns(connection, tables, nativeEnums) {
104
+ async getAllColumns(connection, tablesBySchemas, nativeEnums) {
104
105
  const sql = `select table_schema as schema_name, table_name, column_name,
105
106
  column_default,
106
107
  is_nullable,
@@ -117,7 +118,7 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
117
118
  from information_schema.columns cols
118
119
  join pg_class pgc on cols.table_name = pgc.relname
119
120
  join pg_attribute pga on pgc.oid = pga.attrelid and cols.column_name = pga.attname
120
- where (${tables.map(t => `(table_schema = ${this.platform.quoteValue(t.schema_name)} and table_name = ${this.platform.quoteValue(t.table_name)})`).join(' or ')})
121
+ where (${[...tablesBySchemas.entries()].map(([schema, tables]) => `(table_schema = ${this.platform.quoteValue(schema)} and table_name in (${tables.map(t => this.platform.quoteValue(t.table_name)).join(',')}))`).join(' or ')})
121
122
  order by ordinal_position`;
122
123
  const allColumns = await connection.execute(sql);
123
124
  const str = (val) => val != null ? '' + val : val;
@@ -166,8 +167,8 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
166
167
  }
167
168
  return ret;
168
169
  }
169
- async getAllChecks(connection, tables) {
170
- const sql = this.getChecksSQL(tables);
170
+ async getAllChecks(connection, tablesBySchemas) {
171
+ const sql = this.getChecksSQL(tablesBySchemas);
171
172
  const allChecks = await connection.execute(sql);
172
173
  const ret = {};
173
174
  for (const check of allChecks) {
@@ -184,7 +185,7 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
184
185
  }
185
186
  return ret;
186
187
  }
187
- async getAllForeignKeys(connection, tables) {
188
+ async getAllForeignKeys(connection, tablesBySchemas) {
188
189
  const sql = `select nsp1.nspname schema_name, cls1.relname table_name, nsp2.nspname referenced_schema_name,
189
190
  cls2.relname referenced_table_name, a.attname column_name, af.attname referenced_column_name, conname constraint_name,
190
191
  confupdtype update_rule, confdeltype delete_rule, array_position(con.conkey,a.attnum) as ord, condeferrable, condeferred,
@@ -196,7 +197,7 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
196
197
  join pg_class cls1 on cls1.oid = con.conrelid
197
198
  join pg_class cls2 on cls2.oid = confrelid
198
199
  join pg_namespace nsp2 on nsp2.oid = cls2.relnamespace
199
- where (${tables.map(t => `(cls1.relname = ${this.platform.quoteValue(t.table_name)} and nsp1.nspname = ${this.platform.quoteValue(t.schema_name)})`).join(' or ')})
200
+ where (${[...tablesBySchemas.entries()].map(([schema, tables]) => `(cls1.relname in (${tables.map(t => this.platform.quoteValue(t.table_name)).join(',')}) and nsp1.nspname = ${this.platform.quoteValue(schema)})`).join(' or ')})
200
201
  and confrelid > 0
201
202
  order by nsp1.nspname, cls1.relname, constraint_name, ord`;
202
203
  const allFks = await connection.execute(sql);
@@ -495,23 +496,23 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
495
496
  where indrelid in (${tables.map(t => `${this.platform.quoteValue(`${this.platform.quoteIdentifier(t.schema_name ?? this.platform.getDefaultSchemaName() ?? '')}.${this.platform.quoteIdentifier(t.table_name)}`)}::regclass`).join(', ')})
496
497
  order by relname`;
497
498
  }
498
- getChecksSQL(tables) {
499
+ getChecksSQL(tablesBySchemas) {
499
500
  return `select ccu.table_name as table_name, ccu.table_schema as schema_name, pgc.conname as name, conrelid::regclass as table_from, ccu.column_name as column_name, pg_get_constraintdef(pgc.oid) as expression
500
501
  from pg_constraint pgc
501
502
  join pg_namespace nsp on nsp.oid = pgc.connamespace
502
503
  join pg_class cls on pgc.conrelid = cls.oid
503
504
  join information_schema.constraint_column_usage ccu on pgc.conname = ccu.constraint_name and nsp.nspname = ccu.constraint_schema
504
- where contype = 'c' and (${tables.map(t => `ccu.table_name = ${this.platform.quoteValue(t.table_name)} and ccu.table_schema = ${this.platform.quoteValue(t.schema_name ?? this.platform.getDefaultSchemaName() ?? '')}`).join(' or ')})
505
+ where contype = 'c' and (${[...tablesBySchemas.entries()].map(([schema, tables]) => `ccu.table_name in (${tables.map(t => this.platform.quoteValue(t.table_name)).join(',')}) and ccu.table_schema = ${this.platform.quoteValue(schema ?? this.platform.getDefaultSchemaName() ?? '')}`).join(' or ')})
505
506
  order by pgc.conname`;
506
507
  }
507
508
  /* istanbul ignore next */
508
509
  async getChecks(connection, tableName, schemaName, columns) {
509
- const res = await this.getAllChecks(connection, [{ table_name: tableName, schema_name: schemaName }]);
510
+ const res = await this.getAllChecks(connection, new Map([[schemaName, [{ table_name: tableName, schema_name: schemaName }]]]));
510
511
  return res[tableName];
511
512
  }
512
513
  /* istanbul ignore next */
513
514
  async getColumns(connection, tableName, schemaName) {
514
- const res = await this.getAllColumns(connection, [{ table_name: tableName, schema_name: schemaName }]);
515
+ const res = await this.getAllColumns(connection, new Map([[schemaName, [{ table_name: tableName, schema_name: schemaName }]]]));
515
516
  return res[tableName];
516
517
  }
517
518
  /* istanbul ignore next */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/postgresql",
3
- "version": "6.3.8-dev.2",
3
+ "version": "6.3.8-dev.3",
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.8-dev.2",
61
+ "@mikro-orm/knex": "6.3.8-dev.3",
62
62
  "pg": "8.12.0",
63
63
  "postgres-array": "3.0.2",
64
64
  "postgres-date": "2.1.0",
@@ -68,6 +68,6 @@
68
68
  "@mikro-orm/core": "^6.3.7"
69
69
  },
70
70
  "peerDependencies": {
71
- "@mikro-orm/core": "6.3.8-dev.2"
71
+ "@mikro-orm/core": "6.3.8-dev.3"
72
72
  }
73
73
  }