@mikro-orm/sql 7.2.11-dev.11 → 7.2.11-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/dialects/mysql/MySqlSchemaHelper.js +4 -3
- package/dialects/oracledb/OracleDialect.d.ts +1 -4
- package/dialects/oracledb/OracleDialect.js +5 -10
- package/dialects/postgresql/PostgreSqlSchemaHelper.js +2 -2
- package/dialects/sqlite/SqliteSchemaHelper.js +9 -8
- package/package.json +2 -2
- package/schema/DatabaseTable.js +3 -2
|
@@ -570,12 +570,13 @@ export class MySqlSchemaHelper extends SchemaHelper {
|
|
|
570
570
|
async getAllEnumDefinitions(connection, tables, ctx) {
|
|
571
571
|
const sql = `select column_name as column_name, column_type as column_type, table_name as table_name
|
|
572
572
|
from information_schema.columns
|
|
573
|
-
where data_type = 'enum' and table_name in (${tables.map(t =>
|
|
573
|
+
where data_type = 'enum' and table_name in (${tables.map(t => this.platform.quoteValue(t.table_name)).join(', ')}) and table_schema = database()`;
|
|
574
574
|
const enums = await connection.execute(sql, [], 'all', ctx);
|
|
575
575
|
return enums.reduce((o, item) => {
|
|
576
|
-
|
|
576
|
+
const key = this.getTableKey(item);
|
|
577
|
+
o[key] ??= {};
|
|
577
578
|
// items can hold commas, doubled quotes and backslash escapes
|
|
578
|
-
o[
|
|
579
|
+
o[key][item.column_name] = [...item.column_type.matchAll(/'((?:''|\\.|[^'\\])*)'/g)].map(([, value]) => this.unescapeDefault(value.replaceAll("''", "'")));
|
|
579
580
|
return o;
|
|
580
581
|
}, {});
|
|
581
582
|
}
|
|
@@ -28,6 +28,7 @@ interface OracleResultSet<R> {
|
|
|
28
28
|
declare class OracleQueryCompiler extends DefaultQueryCompiler {
|
|
29
29
|
protected getLeftIdentifierWrapper(): string;
|
|
30
30
|
protected getRightIdentifierWrapper(): string;
|
|
31
|
+
protected getCurrentParameterPlaceholder(): string;
|
|
31
32
|
protected visitAlias(node: AliasNode): void;
|
|
32
33
|
}
|
|
33
34
|
declare class OracleAdapter extends DialectAdapterBase {
|
|
@@ -42,10 +43,6 @@ declare class OracleConnection implements DatabaseConnection {
|
|
|
42
43
|
readonly id: number;
|
|
43
44
|
constructor(connection: OraclePoolConnection, executeOptions?: Record<string, unknown>);
|
|
44
45
|
executeQuery<R>(compiledQuery: CompiledQuery): Promise<QueryResult<R>>;
|
|
45
|
-
formatQuery(query: CompiledQuery): {
|
|
46
|
-
sql: string;
|
|
47
|
-
bindParams: unknown[];
|
|
48
|
-
};
|
|
49
46
|
streamQuery<R>(compiledQuery: CompiledQuery, chunkSize?: number): AsyncIterableIterator<QueryResult<R>>;
|
|
50
47
|
get connection(): OraclePoolConnection;
|
|
51
48
|
}
|
|
@@ -14,6 +14,9 @@ class OracleQueryCompiler extends DefaultQueryCompiler {
|
|
|
14
14
|
getRightIdentifierWrapper() {
|
|
15
15
|
return '';
|
|
16
16
|
}
|
|
17
|
+
getCurrentParameterPlaceholder() {
|
|
18
|
+
return ':' + (this.numParameters - 1);
|
|
19
|
+
}
|
|
17
20
|
visitAlias(node) {
|
|
18
21
|
this.visitNode(node.node);
|
|
19
22
|
this.append(' ');
|
|
@@ -47,8 +50,7 @@ class OracleConnection {
|
|
|
47
50
|
this.#connection = connection;
|
|
48
51
|
}
|
|
49
52
|
async executeQuery(compiledQuery) {
|
|
50
|
-
const
|
|
51
|
-
const result = await this.#connection.execute(sql, bindParams, {
|
|
53
|
+
const result = await this.#connection.execute(compiledQuery.sql, compiledQuery.parameters, {
|
|
52
54
|
autoCommit: compiledQuery.autoCommit,
|
|
53
55
|
outFormat: OUT_FORMAT_OBJECT,
|
|
54
56
|
...this.#executeOptions,
|
|
@@ -60,15 +62,8 @@ class OracleConnection {
|
|
|
60
62
|
outBinds: result.outBinds,
|
|
61
63
|
};
|
|
62
64
|
}
|
|
63
|
-
formatQuery(query) {
|
|
64
|
-
return {
|
|
65
|
-
sql: query.sql.replace(/\$(\d+)/g, (_match, p1) => `:${parseInt(p1, 10) - 1}`), // Format bind params in Oracle syntax :0, :1, etc.
|
|
66
|
-
bindParams: query.parameters,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
65
|
async *streamQuery(compiledQuery, chunkSize) {
|
|
70
|
-
const
|
|
71
|
-
const result = await this.#connection.execute(sql, bindParams, {
|
|
66
|
+
const result = await this.#connection.execute(compiledQuery.sql, compiledQuery.parameters, {
|
|
72
67
|
resultSet: true,
|
|
73
68
|
autoCommit: compiledQuery.autoCommit,
|
|
74
69
|
outFormat: OUT_FORMAT_OBJECT,
|
|
@@ -105,7 +105,7 @@ export class PostgreSqlSchemaHelper extends SchemaHelper {
|
|
|
105
105
|
// breaking a plain `table_name not in (...)` predicate).
|
|
106
106
|
return (`select table_name, table_schema as schema_name, ` +
|
|
107
107
|
`(select pg_catalog.obj_description(c.oid) from pg_catalog.pg_class c
|
|
108
|
-
where c.oid = (select ('
|
|
108
|
+
where c.oid = (select format('%I.%I', table_schema, table_name)::regclass::oid) and c.relname = table_name) as table_comment ` +
|
|
109
109
|
`from information_schema.tables t ` +
|
|
110
110
|
`where ${this.getIgnoredNamespacesConditionSQL('table_schema')} ` +
|
|
111
111
|
`and table_name != 'geometry_columns' and table_name != 'spatial_ref_sys' and table_type != 'VIEW' ` +
|
|
@@ -796,7 +796,7 @@ export class PostgreSqlSchemaHelper extends SchemaHelper {
|
|
|
796
796
|
// INOUT before IN/OUT, with required trailing space so identifiers like `input` aren't
|
|
797
797
|
// mis-parsed as a direction keyword. The name is optional — `pg_get_function_arguments`
|
|
798
798
|
// omits it for unnamed parameters (e.g. `text`), leaving just the type.
|
|
799
|
-
const match = /^(?:(INOUT|VARIADIC|IN|OUT)\s+)?(?:(?:"((?:[^"]|"")+)"|([\w$]+))\s+)?(.+?)(?:\s+default\s+.+)?$/
|
|
799
|
+
const match = /^(?:(INOUT|VARIADIC|IN|OUT)\s+)?(?:(?:"((?:[^"]|"")+)"|([\w$]+))\s+)?(.+?)(?:\s+default\s+.+)?$/is.exec(trimmed);
|
|
800
800
|
/* v8 ignore next 3: defensive guard for unexpected `pg_get_function_arguments` output shapes */
|
|
801
801
|
if (!match) {
|
|
802
802
|
throw new Error(`Could not parse PostgreSQL routine parameter signature: ${JSON.stringify(trimmed)}`);
|
|
@@ -245,8 +245,9 @@ export class SqliteSchemaHelper extends SchemaHelper {
|
|
|
245
245
|
}
|
|
246
246
|
for (let i = cols.length - 1; i >= 0; i--) {
|
|
247
247
|
const col = cols[i];
|
|
248
|
+
const name = col.name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
248
249
|
// the first column is not preceded by a comma
|
|
249
|
-
const re = ` *(?:^|,) *[\`"']?${
|
|
250
|
+
const re = ` *(?:^|,) *[\`"']?${name}[\`"']? (.*)`;
|
|
250
251
|
const columnDef = new RegExp(re, 'i').exec(columnsDef);
|
|
251
252
|
if (columnDef) {
|
|
252
253
|
columns[col.name] = { name: col.name, definition: columnDef[1] };
|
|
@@ -283,7 +284,7 @@ export class SqliteSchemaHelper extends SchemaHelper {
|
|
|
283
284
|
}
|
|
284
285
|
async getColumns(connection, tableName, schemaName, ctx) {
|
|
285
286
|
const prefix = this.getSchemaPrefix(schemaName);
|
|
286
|
-
const columns = await connection.execute(`pragma ${prefix}table_xinfo(
|
|
287
|
+
const columns = await connection.execute(`pragma ${prefix}table_xinfo(${this.platform.quoteValue(tableName)})`, [], 'all', ctx);
|
|
287
288
|
const sql = `select sql from ${prefix}sqlite_master where type = ? and name = ?`;
|
|
288
289
|
const tableDefinition = await connection.execute(sql, ['table', tableName], 'get', ctx);
|
|
289
290
|
const composite = columns.reduce((count, col) => count + (col.pk ? 1 : 0), 0) > 1;
|
|
@@ -370,15 +371,15 @@ export class SqliteSchemaHelper extends SchemaHelper {
|
|
|
370
371
|
}
|
|
371
372
|
async getPrimaryKeys(connection, indexes, tableName, schemaName, ctx) {
|
|
372
373
|
const prefix = this.getSchemaPrefix(schemaName);
|
|
373
|
-
const sql = `pragma ${prefix}table_info(
|
|
374
|
+
const sql = `pragma ${prefix}table_info(${this.platform.quoteValue(tableName)})`;
|
|
374
375
|
const cols = await connection.execute(sql, [], 'all', ctx);
|
|
375
376
|
return cols.filter(col => !!col.pk).map(col => col.name);
|
|
376
377
|
}
|
|
377
378
|
async getIndexes(connection, tableName, schemaName, ctx) {
|
|
378
379
|
const prefix = this.getSchemaPrefix(schemaName);
|
|
379
|
-
const sql = `pragma ${prefix}table_info(
|
|
380
|
+
const sql = `pragma ${prefix}table_info(${this.platform.quoteValue(tableName)})`;
|
|
380
381
|
const cols = await connection.execute(sql, [], 'all', ctx);
|
|
381
|
-
const indexes = await connection.execute(`pragma ${prefix}index_list(
|
|
382
|
+
const indexes = await connection.execute(`pragma ${prefix}index_list(${this.platform.quoteValue(tableName)})`, [], 'all', ctx);
|
|
382
383
|
// sqlite_master.sql holds the original CREATE INDEX statement — the only place a partial
|
|
383
384
|
// index's WHERE predicate is preserved (PRAGMA index_* don't expose it).
|
|
384
385
|
const indexSqls = await connection.execute(`select name, sql from ${prefix}sqlite_master where type = 'index' and tbl_name = ?`, [tableName], 'all', ctx);
|
|
@@ -400,7 +401,7 @@ export class SqliteSchemaHelper extends SchemaHelper {
|
|
|
400
401
|
});
|
|
401
402
|
}
|
|
402
403
|
for (const index of indexes.filter(index => !this.isImplicitIndex(index.name))) {
|
|
403
|
-
const res = await connection.execute(`pragma ${prefix}index_info(
|
|
404
|
+
const res = await connection.execute(`pragma ${prefix}index_info(${this.platform.quoteValue(index.name)})`, [], 'all', ctx);
|
|
404
405
|
const where = wherePredicates.get(index.name);
|
|
405
406
|
ret.push(...res.map(row => ({
|
|
406
407
|
columnNames: [row.name],
|
|
@@ -442,7 +443,7 @@ export class SqliteSchemaHelper extends SchemaHelper {
|
|
|
442
443
|
}
|
|
443
444
|
async getColumnDefinitions(connection, tableName, schemaName, ctx) {
|
|
444
445
|
const prefix = this.getSchemaPrefix(schemaName);
|
|
445
|
-
const columns = await connection.execute(`pragma ${prefix}table_xinfo(
|
|
446
|
+
const columns = await connection.execute(`pragma ${prefix}table_xinfo(${this.platform.quoteValue(tableName)})`, [], 'all', ctx);
|
|
446
447
|
const sql = `select sql from ${prefix}sqlite_master where type = ? and name = ?`;
|
|
447
448
|
const tableDefinition = await connection.execute(sql, ['table', tableName], 'get', ctx);
|
|
448
449
|
return this.parseTableDefinition(tableDefinition.sql, columns);
|
|
@@ -450,7 +451,7 @@ export class SqliteSchemaHelper extends SchemaHelper {
|
|
|
450
451
|
async getForeignKeys(connection, tableName, schemaName, ctx) {
|
|
451
452
|
const { constraints } = await this.getColumnDefinitions(connection, tableName, schemaName, ctx);
|
|
452
453
|
const prefix = this.getSchemaPrefix(schemaName);
|
|
453
|
-
const fks = await connection.execute(`pragma ${prefix}foreign_key_list(
|
|
454
|
+
const fks = await connection.execute(`pragma ${prefix}foreign_key_list(${this.platform.quoteValue(tableName)})`, [], 'all', ctx);
|
|
454
455
|
const qualifiedTableName = schemaName ? `${schemaName}.${tableName}` : tableName;
|
|
455
456
|
return fks.reduce((ret, fk) => {
|
|
456
457
|
const constraintName = this.platform.getIndexName(tableName, [fk.from], 'foreign');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.2.11-dev.
|
|
3
|
+
"version": "7.2.11-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.10"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.2.11-dev.
|
|
56
|
+
"@mikro-orm/core": "7.2.11-dev.13"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|
package/schema/DatabaseTable.js
CHANGED
|
@@ -836,9 +836,10 @@ export class DatabaseTable {
|
|
|
836
836
|
let field = baseName;
|
|
837
837
|
if (fk) {
|
|
838
838
|
const idx = fk.columnNames.indexOf(baseName);
|
|
839
|
-
|
|
839
|
+
const stripSuffix = (suffix) => (field.endsWith(suffix) ? field.slice(0, -suffix.length) : field);
|
|
840
|
+
let replacedFieldName = stripSuffix(`_${fk.referencedColumnNames[idx]}`);
|
|
840
841
|
if (replacedFieldName === field) {
|
|
841
|
-
replacedFieldName =
|
|
842
|
+
replacedFieldName = stripSuffix(`_${namingStrategy.referenceColumnName()}`);
|
|
842
843
|
}
|
|
843
844
|
field = replacedFieldName;
|
|
844
845
|
}
|