@mikro-orm/postgresql 6.2.10-dev.7 → 6.2.10-dev.70
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/PostgreSqlMikroORM.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.PostgreSqlMikroORM = void 0;
|
|
4
|
+
exports.definePostgreSqlConfig = definePostgreSqlConfig;
|
|
4
5
|
const core_1 = require("@mikro-orm/core");
|
|
5
6
|
const PostgreSqlDriver_1 = require("./PostgreSqlDriver");
|
|
6
7
|
/**
|
|
@@ -26,4 +27,3 @@ exports.PostgreSqlMikroORM = PostgreSqlMikroORM;
|
|
|
26
27
|
function definePostgreSqlConfig(options) {
|
|
27
28
|
return (0, core_1.defineConfig)({ driver: PostgreSqlDriver_1.PostgreSqlDriver, ...options });
|
|
28
29
|
}
|
|
29
|
-
exports.definePostgreSqlConfig = definePostgreSqlConfig;
|
package/PostgreSqlPlatform.d.ts
CHANGED
|
@@ -10,12 +10,6 @@ export declare class PostgreSqlPlatform extends AbstractSqlPlatform {
|
|
|
10
10
|
usesCascadeStatement(): boolean;
|
|
11
11
|
supportsNativeEnums(): boolean;
|
|
12
12
|
supportsCustomPrimaryKeyNames(): boolean;
|
|
13
|
-
/**
|
|
14
|
-
* Postgres will complain if we try to batch update uniquely constrained property (moving the value from one entity to another).
|
|
15
|
-
* This flag will result in postponing 1:1 updates (removing them from the batched query).
|
|
16
|
-
* @see https://stackoverflow.com/questions/5403437/atomic-multi-row-update-with-a-unique-constraint
|
|
17
|
-
*/
|
|
18
|
-
allowsUniqueBatchUpdates(): boolean;
|
|
19
13
|
getCurrentTimestampSQL(length: number): string;
|
|
20
14
|
getDateTimeTypeDeclarationSQL(column: {
|
|
21
15
|
length?: number;
|
|
@@ -61,6 +55,9 @@ export declare class PostgreSqlPlatform extends AbstractSqlPlatform {
|
|
|
61
55
|
supportsMultipleStatements(): boolean;
|
|
62
56
|
marshallArray(values: string[]): string;
|
|
63
57
|
unmarshallArray(value: string): string[];
|
|
58
|
+
getVarcharTypeDeclarationSQL(column: {
|
|
59
|
+
length?: number;
|
|
60
|
+
}): string;
|
|
64
61
|
getBlobDeclarationSQL(): string;
|
|
65
62
|
getJsonDeclarationSQL(): string;
|
|
66
63
|
getSearchJsonPropertyKey(path: string[], type: string | undefined | Type, aliased: boolean, value?: unknown): string;
|
package/PostgreSqlPlatform.js
CHANGED
|
@@ -27,14 +27,6 @@ class PostgreSqlPlatform extends knex_1.AbstractSqlPlatform {
|
|
|
27
27
|
supportsCustomPrimaryKeyNames() {
|
|
28
28
|
return true;
|
|
29
29
|
}
|
|
30
|
-
/**
|
|
31
|
-
* Postgres will complain if we try to batch update uniquely constrained property (moving the value from one entity to another).
|
|
32
|
-
* This flag will result in postponing 1:1 updates (removing them from the batched query).
|
|
33
|
-
* @see https://stackoverflow.com/questions/5403437/atomic-multi-row-update-with-a-unique-constraint
|
|
34
|
-
*/
|
|
35
|
-
allowsUniqueBatchUpdates() {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
30
|
getCurrentTimestampSQL(length) {
|
|
39
31
|
return `current_timestamp(${length})`;
|
|
40
32
|
}
|
|
@@ -156,6 +148,12 @@ class PostgreSqlPlatform extends knex_1.AbstractSqlPlatform {
|
|
|
156
148
|
/* istanbul ignore next */
|
|
157
149
|
return value.substring(1, value.length - 1).split(',').map(v => v === `""` ? '' : v);
|
|
158
150
|
}
|
|
151
|
+
getVarcharTypeDeclarationSQL(column) {
|
|
152
|
+
if (column.length === -1) {
|
|
153
|
+
return 'varchar';
|
|
154
|
+
}
|
|
155
|
+
return super.getVarcharTypeDeclarationSQL(column);
|
|
156
|
+
}
|
|
159
157
|
getBlobDeclarationSQL() {
|
|
160
158
|
return 'bytea';
|
|
161
159
|
}
|
|
@@ -51,4 +51,5 @@ export declare class PostgreSqlSchemaHelper extends SchemaHelper {
|
|
|
51
51
|
getChecks(connection: AbstractSqlConnection, tableName: string, schemaName: string, columns?: Column[]): Promise<CheckDef[]>;
|
|
52
52
|
getColumns(connection: AbstractSqlConnection, tableName: string, schemaName?: string): Promise<Column[]>;
|
|
53
53
|
getIndexes(connection: AbstractSqlConnection, tableName: string, schemaName?: string): Promise<IndexDef[]>;
|
|
54
|
+
inferLengthFromColumnType(type: string): number | undefined;
|
|
54
55
|
}
|
|
@@ -26,6 +26,7 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
26
26
|
+ `from information_schema.tables `
|
|
27
27
|
+ `where ${this.getIgnoredNamespacesConditionSQL('table_schema')} `
|
|
28
28
|
+ `and table_name != 'geometry_columns' and table_name != 'spatial_ref_sys' and table_type != 'VIEW' `
|
|
29
|
+
+ `and table_name not in (select inhrelid::regclass::text from pg_inherits) `
|
|
29
30
|
+ `order by table_name`;
|
|
30
31
|
}
|
|
31
32
|
async getNamespaces(connection) {
|
|
@@ -134,11 +135,12 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
134
135
|
if (type === 'numeric' && col.numeric_precision != null && col.numeric_scale != null) {
|
|
135
136
|
type += `(${col.numeric_precision},${col.numeric_scale})`;
|
|
136
137
|
}
|
|
138
|
+
const length = this.inferLengthFromColumnType(type) === -1 ? -1 : col.length;
|
|
137
139
|
const column = {
|
|
138
140
|
name: col.column_name,
|
|
139
141
|
type,
|
|
140
142
|
mappedType,
|
|
141
|
-
length
|
|
143
|
+
length,
|
|
142
144
|
precision: col.numeric_precision,
|
|
143
145
|
scale: col.numeric_scale,
|
|
144
146
|
nullable: col.is_nullable === 'YES',
|
|
@@ -178,7 +180,8 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
178
180
|
async getAllForeignKeys(connection, tables) {
|
|
179
181
|
const sql = `select nsp1.nspname schema_name, cls1.relname table_name, nsp2.nspname referenced_schema_name,
|
|
180
182
|
cls2.relname referenced_table_name, a.attname column_name, af.attname referenced_column_name, conname constraint_name,
|
|
181
|
-
confupdtype update_rule, confdeltype delete_rule, array_position(con.conkey,a.attnum) as ord, condeferrable, condeferred
|
|
183
|
+
confupdtype update_rule, confdeltype delete_rule, array_position(con.conkey,a.attnum) as ord, condeferrable, condeferred,
|
|
184
|
+
pg_get_constraintdef(con.oid) as constraint_def
|
|
182
185
|
from pg_attribute a
|
|
183
186
|
join pg_constraint con on con.conrelid = a.attrelid AND a.attnum = ANY (con.conkey)
|
|
184
187
|
join pg_attribute af on af.attnum = con.confkey[array_position(con.conkey,a.attnum)] AND af.attrelid = con.confrelid
|
|
@@ -191,7 +194,11 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
191
194
|
order by nsp1.nspname, cls1.relname, constraint_name, ord`;
|
|
192
195
|
const allFks = await connection.execute(sql);
|
|
193
196
|
const ret = {};
|
|
194
|
-
function
|
|
197
|
+
function mapReferentialIntegrity(value, def) {
|
|
198
|
+
const match = ['n', 'd'].includes(value) && def.match(/ON DELETE (SET (NULL|DEFAULT) \(.*?\))/);
|
|
199
|
+
if (match) {
|
|
200
|
+
return match[1];
|
|
201
|
+
}
|
|
195
202
|
switch (value) {
|
|
196
203
|
case 'r': return 'RESTRICT';
|
|
197
204
|
case 'c': return 'CASCADE';
|
|
@@ -202,8 +209,8 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
202
209
|
}
|
|
203
210
|
}
|
|
204
211
|
for (const fk of allFks) {
|
|
205
|
-
fk.update_rule =
|
|
206
|
-
fk.delete_rule =
|
|
212
|
+
fk.update_rule = mapReferentialIntegrity(fk.update_rule, fk.constraint_def);
|
|
213
|
+
fk.delete_rule = mapReferentialIntegrity(fk.delete_rule, fk.constraint_def);
|
|
207
214
|
if (fk.condeferrable) {
|
|
208
215
|
fk.defer_mode = fk.condeferred ? core_1.DeferMode.INITIALLY_DEFERRED : core_1.DeferMode.INITIALLY_IMMEDIATE;
|
|
209
216
|
}
|
|
@@ -268,7 +275,7 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
268
275
|
const m1 = item.definition?.match(/check \(\(\("?(\w+)"?\)::/i) || item.definition?.match(/check \(\("?(\w+)"? = /i);
|
|
269
276
|
const m2 = item.definition?.match(/\(array\[(.*)]\)/i) || item.definition?.match(/ = (.*)\)/i);
|
|
270
277
|
if (item.columnName && m1 && m2) {
|
|
271
|
-
const m3 = m2[1].match(/('[^']
|
|
278
|
+
const m3 = m2[1].match(/('[^']*'::text)/g);
|
|
272
279
|
let items;
|
|
273
280
|
/* istanbul ignore else */
|
|
274
281
|
if (m3) {
|
|
@@ -277,7 +284,7 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
277
284
|
else {
|
|
278
285
|
items = m2[1].split(',').map((item) => item.trim().match(/^\(?'(.*)'/)?.[1]);
|
|
279
286
|
}
|
|
280
|
-
items = items.filter(
|
|
287
|
+
items = items.filter(item => item !== undefined);
|
|
281
288
|
if (items.length > 0) {
|
|
282
289
|
o[item.columnName] = items;
|
|
283
290
|
found.push(index);
|
|
@@ -494,5 +501,15 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
494
501
|
const res = await this.getAllIndexes(connection, [{ table_name: tableName, schema_name: schemaName }]);
|
|
495
502
|
return res[tableName];
|
|
496
503
|
}
|
|
504
|
+
inferLengthFromColumnType(type) {
|
|
505
|
+
const match = type.match(/^(varchar|character varying)\s*(?:\(\s*(\d+)\s*\))?/);
|
|
506
|
+
if (!match) {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
if (!match[2]) {
|
|
510
|
+
return -1;
|
|
511
|
+
}
|
|
512
|
+
return +match[2];
|
|
513
|
+
}
|
|
497
514
|
}
|
|
498
515
|
exports.PostgreSqlSchemaHelper = PostgreSqlSchemaHelper;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/postgresql",
|
|
3
|
-
"version": "6.2.10-dev.
|
|
3
|
+
"version": "6.2.10-dev.70",
|
|
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.2.10-dev.
|
|
62
|
-
"pg": "8.
|
|
61
|
+
"@mikro-orm/knex": "6.2.10-dev.70",
|
|
62
|
+
"pg": "8.12.0",
|
|
63
63
|
"postgres-array": "3.0.2",
|
|
64
64
|
"postgres-date": "2.1.0",
|
|
65
65
|
"postgres-interval": "4.0.2"
|
|
@@ -68,6 +68,6 @@
|
|
|
68
68
|
"@mikro-orm/core": "^6.2.9"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
|
-
"@mikro-orm/core": "6.2.10-dev.
|
|
71
|
+
"@mikro-orm/core": "6.2.10-dev.70"
|
|
72
72
|
}
|
|
73
73
|
}
|