@mikro-orm/knex 5.7.8-dev.3 → 5.7.8
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
|
@@ -336,7 +336,8 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
336
336
|
/* istanbul ignore next */
|
|
337
337
|
qb.insert(data)
|
|
338
338
|
.onConflict(uniqueFields.map(p => meta?.properties[p]?.fieldNames[0] ?? p))
|
|
339
|
-
.merge(Object.keys(data).filter(f => !uniqueFields.includes(f)))
|
|
339
|
+
.merge(Object.keys(data).filter(f => !uniqueFields.includes(f)))
|
|
340
|
+
.returning(meta?.hydrateProps.filter(p => !p.lazy && !(p.name in data)).map(p => p.name) ?? '*');
|
|
340
341
|
}
|
|
341
342
|
else {
|
|
342
343
|
qb.update(data).where(where);
|
|
@@ -356,8 +357,9 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
356
357
|
const uniqueFields = core_1.Utils.isPlainObject(where[0]) ? Object.keys(where[0]) : meta.primaryKeys;
|
|
357
358
|
const qb = this.createQueryBuilder(entityName, options.ctx, 'write', options.convertCustomTypes).withSchema(this.getSchemaName(meta, options));
|
|
358
359
|
qb.insert(data)
|
|
359
|
-
.onConflict(uniqueFields.map(p => meta
|
|
360
|
-
.merge(Object.keys(data[0]).filter(f => !uniqueFields.includes(f)))
|
|
360
|
+
.onConflict(uniqueFields.map(p => meta.properties[p]?.fieldNames[0] ?? p))
|
|
361
|
+
.merge(Object.keys(data[0]).filter(f => !uniqueFields.includes(f)))
|
|
362
|
+
.returning(meta.hydrateProps.filter(p => !p.lazy && !(p.name in data[0])).map(p => p.name) ?? '*');
|
|
361
363
|
return qb.execute('run', false);
|
|
362
364
|
}
|
|
363
365
|
const collections = options.processCollections ? data.map(d => this.extractManyToMany(entityName, d)) : [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "5.7.8
|
|
3
|
+
"version": "5.7.8",
|
|
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",
|
|
@@ -63,12 +63,12 @@
|
|
|
63
63
|
"sqlstring": "2.3.3"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@mikro-orm/core": "^5.7.
|
|
66
|
+
"@mikro-orm/core": "^5.7.8"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "
|
|
70
|
-
"@mikro-orm/entity-generator": "
|
|
71
|
-
"@mikro-orm/migrations": "
|
|
69
|
+
"@mikro-orm/core": "^5.0.0",
|
|
70
|
+
"@mikro-orm/entity-generator": "^5.0.0",
|
|
71
|
+
"@mikro-orm/migrations": "^5.0.0",
|
|
72
72
|
"better-sqlite3": "*",
|
|
73
73
|
"mssql": "*",
|
|
74
74
|
"mysql": "*",
|
package/query/QueryBuilder.d.ts
CHANGED
|
@@ -58,6 +58,7 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
58
58
|
private _orderBy;
|
|
59
59
|
private _groupBy;
|
|
60
60
|
private _having;
|
|
61
|
+
private _returning?;
|
|
61
62
|
private _onConflict?;
|
|
62
63
|
private _limit?;
|
|
63
64
|
private _offset?;
|
|
@@ -107,6 +108,7 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
107
108
|
onConflict(fields?: Field<T> | Field<T>[]): this;
|
|
108
109
|
ignore(): this;
|
|
109
110
|
merge(data?: EntityData<T> | Field<T>[]): this;
|
|
111
|
+
returning(fields?: Field<T> | Field<T>[]): this;
|
|
110
112
|
/**
|
|
111
113
|
* @internal
|
|
112
114
|
*/
|
package/query/QueryBuilder.js
CHANGED
|
@@ -266,6 +266,10 @@ class QueryBuilder {
|
|
|
266
266
|
this._onConflict[this._onConflict.length - 1].merge = data;
|
|
267
267
|
return this;
|
|
268
268
|
}
|
|
269
|
+
returning(fields) {
|
|
270
|
+
this._returning = fields != null ? core_1.Utils.asArray(fields) : fields;
|
|
271
|
+
return this;
|
|
272
|
+
}
|
|
269
273
|
/**
|
|
270
274
|
* @internal
|
|
271
275
|
*/
|
|
@@ -377,7 +381,7 @@ class QueryBuilder {
|
|
|
377
381
|
if (this.lockMode) {
|
|
378
382
|
this.helper.getLockSQL(qb, this.lockMode, this.lockTables);
|
|
379
383
|
}
|
|
380
|
-
this.helper.finalize(this.type ?? enums_1.QueryType.SELECT, qb, this.mainAlias.metadata);
|
|
384
|
+
this.helper.finalize(this.type ?? enums_1.QueryType.SELECT, qb, this.mainAlias.metadata, this._data, this._returning);
|
|
381
385
|
return qb;
|
|
382
386
|
}
|
|
383
387
|
/**
|
|
@@ -565,7 +569,7 @@ class QueryBuilder {
|
|
|
565
569
|
// clone array/object properties
|
|
566
570
|
const properties = [
|
|
567
571
|
'flags', '_populate', '_populateWhere', '_populateMap', '_joins', '_joinedProps', '_cond', '_data', '_orderBy',
|
|
568
|
-
'_schema', '_indexHint', '_cache', 'subQueries', 'lockMode', 'lockTables', '_groupBy', '_having',
|
|
572
|
+
'_schema', '_indexHint', '_cache', 'subQueries', 'lockMode', 'lockTables', '_groupBy', '_having', '_returning',
|
|
569
573
|
];
|
|
570
574
|
properties.forEach(prop => qb[prop] = core_1.Utils.copy(this[prop]));
|
|
571
575
|
/* istanbul ignore else */
|
|
@@ -48,7 +48,7 @@ export declare class QueryBuilderHelper {
|
|
|
48
48
|
private getOperatorReplacement;
|
|
49
49
|
getQueryOrder(type: QueryType, orderBy: FlatQueryOrderMap | FlatQueryOrderMap[], populate: Dictionary<string>): string;
|
|
50
50
|
getQueryOrderFromObject(type: QueryType, orderBy: FlatQueryOrderMap, populate: Dictionary<string>): string;
|
|
51
|
-
finalize(type: QueryType, qb: Knex.QueryBuilder, meta?: EntityMetadata): void;
|
|
51
|
+
finalize(type: QueryType, qb: Knex.QueryBuilder, meta?: EntityMetadata, data?: Dictionary, returning?: Field<any>[]): void;
|
|
52
52
|
splitField(field: string, greedyAlias?: boolean): [string, string];
|
|
53
53
|
getLockSQL(qb: Knex.QueryBuilder, lockMode: LockMode, lockTables?: string[]): void;
|
|
54
54
|
updateVersionProperty(qb: Knex.QueryBuilder, data: Dictionary): void;
|
|
@@ -460,11 +460,22 @@ class QueryBuilderHelper {
|
|
|
460
460
|
});
|
|
461
461
|
return ret.join(', ');
|
|
462
462
|
}
|
|
463
|
-
finalize(type, qb, meta) {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
463
|
+
finalize(type, qb, meta, data, returning) {
|
|
464
|
+
if (!meta || !data || !this.platform.usesReturningStatement()) {
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
// always respect explicit returning hint
|
|
468
|
+
if (returning && returning.length > 0) {
|
|
469
|
+
qb.returning(returning.map(field => this.mapper(field, type)));
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
if (type === enums_1.QueryType.INSERT) {
|
|
473
|
+
const returningProps = meta.hydrateProps
|
|
474
|
+
.filter(prop => prop.returning || (prop.persist !== false && ((prop.primary && prop.autoincrement) || prop.defaultRaw)))
|
|
475
|
+
.filter(prop => !(prop.name in data));
|
|
476
|
+
if (returningProps.length > 0) {
|
|
477
|
+
qb.returning(core_1.Utils.flatten(returningProps.map(prop => prop.fieldNames)));
|
|
478
|
+
}
|
|
468
479
|
}
|
|
469
480
|
}
|
|
470
481
|
splitField(field, greedyAlias = false) {
|