@mikro-orm/knex 6.0.0-dev.81 → 6.0.0-dev.83
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
|
@@ -643,17 +643,18 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
643
643
|
* @internal
|
|
644
644
|
*/
|
|
645
645
|
mapPropToFieldNames(qb, prop, tableAlias) {
|
|
646
|
-
const
|
|
646
|
+
const knex = this.connection.getKnex();
|
|
647
|
+
const aliased = knex.ref(tableAlias ? `${tableAlias}__${prop.fieldNames[0]}` : prop.fieldNames[0]).toString();
|
|
647
648
|
if (prop.customType?.convertToJSValueSQL && tableAlias) {
|
|
648
|
-
const prefixed =
|
|
649
|
+
const prefixed = knex.ref(prop.fieldNames[0]).withSchema(tableAlias).toString();
|
|
649
650
|
return [(0, core_1.raw)(`${prop.customType.convertToJSValueSQL(prefixed, this.platform)} as ${aliased}`)];
|
|
650
651
|
}
|
|
651
652
|
if (prop.formula) {
|
|
652
|
-
const alias =
|
|
653
|
+
const alias = knex.ref(tableAlias ?? qb.alias).toString();
|
|
653
654
|
return [(0, core_1.raw)(`${prop.formula(alias)} as ${aliased}`)];
|
|
654
655
|
}
|
|
655
656
|
if (tableAlias) {
|
|
656
|
-
return prop.fieldNames.map(fieldName =>
|
|
657
|
+
return prop.fieldNames.map(fieldName => knex.ref(fieldName).withSchema(tableAlias).as(`${tableAlias}__${fieldName}`));
|
|
657
658
|
}
|
|
658
659
|
return prop.fieldNames;
|
|
659
660
|
}
|
|
@@ -853,8 +854,8 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
853
854
|
meta.props
|
|
854
855
|
.filter(prop => prop.formula && !lazyProps.includes(prop))
|
|
855
856
|
.forEach(prop => {
|
|
856
|
-
const alias =
|
|
857
|
-
const aliased =
|
|
857
|
+
const alias = this.connection.getKnex().ref(qb.alias).toString();
|
|
858
|
+
const aliased = this.connection.getKnex().ref(prop.fieldNames[0]).toString();
|
|
858
859
|
ret.push((0, core_1.raw)(`${prop.formula(alias)} as ${aliased}`));
|
|
859
860
|
});
|
|
860
861
|
meta.props
|
package/AbstractSqlPlatform.js
CHANGED
|
@@ -48,9 +48,15 @@ class AbstractSqlPlatform extends core_1.Platform {
|
|
|
48
48
|
let j = 0;
|
|
49
49
|
let pos = 0;
|
|
50
50
|
let ret = '';
|
|
51
|
-
if (sql[0] === '?'
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
if (sql[0] === '?') {
|
|
52
|
+
if (sql[1] === '?') {
|
|
53
|
+
ret += this.quoteIdentifier(params[j++]);
|
|
54
|
+
pos = 2;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
ret += this.quoteValue(params[j++]);
|
|
58
|
+
pos = 1;
|
|
59
|
+
}
|
|
54
60
|
}
|
|
55
61
|
while (pos < sql.length) {
|
|
56
62
|
const idx = sql.indexOf('?', pos + 1);
|
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.83",
|
|
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.7.10"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "~6.0.0-dev.
|
|
69
|
+
"@mikro-orm/core": "~6.0.0-dev.83"
|
|
70
70
|
}
|
|
71
71
|
}
|
package/query/QueryBuilder.d.ts
CHANGED
|
@@ -115,12 +115,6 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
|
|
|
115
115
|
* @internal
|
|
116
116
|
*/
|
|
117
117
|
populate(populate: PopulateOptions<T>[], populateWhere?: ObjectQuery<T> | PopulateHint): this;
|
|
118
|
-
/**
|
|
119
|
-
* @internal
|
|
120
|
-
*/
|
|
121
|
-
ref(field: string): Knex.Ref<string, {
|
|
122
|
-
[x: string]: string;
|
|
123
|
-
}>;
|
|
124
118
|
limit(limit?: number, offset?: number): this;
|
|
125
119
|
offset(offset?: number): this;
|
|
126
120
|
withSchema(schema?: string): this;
|
package/query/QueryBuilder.js
CHANGED
|
@@ -299,12 +299,6 @@ class QueryBuilder {
|
|
|
299
299
|
this._populateWhere = populateWhere;
|
|
300
300
|
return this;
|
|
301
301
|
}
|
|
302
|
-
/**
|
|
303
|
-
* @internal
|
|
304
|
-
*/
|
|
305
|
-
ref(field) {
|
|
306
|
-
return this.knex.ref(field);
|
|
307
|
-
}
|
|
308
302
|
limit(limit, offset = 0) {
|
|
309
303
|
this.ensureNotFinalized();
|
|
310
304
|
this._limit = limit;
|
|
@@ -947,7 +941,7 @@ class QueryBuilder {
|
|
|
947
941
|
if (!prop?.persist && !prop?.formula) {
|
|
948
942
|
addToSelect.push(fieldName);
|
|
949
943
|
}
|
|
950
|
-
orderBy.push({ [(0, core_1.raw)(`min(${this.ref(fieldName)}${type})`)]: direction });
|
|
944
|
+
orderBy.push({ [(0, core_1.raw)(`min(${this.knex.ref(fieldName)}${type})`)]: direction });
|
|
951
945
|
}
|
|
952
946
|
}
|
|
953
947
|
subQuery.orderBy(orderBy);
|
|
@@ -155,6 +155,7 @@ class QueryBuilderHelper {
|
|
|
155
155
|
const prop2 = pivotMeta.relations[0] === prop ? pivotMeta.relations[1] : pivotMeta.relations[0];
|
|
156
156
|
return {
|
|
157
157
|
prop, type, cond, ownerAlias, alias,
|
|
158
|
+
inverseAlias: ownerAlias,
|
|
158
159
|
table: pivotMeta.collection,
|
|
159
160
|
schema: pivotMeta.schema,
|
|
160
161
|
joinColumns: prop.joinColumns,
|
|
@@ -179,7 +180,7 @@ class QueryBuilderHelper {
|
|
|
179
180
|
});
|
|
180
181
|
if (join.prop.targetMeta.discriminatorValue && !join.path?.endsWith('[pivot]')) {
|
|
181
182
|
const typeProperty = join.prop.targetMeta.root.discriminatorColumn;
|
|
182
|
-
const alias =
|
|
183
|
+
const alias = join.inverseAlias ?? join.alias;
|
|
183
184
|
join.cond[`${alias}.${typeProperty}`] = join.prop.targetMeta.discriminatorValue;
|
|
184
185
|
}
|
|
185
186
|
Object.keys(join.cond).forEach(key => {
|
|
@@ -344,6 +345,9 @@ class QueryBuilderHelper {
|
|
|
344
345
|
}
|
|
345
346
|
appendQuerySubCondition(qb, type, method, cond, key, operator) {
|
|
346
347
|
const m = operator === '$or' ? 'orWhere' : method;
|
|
348
|
+
if (cond[key] instanceof core_1.RawQueryFragment) {
|
|
349
|
+
cond[key] = this.knex.raw(cond[key].sql, cond[key].params);
|
|
350
|
+
}
|
|
347
351
|
if (this.isSimpleRegExp(cond[key])) {
|
|
348
352
|
return void qb[m](this.mapper(key, type), 'like', this.getRegExpParam(cond[key]));
|
|
349
353
|
}
|
|
@@ -447,9 +451,12 @@ class QueryBuilderHelper {
|
|
|
447
451
|
/* istanbul ignore next */
|
|
448
452
|
const rawColumn = core_1.Utils.isString(column) ? column.split('.').map(e => this.knex.ref(e)).join('.') : column;
|
|
449
453
|
const customOrder = prop?.customOrder;
|
|
450
|
-
|
|
454
|
+
let colPart = customOrder
|
|
451
455
|
? this.platform.generateCustomOrder(rawColumn, customOrder)
|
|
452
456
|
: rawColumn;
|
|
457
|
+
if (core_1.Utils.isRawSql(colPart)) {
|
|
458
|
+
colPart = this.platform.formatQuery(colPart.sql, colPart.params);
|
|
459
|
+
}
|
|
453
460
|
ret.push(`${colPart} ${order.toLowerCase()}`);
|
|
454
461
|
});
|
|
455
462
|
});
|
package/typings.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Knex } from 'knex';
|
|
2
|
-
import type { CheckCallback, Dictionary, EntityProperty, GroupOperator, QBFilterQuery, QueryOrderMap, Type } from '@mikro-orm/core';
|
|
2
|
+
import type { CheckCallback, Dictionary, EntityProperty, GroupOperator, RawQueryFragment, QBFilterQuery, QueryOrderMap, Type } from '@mikro-orm/core';
|
|
3
3
|
import type { QueryType } from './query/enums';
|
|
4
4
|
import type { DatabaseSchema, DatabaseTable } from './schema';
|
|
5
5
|
export interface Table {
|
|
@@ -11,7 +11,7 @@ export type KnexStringRef = Knex.Ref<string, {
|
|
|
11
11
|
[alias: string]: string;
|
|
12
12
|
}>;
|
|
13
13
|
type AnyString = string & {};
|
|
14
|
-
export type Field<T> = AnyString | keyof T | KnexStringRef | Knex.QueryBuilder;
|
|
14
|
+
export type Field<T> = AnyString | keyof T | RawQueryFragment | KnexStringRef | Knex.QueryBuilder;
|
|
15
15
|
export interface JoinOptions {
|
|
16
16
|
table: string;
|
|
17
17
|
schema?: string;
|