@mikro-orm/sql 7.2.4-dev.0 → 7.2.4-dev.10
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
|
@@ -1143,26 +1143,32 @@ export class AbstractSqlDriver extends DatabaseDriver {
|
|
|
1143
1143
|
}
|
|
1144
1144
|
sql += ' where ';
|
|
1145
1145
|
const pkProps = meta.primaryKeys.concat(...meta.getOwnConcurrencyCheckKeys());
|
|
1146
|
+
// an optimistically locked batch carries the version in every condition
|
|
1147
|
+
if (meta.versionProperty &&
|
|
1148
|
+
where.every(cond => Utils.isPlainObject(cond) && meta.versionProperty in cond)) {
|
|
1149
|
+
pkProps.push(meta.versionProperty);
|
|
1150
|
+
}
|
|
1146
1151
|
const pks = Utils.flatten(pkProps.map(pk => meta.properties[pk].fieldNames));
|
|
1147
1152
|
const useTupleIn = pks.length <= 1 || this.platform.allowsComparingTuples();
|
|
1148
1153
|
const condTemplate = useTupleIn
|
|
1149
1154
|
? `(${pks.map(() => '?').join(', ')})`
|
|
1150
1155
|
: `(${pks.map(pk => `${this.platform.quoteIdentifier(pk)} = ?`).join(' and ')})`;
|
|
1151
|
-
const conds = where.
|
|
1156
|
+
const conds = where.flatMap(cond => {
|
|
1152
1157
|
// with multiple PK columns the condition is looked up by property name, so it needs to stay an object
|
|
1153
1158
|
if (pks.length === 1 && Utils.isPlainObject(cond) && Utils.getObjectKeysSize(cond) === 1) {
|
|
1154
1159
|
cond = Object.values(cond)[0];
|
|
1155
1160
|
}
|
|
1156
1161
|
if (pks.length > 1) {
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1162
|
+
// a date version in sqlite matches either of its storage formats (see `convertVersionValue()`)
|
|
1163
|
+
const version = cond[meta.versionProperty];
|
|
1164
|
+
const versions = version?.$in ?? [version];
|
|
1165
|
+
return versions.map(v => {
|
|
1166
|
+
pkProps.forEach(pk => {
|
|
1167
|
+
const value = pk === meta.versionProperty ? v : cond[pk];
|
|
1168
|
+
params.push(...(Array.isArray(value) ? Utils.flatten(value) : [value]));
|
|
1169
|
+
});
|
|
1170
|
+
return condTemplate;
|
|
1164
1171
|
});
|
|
1165
|
-
return condTemplate;
|
|
1166
1172
|
}
|
|
1167
1173
|
params.push(cond);
|
|
1168
1174
|
return '?';
|
|
@@ -128,8 +128,10 @@ export class SqliteSchemaHelper extends SchemaHelper {
|
|
|
128
128
|
sql += `, primary key (${primaryKey.columnNames.map(c => this.quote(c)).join(', ')})`;
|
|
129
129
|
}
|
|
130
130
|
const parts = [];
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
if (this.options.createForeignKeyConstraints) {
|
|
132
|
+
for (const fk of Object.values(table.getForeignKeys())) {
|
|
133
|
+
parts.push(this.createForeignKey(table, fk, false));
|
|
134
|
+
}
|
|
133
135
|
}
|
|
134
136
|
for (const check of table.getChecks()) {
|
|
135
137
|
const sql = `constraint ${this.quote(check.name)} check (${check.expression})`;
|
|
@@ -498,7 +500,7 @@ export class SqliteSchemaHelper extends SchemaHelper {
|
|
|
498
500
|
const [schemaName, tableName] = this.splitTableName(diff.name);
|
|
499
501
|
if (Utils.hasObjectKeys(diff.removedChecks) ||
|
|
500
502
|
Utils.hasObjectKeys(diff.changedChecks) ||
|
|
501
|
-
Utils.hasObjectKeys(diff.changedForeignKeys) ||
|
|
503
|
+
(this.options.createForeignKeyConstraints && Utils.hasObjectKeys(diff.changedForeignKeys)) ||
|
|
502
504
|
Utils.hasObjectKeys(diff.changedColumns) ||
|
|
503
505
|
// sqlite can only add or change a primary key by rebuilding the table
|
|
504
506
|
[...Object.values(diff.addedIndexes), ...Object.values(diff.changedIndexes)].some(index => index.primary)) {
|
|
@@ -517,7 +519,8 @@ export class SqliteSchemaHelper extends SchemaHelper {
|
|
|
517
519
|
if (Object.values(diff.addedColumns).length > 0) {
|
|
518
520
|
this.append(ret, this.getAddColumnsSQL(diff.toTable, Object.values(diff.addedColumns), diff));
|
|
519
521
|
}
|
|
520
|
-
if (
|
|
522
|
+
if ((this.options.createForeignKeyConstraints && Utils.hasObjectKeys(diff.addedForeignKeys)) ||
|
|
523
|
+
Utils.hasObjectKeys(diff.addedChecks)) {
|
|
521
524
|
return this.getAlterTempTableSQL(diff);
|
|
522
525
|
}
|
|
523
526
|
for (const [oldColumnName, column] of Object.entries(diff.renamedColumns)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.2.4-dev.
|
|
3
|
+
"version": "7.2.4-dev.10",
|
|
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.3"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.2.4-dev.
|
|
56
|
+
"@mikro-orm/core": "7.2.4-dev.10"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|