@mikro-orm/sql 7.1.9-dev.17 → 7.1.9-dev.19
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/AbstractSqlDriver.js
CHANGED
|
@@ -604,7 +604,7 @@ export class AbstractSqlDriver extends DatabaseDriver {
|
|
|
604
604
|
let pk;
|
|
605
605
|
if (meta.primaryKeys.length > 1) {
|
|
606
606
|
// owner has composite pk
|
|
607
|
-
pk = Utils.
|
|
607
|
+
pk = Utils.getOrderedPrimaryKeys(data, meta);
|
|
608
608
|
}
|
|
609
609
|
else {
|
|
610
610
|
/* v8 ignore next */
|
|
@@ -887,10 +887,9 @@ export class AbstractSqlDriver extends DatabaseDriver {
|
|
|
887
887
|
}
|
|
888
888
|
const res = await this.execute(sql, params, 'run', options.ctx, withAbortContext(options.loggerContext, options));
|
|
889
889
|
let pk;
|
|
890
|
-
/* v8 ignore next */
|
|
891
890
|
if (pks.length > 1) {
|
|
892
891
|
// owner has composite pk
|
|
893
|
-
pk = data.map(d => Utils.
|
|
892
|
+
pk = data.map(d => Utils.getOrderedPrimaryKeys(d, meta));
|
|
894
893
|
}
|
|
895
894
|
else {
|
|
896
895
|
res.row ??= {};
|
|
@@ -949,8 +948,7 @@ export class AbstractSqlDriver extends DatabaseDriver {
|
|
|
949
948
|
}
|
|
950
949
|
res = await this.rethrow(qb.execute('run', false));
|
|
951
950
|
}
|
|
952
|
-
|
|
953
|
-
const pk = pks.map(pk => Utils.extractPK(data[pk] || where, meta));
|
|
951
|
+
const pk = Utils.getOrderedPrimaryKeys({ ...where, ...data }, meta);
|
|
954
952
|
await this.processManyToMany(meta, pk, collections, true, options);
|
|
955
953
|
return res;
|
|
956
954
|
}
|
|
@@ -1113,7 +1111,8 @@ export class AbstractSqlDriver extends DatabaseDriver {
|
|
|
1113
1111
|
}
|
|
1114
1112
|
const res = await this.rethrow(this.execute(sql, params, 'run', options.ctx, withAbortContext(options.loggerContext, options)));
|
|
1115
1113
|
for (let i = 0; i < collections.length; i++) {
|
|
1116
|
-
|
|
1114
|
+
const pk = Utils.getOrderedPrimaryKeys(where[i], meta);
|
|
1115
|
+
await this.processManyToMany(meta, pk, collections[i], false, options);
|
|
1117
1116
|
}
|
|
1118
1117
|
return res;
|
|
1119
1118
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.1.9-dev.
|
|
3
|
+
"version": "7.1.9-dev.19",
|
|
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.1.8"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.1.9-dev.
|
|
56
|
+
"@mikro-orm/core": "7.1.9-dev.19"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|
|
@@ -54,6 +54,8 @@ export declare class SqlSchemaGenerator extends AbstractSchemaGenerator<Abstract
|
|
|
54
54
|
wrap?: boolean;
|
|
55
55
|
ctx?: Transaction;
|
|
56
56
|
}): Promise<void>;
|
|
57
|
+
/** Whether the statement has to be the first one in a query batch, e.g. `create trigger` on MSSQL. */
|
|
58
|
+
protected startsBatch(_statement: string): boolean;
|
|
57
59
|
dropTableIfExists(name: string, schema?: string): Promise<void>;
|
|
58
60
|
private wrapSchema;
|
|
59
61
|
private append;
|
|
@@ -443,14 +443,19 @@ export class SqlSchemaGenerator extends AbstractSchemaGenerator {
|
|
|
443
443
|
const groups = [];
|
|
444
444
|
let i = 0;
|
|
445
445
|
for (const line of lines) {
|
|
446
|
-
|
|
446
|
+
const stmt = line.trim();
|
|
447
|
+
if (stmt === '') {
|
|
447
448
|
if (groups[i]?.length > 0) {
|
|
448
449
|
i++;
|
|
449
450
|
}
|
|
450
451
|
continue;
|
|
451
452
|
}
|
|
453
|
+
// same boundary an empty line creates, for statements that have to start their own batch
|
|
454
|
+
if (groups[i]?.length > 0 && this.startsBatch(stmt)) {
|
|
455
|
+
i++;
|
|
456
|
+
}
|
|
452
457
|
groups[i] ??= [];
|
|
453
|
-
groups[i].push(
|
|
458
|
+
groups[i].push(stmt);
|
|
454
459
|
}
|
|
455
460
|
if (groups.length === 0) {
|
|
456
461
|
return;
|
|
@@ -471,6 +476,10 @@ export class SqlSchemaGenerator extends AbstractSchemaGenerator {
|
|
|
471
476
|
});
|
|
472
477
|
await Utils.runSerial(statements, stmt => this.driver.execute(stmt));
|
|
473
478
|
}
|
|
479
|
+
/** Whether the statement has to be the first one in a query batch, e.g. `create trigger` on MSSQL. */
|
|
480
|
+
startsBatch(_statement) {
|
|
481
|
+
return false;
|
|
482
|
+
}
|
|
474
483
|
async dropTableIfExists(name, schema) {
|
|
475
484
|
const sql = this.helper.dropTableIfExists(name, schema);
|
|
476
485
|
return this.execute(sql);
|