@mikro-orm/postgresql 6.6.11-dev.0 → 6.6.11-dev.2

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.
@@ -1,4 +1,4 @@
1
- import { type Dictionary } from '@mikro-orm/core';
1
+ import { type Transaction, type Dictionary } from '@mikro-orm/core';
2
2
  import { SchemaHelper, type AbstractSqlConnection, type CheckDef, type Column, type DatabaseSchema, type DatabaseTable, type ForeignKey, type IndexDef, type Knex, type Table, type TableDifference } from '@mikro-orm/knex';
3
3
  export declare class PostgreSqlSchemaHelper extends SchemaHelper {
4
4
  static readonly DEFAULT_VALUES: {
@@ -13,18 +13,18 @@ export declare class PostgreSqlSchemaHelper extends SchemaHelper {
13
13
  getSchemaBeginning(charset: string, disableForeignKeys?: boolean): string;
14
14
  getCreateDatabaseSQL(name: string): string;
15
15
  getListTablesSQL(): string;
16
- getNamespaces(connection: AbstractSqlConnection): Promise<string[]>;
16
+ getNamespaces(connection: AbstractSqlConnection, ctx?: Transaction): Promise<string[]>;
17
17
  private getIgnoredNamespacesConditionSQL;
18
- loadInformationSchema(schema: DatabaseSchema, connection: AbstractSqlConnection, tables: Table[], schemas?: string[]): Promise<void>;
19
- getAllIndexes(connection: AbstractSqlConnection, tables: Table[]): Promise<Dictionary<IndexDef[]>>;
18
+ loadInformationSchema(schema: DatabaseSchema, connection: AbstractSqlConnection, tables: Table[], schemas?: string[], ctx?: Transaction): Promise<void>;
19
+ getAllIndexes(connection: AbstractSqlConnection, tables: Table[], ctx?: Transaction): Promise<Dictionary<IndexDef[]>>;
20
20
  getAllColumns(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>, nativeEnums?: Dictionary<{
21
21
  name: string;
22
22
  schema?: string;
23
23
  items: string[];
24
- }>): Promise<Dictionary<Column[]>>;
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
- getNativeEnumDefinitions(connection: AbstractSqlConnection, schemas: string[]): Promise<Dictionary<{
24
+ }>, ctx?: Transaction): Promise<Dictionary<Column[]>>;
25
+ getAllChecks(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>, ctx?: Transaction): Promise<Dictionary<CheckDef[]>>;
26
+ getAllForeignKeys(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>, ctx?: Transaction): Promise<Dictionary<Dictionary<ForeignKey>>>;
27
+ getNativeEnumDefinitions(connection: AbstractSqlConnection, schemas: string[], ctx?: Transaction): Promise<Dictionary<{
28
28
  name: string;
29
29
  schema?: string;
30
30
  items: string[];
@@ -32,11 +32,11 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
32
32
  + `and table_name not in (select inhrelid::regclass::text from pg_inherits) `
33
33
  + `order by table_name`;
34
34
  }
35
- async getNamespaces(connection) {
35
+ async getNamespaces(connection, ctx) {
36
36
  const sql = `select schema_name from information_schema.schemata `
37
37
  + `where ${this.getIgnoredNamespacesConditionSQL()} `
38
38
  + `order by schema_name`;
39
- const res = await connection.execute(sql);
39
+ const res = await connection.execute(sql, [], 'all', ctx);
40
40
  return res.map(row => row.schema_name);
41
41
  }
42
42
  getIgnoredNamespacesConditionSQL(column = 'schema_name') {
@@ -54,18 +54,18 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
54
54
  ].map(p => `"${column}" not like '${p}%'`).join(' and ');
55
55
  return `${ignoredPrefixes} and "${column}" not in (${ignored})`;
56
56
  }
57
- async loadInformationSchema(schema, connection, tables, schemas) {
57
+ async loadInformationSchema(schema, connection, tables, schemas, ctx) {
58
58
  schemas ??= tables.length === 0 ? [schema.name] : tables.map(t => t.schema_name ?? schema.name);
59
- const nativeEnums = await this.getNativeEnumDefinitions(connection, schemas);
59
+ const nativeEnums = await this.getNativeEnumDefinitions(connection, schemas, ctx);
60
60
  schema.setNativeEnums(nativeEnums);
61
61
  if (tables.length === 0) {
62
62
  return;
63
63
  }
64
64
  const tablesBySchema = this.getTablesGroupedBySchemas(tables);
65
- const columns = await this.getAllColumns(connection, tablesBySchema, nativeEnums);
66
- const indexes = await this.getAllIndexes(connection, tables);
67
- const checks = await this.getAllChecks(connection, tablesBySchema);
68
- const fks = await this.getAllForeignKeys(connection, tablesBySchema);
65
+ const columns = await this.getAllColumns(connection, tablesBySchema, nativeEnums, ctx);
66
+ const indexes = await this.getAllIndexes(connection, tables, ctx);
67
+ const checks = await this.getAllChecks(connection, tablesBySchema, ctx);
68
+ const fks = await this.getAllForeignKeys(connection, tablesBySchema, ctx);
69
69
  for (const t of tables) {
70
70
  const key = this.getTableKey(t);
71
71
  const table = schema.addTable(t.table_name, t.schema_name, t.table_comment);
@@ -76,10 +76,10 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
76
76
  }
77
77
  }
78
78
  }
79
- async getAllIndexes(connection, tables) {
79
+ async getAllIndexes(connection, tables, ctx) {
80
80
  const sql = this.getIndexesSQL(tables);
81
81
  const unquote = (str) => str.replace(/['"`]/g, '');
82
- const allIndexes = await connection.execute(sql);
82
+ const allIndexes = await connection.execute(sql, [], 'all', ctx);
83
83
  const ret = {};
84
84
  for (const index of allIndexes) {
85
85
  const key = this.getTableKey(index);
@@ -106,7 +106,7 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
106
106
  }
107
107
  return ret;
108
108
  }
109
- async getAllColumns(connection, tablesBySchemas, nativeEnums) {
109
+ async getAllColumns(connection, tablesBySchemas, nativeEnums, ctx) {
110
110
  const sql = `select table_schema as schema_name, table_name, column_name,
111
111
  column_default,
112
112
  is_nullable,
@@ -126,7 +126,7 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
126
126
  join pg_attribute pga on pgc.oid = pga.attrelid and cols.column_name = pga.attname
127
127
  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 ')})
128
128
  order by ordinal_position`;
129
- const allColumns = await connection.execute(sql);
129
+ const allColumns = await connection.execute(sql, [], 'all', ctx);
130
130
  const str = (val) => val != null ? '' + val : val;
131
131
  const ret = {};
132
132
  for (const col of allColumns) {
@@ -176,9 +176,9 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
176
176
  }
177
177
  return ret;
178
178
  }
179
- async getAllChecks(connection, tablesBySchemas) {
179
+ async getAllChecks(connection, tablesBySchemas, ctx) {
180
180
  const sql = this.getChecksSQL(tablesBySchemas);
181
- const allChecks = await connection.execute(sql);
181
+ const allChecks = await connection.execute(sql, [], 'all', ctx);
182
182
  const ret = {};
183
183
  const seen = new Set();
184
184
  for (const check of allChecks) {
@@ -200,7 +200,7 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
200
200
  }
201
201
  return ret;
202
202
  }
203
- async getAllForeignKeys(connection, tablesBySchemas) {
203
+ async getAllForeignKeys(connection, tablesBySchemas, ctx) {
204
204
  const sql = `select nsp1.nspname schema_name, cls1.relname table_name, nsp2.nspname referenced_schema_name,
205
205
  cls2.relname referenced_table_name, a.attname column_name, af.attname referenced_column_name, conname constraint_name,
206
206
  confupdtype update_rule, confdeltype delete_rule, array_position(con.conkey,a.attnum) as ord, condeferrable, condeferred,
@@ -215,7 +215,7 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
215
215
  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 ')})
216
216
  and confrelid > 0
217
217
  order by nsp1.nspname, cls1.relname, constraint_name, ord`;
218
- const allFks = await connection.execute(sql);
218
+ const allFks = await connection.execute(sql, [], 'all', ctx);
219
219
  const ret = {};
220
220
  function mapReferentialIntegrity(value, def) {
221
221
  const match = ['n', 'd'].includes(value) && def.match(/ON DELETE (SET (NULL|DEFAULT) \(.*?\))/);
@@ -248,14 +248,14 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
248
248
  });
249
249
  return ret;
250
250
  }
251
- async getNativeEnumDefinitions(connection, schemas) {
251
+ async getNativeEnumDefinitions(connection, schemas, ctx) {
252
252
  const uniqueSchemas = core_1.Utils.unique(schemas);
253
253
  const res = await connection.execute(`select t.typname as enum_name, n.nspname as schema_name, array_agg(e.enumlabel order by e.enumsortorder) as enum_value
254
254
  from pg_type t
255
255
  join pg_enum e on t.oid = e.enumtypid
256
256
  join pg_catalog.pg_namespace n on n.oid = t.typnamespace
257
257
  where n.nspname in (${Array(uniqueSchemas.length).fill('?').join(', ')})
258
- group by t.typname, n.nspname`, uniqueSchemas);
258
+ group by t.typname, n.nspname`, uniqueSchemas, 'all', ctx);
259
259
  return res.reduce((o, row) => {
260
260
  let name = row.enum_name;
261
261
  if (row.schema_name && row.schema_name !== this.platform.getDefaultSchemaName()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/postgresql",
3
- "version": "6.6.11-dev.0",
3
+ "version": "6.6.11-dev.2",
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,8 +58,8 @@
58
58
  "access": "public"
59
59
  },
60
60
  "dependencies": {
61
- "@mikro-orm/knex": "6.6.11-dev.0",
62
- "pg": "8.19.0",
61
+ "@mikro-orm/knex": "6.6.11-dev.2",
62
+ "pg": "8.20.0",
63
63
  "postgres-array": "3.0.4",
64
64
  "postgres-date": "2.1.0",
65
65
  "postgres-interval": "4.0.2"
@@ -68,6 +68,6 @@
68
68
  "@mikro-orm/core": "^6.6.10"
69
69
  },
70
70
  "peerDependencies": {
71
- "@mikro-orm/core": "6.6.11-dev.0"
71
+ "@mikro-orm/core": "6.6.11-dev.2"
72
72
  }
73
73
  }