@mikro-orm/postgresql 6.2.10-dev.9 → 6.2.10-dev.91
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 +2 -2
- package/PostgreSqlPlatform.d.ts +6 -6
- package/PostgreSqlPlatform.js +22 -10
- package/PostgreSqlSchemaHelper.d.ts +1 -0
- package/PostgreSqlSchemaHelper.js +43 -10
- package/index.mjs +1 -0
- package/package.json +4 -4
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,12 @@ 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;
|
|
61
|
+
getCharTypeDeclarationSQL(column: {
|
|
62
|
+
length?: number;
|
|
63
|
+
}): string;
|
|
64
64
|
getBlobDeclarationSQL(): string;
|
|
65
65
|
getJsonDeclarationSQL(): string;
|
|
66
66
|
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
|
}
|
|
@@ -153,8 +145,27 @@ class PostgreSqlPlatform extends knex_1.AbstractSqlPlatform {
|
|
|
153
145
|
if (value === '{}') {
|
|
154
146
|
return [];
|
|
155
147
|
}
|
|
156
|
-
|
|
157
|
-
|
|
148
|
+
return value.substring(1, value.length - 1).split(',').map(v => {
|
|
149
|
+
if (v === `""`) {
|
|
150
|
+
return '';
|
|
151
|
+
}
|
|
152
|
+
if (v.match(/"(.*)"/)) {
|
|
153
|
+
return v.substring(1, v.length - 1).replaceAll('\\"', '"');
|
|
154
|
+
}
|
|
155
|
+
return v;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
getVarcharTypeDeclarationSQL(column) {
|
|
159
|
+
if (column.length === -1) {
|
|
160
|
+
return 'varchar';
|
|
161
|
+
}
|
|
162
|
+
return super.getVarcharTypeDeclarationSQL(column);
|
|
163
|
+
}
|
|
164
|
+
getCharTypeDeclarationSQL(column) {
|
|
165
|
+
if (column.length === -1) {
|
|
166
|
+
return 'char';
|
|
167
|
+
}
|
|
168
|
+
return super.getCharTypeDeclarationSQL(column);
|
|
158
169
|
}
|
|
159
170
|
getBlobDeclarationSQL() {
|
|
160
171
|
return 'bytea';
|
|
@@ -242,6 +253,7 @@ class PostgreSqlPlatform extends knex_1.AbstractSqlPlatform {
|
|
|
242
253
|
'bytea': 'blob',
|
|
243
254
|
'jsonb': 'json',
|
|
244
255
|
'character varying': 'varchar',
|
|
256
|
+
'bpchar': 'character',
|
|
245
257
|
};
|
|
246
258
|
return super.getDefaultMappedType(map[normalizedType] ?? type);
|
|
247
259
|
}
|
|
@@ -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) {
|
|
@@ -105,16 +106,17 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
105
106
|
is_nullable,
|
|
106
107
|
udt_name,
|
|
107
108
|
coalesce(datetime_precision, character_maximum_length) length,
|
|
109
|
+
atttypmod custom_length,
|
|
108
110
|
numeric_precision,
|
|
109
111
|
numeric_scale,
|
|
110
112
|
data_type,
|
|
111
113
|
is_identity,
|
|
112
114
|
identity_generation,
|
|
113
115
|
generation_expression,
|
|
114
|
-
|
|
115
|
-
from pg_catalog.pg_class c
|
|
116
|
-
where c.oid = (select ('"' || cols.table_schema || '"."' || cols.table_name || '"')::regclass::oid) and c.relname = cols.table_name) as column_comment
|
|
116
|
+
pg_catalog.col_description(pgc.oid, cols.ordinal_position::int) column_comment
|
|
117
117
|
from information_schema.columns cols
|
|
118
|
+
join pg_class pgc on cols.table_name = pgc.relname
|
|
119
|
+
join pg_attribute pga on pgc.oid = pga.attrelid and cols.column_name = pga.attname
|
|
118
120
|
where (${tables.map(t => `(table_schema = ${this.platform.quoteValue(t.schema_name)} and table_name = ${this.platform.quoteValue(t.table_name)})`).join(' or ')})
|
|
119
121
|
order by ordinal_position`;
|
|
120
122
|
const allColumns = await connection.execute(sql);
|
|
@@ -128,17 +130,21 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
128
130
|
let type = col.data_type.toLowerCase() === 'array'
|
|
129
131
|
? col.udt_name.replace(/^_(.*)$/, '$1[]')
|
|
130
132
|
: col.udt_name;
|
|
133
|
+
if (type === 'vector' && col.length == null && col.custom_length != null) {
|
|
134
|
+
col.length = col.custom_length;
|
|
135
|
+
}
|
|
131
136
|
if (col.length != null && !type.endsWith(`(${col.length})`)) {
|
|
132
137
|
type += `(${col.length})`;
|
|
133
138
|
}
|
|
134
139
|
if (type === 'numeric' && col.numeric_precision != null && col.numeric_scale != null) {
|
|
135
140
|
type += `(${col.numeric_precision},${col.numeric_scale})`;
|
|
136
141
|
}
|
|
142
|
+
const length = this.inferLengthFromColumnType(type) === -1 ? -1 : col.length;
|
|
137
143
|
const column = {
|
|
138
144
|
name: col.column_name,
|
|
139
145
|
type,
|
|
140
146
|
mappedType,
|
|
141
|
-
length
|
|
147
|
+
length,
|
|
142
148
|
precision: col.numeric_precision,
|
|
143
149
|
scale: col.numeric_scale,
|
|
144
150
|
nullable: col.is_nullable === 'YES',
|
|
@@ -178,7 +184,8 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
178
184
|
async getAllForeignKeys(connection, tables) {
|
|
179
185
|
const sql = `select nsp1.nspname schema_name, cls1.relname table_name, nsp2.nspname referenced_schema_name,
|
|
180
186
|
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
|
|
187
|
+
confupdtype update_rule, confdeltype delete_rule, array_position(con.conkey,a.attnum) as ord, condeferrable, condeferred,
|
|
188
|
+
pg_get_constraintdef(con.oid) as constraint_def
|
|
182
189
|
from pg_attribute a
|
|
183
190
|
join pg_constraint con on con.conrelid = a.attrelid AND a.attnum = ANY (con.conkey)
|
|
184
191
|
join pg_attribute af on af.attnum = con.confkey[array_position(con.conkey,a.attnum)] AND af.attrelid = con.confrelid
|
|
@@ -191,7 +198,11 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
191
198
|
order by nsp1.nspname, cls1.relname, constraint_name, ord`;
|
|
192
199
|
const allFks = await connection.execute(sql);
|
|
193
200
|
const ret = {};
|
|
194
|
-
function
|
|
201
|
+
function mapReferentialIntegrity(value, def) {
|
|
202
|
+
const match = ['n', 'd'].includes(value) && def.match(/ON DELETE (SET (NULL|DEFAULT) \(.*?\))/);
|
|
203
|
+
if (match) {
|
|
204
|
+
return match[1];
|
|
205
|
+
}
|
|
195
206
|
switch (value) {
|
|
196
207
|
case 'r': return 'RESTRICT';
|
|
197
208
|
case 'c': return 'CASCADE';
|
|
@@ -202,8 +213,8 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
202
213
|
}
|
|
203
214
|
}
|
|
204
215
|
for (const fk of allFks) {
|
|
205
|
-
fk.update_rule =
|
|
206
|
-
fk.delete_rule =
|
|
216
|
+
fk.update_rule = mapReferentialIntegrity(fk.update_rule, fk.constraint_def);
|
|
217
|
+
fk.delete_rule = mapReferentialIntegrity(fk.delete_rule, fk.constraint_def);
|
|
207
218
|
if (fk.condeferrable) {
|
|
208
219
|
fk.defer_mode = fk.condeferred ? core_1.DeferMode.INITIALLY_DEFERRED : core_1.DeferMode.INITIALLY_IMMEDIATE;
|
|
209
220
|
}
|
|
@@ -268,7 +279,7 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
268
279
|
const m1 = item.definition?.match(/check \(\(\("?(\w+)"?\)::/i) || item.definition?.match(/check \(\("?(\w+)"? = /i);
|
|
269
280
|
const m2 = item.definition?.match(/\(array\[(.*)]\)/i) || item.definition?.match(/ = (.*)\)/i);
|
|
270
281
|
if (item.columnName && m1 && m2) {
|
|
271
|
-
const m3 = m2[1].match(/('[^']
|
|
282
|
+
const m3 = m2[1].match(/('[^']*'::text)/g);
|
|
272
283
|
let items;
|
|
273
284
|
/* istanbul ignore else */
|
|
274
285
|
if (m3) {
|
|
@@ -277,7 +288,7 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
277
288
|
else {
|
|
278
289
|
items = m2[1].split(',').map((item) => item.trim().match(/^\(?'(.*)'/)?.[1]);
|
|
279
290
|
}
|
|
280
|
-
items = items.filter(
|
|
291
|
+
items = items.filter(item => item !== undefined);
|
|
281
292
|
if (items.length > 0) {
|
|
282
293
|
o[item.columnName] = items;
|
|
283
294
|
found.push(index);
|
|
@@ -494,5 +505,27 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
|
|
|
494
505
|
const res = await this.getAllIndexes(connection, [{ table_name: tableName, schema_name: schemaName }]);
|
|
495
506
|
return res[tableName];
|
|
496
507
|
}
|
|
508
|
+
inferLengthFromColumnType(type) {
|
|
509
|
+
const match = type.match(/^(\w+(?:\s+\w+)*)\s*(?:\(\s*(\d+)\s*\)|$)/);
|
|
510
|
+
if (!match) {
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
if (!match[2]) {
|
|
514
|
+
switch (match[1]) {
|
|
515
|
+
case 'character varying':
|
|
516
|
+
case 'varchar':
|
|
517
|
+
case 'bpchar':
|
|
518
|
+
case 'char':
|
|
519
|
+
case 'character':
|
|
520
|
+
return -1;
|
|
521
|
+
case 'interval':
|
|
522
|
+
case 'time':
|
|
523
|
+
case 'timestamptz':
|
|
524
|
+
return this.platform.getDefaultDateTimeLength();
|
|
525
|
+
}
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
return +match[2];
|
|
529
|
+
}
|
|
497
530
|
}
|
|
498
531
|
exports.PostgreSqlSchemaHelper = PostgreSqlSchemaHelper;
|
package/index.mjs
CHANGED
|
@@ -33,6 +33,7 @@ export const ChangeSet = mod.ChangeSet;
|
|
|
33
33
|
export const ChangeSetComputer = mod.ChangeSetComputer;
|
|
34
34
|
export const ChangeSetPersister = mod.ChangeSetPersister;
|
|
35
35
|
export const ChangeSetType = mod.ChangeSetType;
|
|
36
|
+
export const CharacterType = mod.CharacterType;
|
|
36
37
|
export const Check = mod.Check;
|
|
37
38
|
export const CheckConstraintViolationException = mod.CheckConstraintViolationException;
|
|
38
39
|
export const Collection = mod.Collection;
|
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.91",
|
|
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.91",
|
|
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.91"
|
|
72
72
|
}
|
|
73
73
|
}
|