@mikro-orm/knex 6.0.0-dev.29 → 6.0.0-dev.31
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/AbstractSqlConnection.js +2 -2
- package/AbstractSqlDriver.js +12 -13
- package/SqlEntityRepository.d.ts +0 -1
- package/SqlEntityRepository.js +0 -1
- package/package.json +2 -2
- package/query/QueryBuilder.d.ts +1 -1
- package/query/QueryBuilder.js +3 -3
- package/schema/DatabaseTable.js +2 -3
- package/schema/SqlSchemaGenerator.js +5 -5
package/AbstractSqlConnection.js
CHANGED
|
@@ -78,7 +78,7 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
78
78
|
}
|
|
79
79
|
async execute(queryOrKnex, params = [], method = 'all', ctx) {
|
|
80
80
|
if (core_1.Utils.isObject(queryOrKnex)) {
|
|
81
|
-
ctx
|
|
81
|
+
ctx ??= (queryOrKnex.client.transacting ? queryOrKnex : null);
|
|
82
82
|
const q = queryOrKnex.toSQL();
|
|
83
83
|
queryOrKnex = q.sql;
|
|
84
84
|
params = q.bindings;
|
|
@@ -177,5 +177,5 @@ class AbstractSqlConnection extends core_1.Connection {
|
|
|
177
177
|
};
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
|
-
AbstractSqlConnection.__patched = false;
|
|
181
180
|
exports.AbstractSqlConnection = AbstractSqlConnection;
|
|
181
|
+
AbstractSqlConnection.__patched = false;
|
package/AbstractSqlDriver.js
CHANGED
|
@@ -73,7 +73,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
73
73
|
opts.limit = 1;
|
|
74
74
|
}
|
|
75
75
|
if (opts.limit > 0 && !opts.flags?.includes(core_1.QueryFlag.DISABLE_PAGINATE)) {
|
|
76
|
-
opts.flags
|
|
76
|
+
opts.flags ??= [];
|
|
77
77
|
opts.flags.push(core_1.QueryFlag.DISABLE_PAGINATE);
|
|
78
78
|
}
|
|
79
79
|
const res = await this.find(entityName, where, opts);
|
|
@@ -150,7 +150,6 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
150
150
|
mapJoinedProps(result, meta, populate, qb, root, map, parentJoinPath) {
|
|
151
151
|
const joinedProps = this.joinedProps(meta, populate);
|
|
152
152
|
joinedProps.forEach(p => {
|
|
153
|
-
var _a, _b;
|
|
154
153
|
const relation = meta.properties[p.field];
|
|
155
154
|
/* istanbul ignore next */
|
|
156
155
|
if (!relation) {
|
|
@@ -168,7 +167,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
168
167
|
if (!hasPK) {
|
|
169
168
|
// initialize empty collections
|
|
170
169
|
if ([core_1.ReferenceKind.MANY_TO_MANY, core_1.ReferenceKind.ONE_TO_MANY].includes(relation.kind)) {
|
|
171
|
-
result[
|
|
170
|
+
result[relation.name] ??= [];
|
|
172
171
|
}
|
|
173
172
|
return;
|
|
174
173
|
}
|
|
@@ -193,7 +192,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
193
192
|
map[key] = result;
|
|
194
193
|
}
|
|
195
194
|
if ([core_1.ReferenceKind.MANY_TO_MANY, core_1.ReferenceKind.ONE_TO_MANY].includes(relation.kind)) {
|
|
196
|
-
result[
|
|
195
|
+
result[relation.name] ??= [];
|
|
197
196
|
this.appendToCollection(meta2, result[relation.name], relationPojo);
|
|
198
197
|
}
|
|
199
198
|
else {
|
|
@@ -228,7 +227,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
228
227
|
return this.rethrow(qb.getCount());
|
|
229
228
|
}
|
|
230
229
|
async nativeInsert(entityName, data, options = {}) {
|
|
231
|
-
options.convertCustomTypes
|
|
230
|
+
options.convertCustomTypes ??= true;
|
|
232
231
|
const meta = this.metadata.find(entityName);
|
|
233
232
|
const collections = this.extractManyToMany(entityName, data);
|
|
234
233
|
const pks = meta?.primaryKeys ?? [this.config.getNamingStrategy().referenceColumnName()];
|
|
@@ -248,8 +247,8 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
248
247
|
return res;
|
|
249
248
|
}
|
|
250
249
|
async nativeInsertMany(entityName, data, options = {}) {
|
|
251
|
-
options.processCollections
|
|
252
|
-
options.convertCustomTypes
|
|
250
|
+
options.processCollections ??= true;
|
|
251
|
+
options.convertCustomTypes ??= true;
|
|
253
252
|
const meta = this.metadata.find(entityName);
|
|
254
253
|
const collections = options.processCollections ? data.map(d => this.extractManyToMany(entityName, d)) : [];
|
|
255
254
|
const pks = this.getPrimaryKeyFields(entityName);
|
|
@@ -302,8 +301,8 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
302
301
|
pk = data.map(d => core_1.Utils.getPrimaryKeyCond(d, pks));
|
|
303
302
|
}
|
|
304
303
|
else {
|
|
305
|
-
res.row
|
|
306
|
-
res.rows
|
|
304
|
+
res.row ??= {};
|
|
305
|
+
res.rows ??= [];
|
|
307
306
|
pk = data.map((d, i) => d[pks[0]] ?? res.rows[i]?.[pks[0]]).map(d => [d]);
|
|
308
307
|
res.insertId = res.insertId || res.row[pks[0]];
|
|
309
308
|
}
|
|
@@ -313,7 +312,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
313
312
|
return res;
|
|
314
313
|
}
|
|
315
314
|
async nativeUpdate(entityName, where, data, options = {}) {
|
|
316
|
-
options.convertCustomTypes
|
|
315
|
+
options.convertCustomTypes ??= true;
|
|
317
316
|
const meta = this.metadata.find(entityName);
|
|
318
317
|
const pks = this.getPrimaryKeyFields(entityName);
|
|
319
318
|
const collections = this.extractManyToMany(entityName, data);
|
|
@@ -344,8 +343,8 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
344
343
|
return res;
|
|
345
344
|
}
|
|
346
345
|
async nativeUpdateMany(entityName, where, data, options = {}) {
|
|
347
|
-
options.processCollections
|
|
348
|
-
options.convertCustomTypes
|
|
346
|
+
options.processCollections ??= true;
|
|
347
|
+
options.convertCustomTypes ??= true;
|
|
349
348
|
const meta = this.metadata.get(entityName);
|
|
350
349
|
if (options.upsert) {
|
|
351
350
|
const uniqueFields = core_1.Utils.isPlainObject(where[0]) ? Object.keys(where[0]) : meta.primaryKeys;
|
|
@@ -465,7 +464,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
465
464
|
const pivotMeta = this.metadata.find(coll.property.pivotEntity);
|
|
466
465
|
if (pivotMeta.schema === '*') {
|
|
467
466
|
/* istanbul ignore next */
|
|
468
|
-
options
|
|
467
|
+
options ??= {};
|
|
469
468
|
options.schema = ownerSchema;
|
|
470
469
|
}
|
|
471
470
|
return this.rethrow(this.updateCollectionDiff(meta, coll.property, pks, deleteDiff, insertDiff, options));
|
package/SqlEntityRepository.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ import type { SqlEntityManager } from './SqlEntityManager';
|
|
|
5
5
|
import type { QueryBuilder } from './query';
|
|
6
6
|
export declare class SqlEntityRepository<T extends object> extends EntityRepository<T> {
|
|
7
7
|
protected readonly _em: SqlEntityManager;
|
|
8
|
-
protected readonly entityName: EntityName<T>;
|
|
9
8
|
constructor(_em: SqlEntityManager, entityName: EntityName<T>);
|
|
10
9
|
/**
|
|
11
10
|
* Creates a QueryBuilder instance
|
package/SqlEntityRepository.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "6.0.0-dev.
|
|
3
|
+
"version": "6.0.0-dev.31",
|
|
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",
|
|
@@ -66,6 +66,6 @@
|
|
|
66
66
|
"@mikro-orm/core": "^5.6.8"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "~6.0.0-dev.
|
|
69
|
+
"@mikro-orm/core": "~6.0.0-dev.31"
|
|
70
70
|
}
|
|
71
71
|
}
|
package/query/QueryBuilder.d.ts
CHANGED
|
@@ -77,7 +77,7 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
77
77
|
/**
|
|
78
78
|
* @internal
|
|
79
79
|
*/
|
|
80
|
-
constructor(entityName: EntityName<T> | QueryBuilder<T>, metadata: MetadataStorage, driver: AbstractSqlDriver, context?: Knex.Transaction<any, any[]> | undefined, alias?: string, connectionType?: ConnectionType | undefined, em?: SqlEntityManager<AbstractSqlDriver<import("
|
|
80
|
+
constructor(entityName: EntityName<T> | QueryBuilder<T>, metadata: MetadataStorage, driver: AbstractSqlDriver, context?: Knex.Transaction<any, any[]> | undefined, alias?: string, connectionType?: ConnectionType | undefined, em?: SqlEntityManager<AbstractSqlDriver<import("../AbstractSqlConnection").AbstractSqlConnection, import("../AbstractSqlPlatform").AbstractSqlPlatform>> | undefined);
|
|
81
81
|
select(fields: Field<T> | Field<T>[], distinct?: boolean): SelectQueryBuilder<T>;
|
|
82
82
|
addSelect(fields: Field<T> | Field<T>[]): SelectQueryBuilder<T>;
|
|
83
83
|
distinct(): SelectQueryBuilder<T>;
|
package/query/QueryBuilder.js
CHANGED
|
@@ -580,7 +580,7 @@ class QueryBuilder {
|
|
|
580
580
|
aliased: !this.type || [enums_1.QueryType.SELECT, enums_1.QueryType.COUNT].includes(this.type),
|
|
581
581
|
});
|
|
582
582
|
let aliasedName = `${fromAlias}.${prop.name}#${alias}`;
|
|
583
|
-
path
|
|
583
|
+
path ??= `${(Object.values(this._joins).find(j => j.alias === fromAlias)?.path ?? entityName)}.${prop.name}`;
|
|
584
584
|
if (prop.kind === core_1.ReferenceKind.ONE_TO_MANY) {
|
|
585
585
|
this._joins[aliasedName] = this.helper.joinOneToReference(prop, fromAlias, alias, type, cond);
|
|
586
586
|
}
|
|
@@ -875,11 +875,11 @@ class QueryBuilder {
|
|
|
875
875
|
fromSubQuery(target, aliasName) {
|
|
876
876
|
const subQuery = target.getKnexQuery();
|
|
877
877
|
const { entityName } = target.mainAlias;
|
|
878
|
-
aliasName
|
|
878
|
+
aliasName ??= this.getNextAlias(entityName);
|
|
879
879
|
this.createMainAlias(entityName, aliasName, subQuery);
|
|
880
880
|
}
|
|
881
881
|
fromEntityName(entityName, aliasName) {
|
|
882
|
-
aliasName
|
|
882
|
+
aliasName ??= this._mainAlias?.aliasName ?? this.getNextAlias(entityName);
|
|
883
883
|
this.createMainAlias(entityName, aliasName);
|
|
884
884
|
}
|
|
885
885
|
createQueryBuilderHelper() {
|
package/schema/DatabaseTable.js
CHANGED
|
@@ -51,7 +51,6 @@ class DatabaseTable {
|
|
|
51
51
|
}
|
|
52
52
|
addColumnFromProperty(prop, meta) {
|
|
53
53
|
prop.fieldNames.forEach((field, idx) => {
|
|
54
|
-
var _a;
|
|
55
54
|
const type = prop.enum ? 'enum' : prop.columnTypes[idx];
|
|
56
55
|
const mappedType = this.platform.getMappedType(type);
|
|
57
56
|
if (mappedType instanceof core_1.DecimalType) {
|
|
@@ -64,7 +63,7 @@ class DatabaseTable {
|
|
|
64
63
|
}
|
|
65
64
|
}
|
|
66
65
|
if (mappedType instanceof core_1.DateTimeType) {
|
|
67
|
-
prop.length
|
|
66
|
+
prop.length ??= this.platform.getDefaultDateTimeLength();
|
|
68
67
|
}
|
|
69
68
|
const primary = !meta.compositePK && !!prop.primary && prop.kind === core_1.ReferenceKind.SCALAR && this.platform.isNumericColumn(mappedType);
|
|
70
69
|
this.columns[field] = {
|
|
@@ -84,7 +83,7 @@ class DatabaseTable {
|
|
|
84
83
|
extra: prop.extra,
|
|
85
84
|
ignoreSchemaChanges: prop.ignoreSchemaChanges,
|
|
86
85
|
};
|
|
87
|
-
|
|
86
|
+
this.columns[field].unsigned ||= this.columns[field].autoincrement;
|
|
88
87
|
const defaultValue = this.platform.getSchemaHelper().normalizeDefaultValue(prop.defaultRaw, prop.length);
|
|
89
88
|
this.columns[field].default = defaultValue;
|
|
90
89
|
});
|
|
@@ -143,9 +143,9 @@ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
143
143
|
};
|
|
144
144
|
}
|
|
145
145
|
async prepareSchemaForComparison(options) {
|
|
146
|
-
options.wrap
|
|
147
|
-
options.safe
|
|
148
|
-
options.dropTables
|
|
146
|
+
options.wrap ??= this.options.disableForeignKeys;
|
|
147
|
+
options.safe ??= false;
|
|
148
|
+
options.dropTables ??= true;
|
|
149
149
|
const toSchema = this.getTargetSchema(options.schema);
|
|
150
150
|
const fromSchema = options.fromSchema ?? await DatabaseSchema_1.DatabaseSchema.create(this.connection, this.platform, this.config, options.schema);
|
|
151
151
|
const wildcardSchemaTables = Object.values(this.metadata.getAll()).filter(meta => meta.schema === '*').map(meta => meta.tableName);
|
|
@@ -353,7 +353,7 @@ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
353
353
|
await this.driver.execute(this.helper.getDropDatabaseSQL('' + this.knex.ref(name)));
|
|
354
354
|
}
|
|
355
355
|
async execute(sql, options = {}) {
|
|
356
|
-
options.wrap
|
|
356
|
+
options.wrap ??= false;
|
|
357
357
|
const lines = this.wrapSchema(sql, options).split('\n').filter(i => i.trim());
|
|
358
358
|
if (lines.length === 0) {
|
|
359
359
|
return;
|
|
@@ -365,7 +365,7 @@ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
365
365
|
await core_1.Utils.runSerial(lines, line => this.driver.execute(line));
|
|
366
366
|
}
|
|
367
367
|
wrapSchema(sql, options = {}) {
|
|
368
|
-
options.wrap
|
|
368
|
+
options.wrap ??= this.options.disableForeignKeys;
|
|
369
369
|
if (!options.wrap || sql.trim() === '') {
|
|
370
370
|
return sql;
|
|
371
371
|
}
|