@mikro-orm/knex 6.4.17-dev.6 → 6.4.17-dev.60
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 +21 -15
- package/README.md +1 -1
- package/dialects/mysql/MySqlSchemaHelper.js +8 -1
- package/index.mjs +2 -0
- package/package.json +2 -2
- package/query/CriteriaNodeFactory.js +7 -5
- package/schema/DatabaseTable.d.ts +5 -4
- package/schema/DatabaseTable.js +13 -1
- package/typings.d.ts +1 -1
package/AbstractSqlDriver.js
CHANGED
|
@@ -333,6 +333,9 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
333
333
|
if (meta && !core_1.Utils.isEmpty(populate)) {
|
|
334
334
|
this.buildFields(meta, populate, joinedProps, qb, qb.alias, options, true);
|
|
335
335
|
}
|
|
336
|
+
if (options.em) {
|
|
337
|
+
await qb.applyJoinedFilters(options.em, options.filters);
|
|
338
|
+
}
|
|
336
339
|
return this.rethrow(qb.getCount());
|
|
337
340
|
}
|
|
338
341
|
async nativeInsert(entityName, data, options = {}) {
|
|
@@ -401,14 +404,14 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
401
404
|
value = this.mapDataToFieldNames(value, false, prop.embeddedProps, options.convertCustomTypes);
|
|
402
405
|
}
|
|
403
406
|
}
|
|
404
|
-
if (options.convertCustomTypes && prop.customType) {
|
|
405
|
-
params.push(prop.customType.convertToDatabaseValue(value, this.platform, { key: prop.name, mode: 'query-data' }));
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
407
|
if (typeof value === 'undefined' && this.platform.usesDefaultKeyword()) {
|
|
409
408
|
params.push((0, core_1.raw)('default'));
|
|
410
409
|
return;
|
|
411
410
|
}
|
|
411
|
+
if (options.convertCustomTypes && prop.customType) {
|
|
412
|
+
params.push(prop.customType.convertToDatabaseValue(value, this.platform, { key: prop.name, mode: 'query-data' }));
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
412
415
|
params.push(value);
|
|
413
416
|
};
|
|
414
417
|
if (fields.length > 0 || this.platform.usesDefaultKeyword()) {
|
|
@@ -1156,7 +1159,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
1156
1159
|
if (!join && parentAlias === qb.alias) {
|
|
1157
1160
|
continue;
|
|
1158
1161
|
}
|
|
1159
|
-
if (![core_1.ReferenceKind.SCALAR, core_1.ReferenceKind.EMBEDDED].includes(prop.kind) && typeof childOrder === 'object') {
|
|
1162
|
+
if (join && ![core_1.ReferenceKind.SCALAR, core_1.ReferenceKind.EMBEDDED].includes(prop.kind) && typeof childOrder === 'object') {
|
|
1160
1163
|
const children = this.buildPopulateOrderBy(qb, meta2, core_1.Utils.asArray(childOrder), path, explicit, propAlias);
|
|
1161
1164
|
orderBy.push(...children);
|
|
1162
1165
|
continue;
|
|
@@ -1311,16 +1314,19 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
1311
1314
|
ret.push('*');
|
|
1312
1315
|
}
|
|
1313
1316
|
if (ret.length > 0 && !hasExplicitFields && addFormulas) {
|
|
1314
|
-
meta.props
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1317
|
+
for (const prop of meta.props) {
|
|
1318
|
+
if (lazyProps.includes(prop)) {
|
|
1319
|
+
continue;
|
|
1320
|
+
}
|
|
1321
|
+
if (prop.formula) {
|
|
1322
|
+
const a = this.platform.quoteIdentifier(alias);
|
|
1323
|
+
const aliased = this.platform.quoteIdentifier(prop.fieldNames[0]);
|
|
1324
|
+
ret.push((0, core_1.raw)(`${prop.formula(a)} as ${aliased}`));
|
|
1325
|
+
}
|
|
1326
|
+
if (!prop.object && (prop.hasConvertToDatabaseValueSQL || prop.hasConvertToJSValueSQL)) {
|
|
1327
|
+
ret.push(prop.name);
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1324
1330
|
}
|
|
1325
1331
|
// add joined relations after the root entity fields
|
|
1326
1332
|
if (joinedProps.length > 0) {
|
package/README.md
CHANGED
|
@@ -141,7 +141,7 @@ There is also auto-generated [CHANGELOG.md](CHANGELOG.md) file based on commit m
|
|
|
141
141
|
- [Composite and Foreign Keys as Primary Key](https://mikro-orm.io/docs/composite-keys)
|
|
142
142
|
- [Filters](https://mikro-orm.io/docs/filters)
|
|
143
143
|
- [Using `QueryBuilder`](https://mikro-orm.io/docs/query-builder)
|
|
144
|
-
- [
|
|
144
|
+
- [Populating relations](https://mikro-orm.io/docs/populating-relations)
|
|
145
145
|
- [Property Validation](https://mikro-orm.io/docs/property-validation)
|
|
146
146
|
- [Lifecycle Hooks](https://mikro-orm.io/docs/events#hooks)
|
|
147
147
|
- [Vanilla JS Support](https://mikro-orm.io/docs/usage-with-js)
|
|
@@ -204,7 +204,14 @@ class MySqlSchemaHelper extends SchemaHelper_1.SchemaHelper {
|
|
|
204
204
|
col.defaultTo(null);
|
|
205
205
|
}
|
|
206
206
|
else {
|
|
207
|
-
|
|
207
|
+
const columnType = column.type.toLowerCase();
|
|
208
|
+
// https://dev.mysql.com/doc/refman/9.0/en/data-type-defaults.html
|
|
209
|
+
const needsExpression = ['blob', 'text', 'json', 'point', 'linestring', 'polygon', 'multipoint', 'multilinestring', 'multipolygon', 'geometrycollection'].some(type => columnType.startsWith(type));
|
|
210
|
+
let defaultSql = needsExpression && !column.default.startsWith('(') ? `(${column.default})` : column.default;
|
|
211
|
+
if (column.extra) {
|
|
212
|
+
defaultSql += ' ' + column.extra;
|
|
213
|
+
}
|
|
214
|
+
col.defaultTo(knex.raw(defaultSql));
|
|
208
215
|
}
|
|
209
216
|
}
|
|
210
217
|
return col;
|
package/index.mjs
CHANGED
|
@@ -219,12 +219,14 @@ export const compareBuffers = mod.compareBuffers;
|
|
|
219
219
|
export const compareObjects = mod.compareObjects;
|
|
220
220
|
export const createSqlFunction = mod.createSqlFunction;
|
|
221
221
|
export const defineConfig = mod.defineConfig;
|
|
222
|
+
export const defineEntity = mod.defineEntity;
|
|
222
223
|
export const equals = mod.equals;
|
|
223
224
|
export const getOnConflictFields = mod.getOnConflictFields;
|
|
224
225
|
export const getOnConflictReturningFields = mod.getOnConflictReturningFields;
|
|
225
226
|
export const helper = mod.helper;
|
|
226
227
|
export const knex = mod.knex;
|
|
227
228
|
export const parseJsonSafe = mod.parseJsonSafe;
|
|
229
|
+
export const quote = mod.quote;
|
|
228
230
|
export const raw = mod.raw;
|
|
229
231
|
export const ref = mod.ref;
|
|
230
232
|
export const rel = mod.rel;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "6.4.17-dev.
|
|
3
|
+
"version": "6.4.17-dev.60",
|
|
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,7 +66,7 @@
|
|
|
66
66
|
"@mikro-orm/core": "^6.4.16"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "6.4.17-dev.
|
|
69
|
+
"@mikro-orm/core": "6.4.17-dev.60",
|
|
70
70
|
"better-sqlite3": "*",
|
|
71
71
|
"libsql": "*",
|
|
72
72
|
"mariadb": "*"
|
|
@@ -49,13 +49,14 @@ class CriteriaNodeFactory {
|
|
|
49
49
|
static createObjectItemNode(metadata, entityName, node, payload, key, meta) {
|
|
50
50
|
const prop = meta?.properties[key];
|
|
51
51
|
const childEntity = prop && prop.kind !== core_1.ReferenceKind.SCALAR ? prop.type : entityName;
|
|
52
|
-
|
|
52
|
+
const isNotEmbedded = prop?.kind !== core_1.ReferenceKind.EMBEDDED;
|
|
53
|
+
if (isNotEmbedded && prop?.customType instanceof core_1.JsonType) {
|
|
53
54
|
return this.createScalarNode(metadata, childEntity, payload[key], node, key);
|
|
54
55
|
}
|
|
55
56
|
if (prop?.kind === core_1.ReferenceKind.SCALAR && payload[key] != null && Object.keys(payload[key]).some(f => core_1.Utils.isGroupOperator(f))) {
|
|
56
57
|
throw core_1.ValidationError.cannotUseGroupOperatorsInsideScalars(entityName, prop.name, payload);
|
|
57
58
|
}
|
|
58
|
-
if (
|
|
59
|
+
if (isNotEmbedded) {
|
|
59
60
|
return this.createNode(metadata, childEntity, payload[key], node, key);
|
|
60
61
|
}
|
|
61
62
|
if (payload[key] == null) {
|
|
@@ -72,11 +73,12 @@ class CriteriaNodeFactory {
|
|
|
72
73
|
throw core_1.ValidationError.cannotUseOperatorsInsideEmbeddables(entityName, prop.name, payload);
|
|
73
74
|
}
|
|
74
75
|
const map = Object.keys(payload[key]).reduce((oo, k) => {
|
|
75
|
-
|
|
76
|
+
const embeddedProp = prop.embeddedProps[k] ?? Object.values(prop.embeddedProps).find(p => p.name === k);
|
|
77
|
+
if (!embeddedProp && !allowedOperators.includes(k)) {
|
|
76
78
|
throw core_1.ValidationError.invalidEmbeddableQuery(entityName, k, prop.type);
|
|
77
79
|
}
|
|
78
|
-
if (
|
|
79
|
-
oo[
|
|
80
|
+
if (embeddedProp) {
|
|
81
|
+
oo[embeddedProp.name] = payload[key][k];
|
|
80
82
|
}
|
|
81
83
|
else if (typeof payload[key][k] === 'object') {
|
|
82
84
|
oo[k] = JSON.stringify(payload[key][k]);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Configuration, type DeferMode, type Dictionary, type EntityMetadata, type EntityProperty, type NamingStrategy } from '@mikro-orm/core';
|
|
1
|
+
import { type Configuration, type DeferMode, type Dictionary, type EntityMetadata, type EntityProperty, type NamingStrategy, type IndexCallback } from '@mikro-orm/core';
|
|
2
2
|
import type { SchemaHelper } from './SchemaHelper';
|
|
3
3
|
import type { CheckDef, Column, ForeignKey, IndexDef } from '../typings';
|
|
4
4
|
import type { AbstractSqlPlatform } from '../AbstractSqlPlatform';
|
|
@@ -53,12 +53,13 @@ export declare class DatabaseTable {
|
|
|
53
53
|
private getPropertyTypeForForeignKey;
|
|
54
54
|
private getPropertyTypeForColumn;
|
|
55
55
|
private getPropertyDefaultValue;
|
|
56
|
+
private processIndexExpression;
|
|
56
57
|
addIndex(meta: EntityMetadata, index: {
|
|
57
|
-
properties
|
|
58
|
+
properties?: string | string[];
|
|
58
59
|
name?: string;
|
|
59
60
|
type?: string;
|
|
60
|
-
expression?: string
|
|
61
|
-
deferMode?: DeferMode
|
|
61
|
+
expression?: string | IndexCallback<any>;
|
|
62
|
+
deferMode?: DeferMode | `${DeferMode}`;
|
|
62
63
|
options?: Dictionary;
|
|
63
64
|
}, type: 'index' | 'unique' | 'primary'): void;
|
|
64
65
|
addCheck(check: CheckDef): void;
|
package/schema/DatabaseTable.js
CHANGED
|
@@ -700,6 +700,18 @@ class DatabaseTable {
|
|
|
700
700
|
}
|
|
701
701
|
return '' + val;
|
|
702
702
|
}
|
|
703
|
+
processIndexExpression(expression, meta) {
|
|
704
|
+
if (expression instanceof Function) {
|
|
705
|
+
const exp = expression({ name: this.name, schema: this.schema, toString() {
|
|
706
|
+
if (this.schema) {
|
|
707
|
+
return `${this.schema}.${this.name}`;
|
|
708
|
+
}
|
|
709
|
+
return this.name;
|
|
710
|
+
} }, meta.createColumnMappingObject());
|
|
711
|
+
return exp instanceof core_1.RawQueryFragment ? this.platform.formatQuery(exp.sql, exp.params) : exp;
|
|
712
|
+
}
|
|
713
|
+
return expression;
|
|
714
|
+
}
|
|
703
715
|
addIndex(meta, index, type) {
|
|
704
716
|
const properties = core_1.Utils.unique(core_1.Utils.flatten(core_1.Utils.asArray(index.properties).map(prop => {
|
|
705
717
|
const parts = prop.split('.');
|
|
@@ -741,7 +753,7 @@ class DatabaseTable {
|
|
|
741
753
|
primary: type === 'primary',
|
|
742
754
|
unique: type !== 'index',
|
|
743
755
|
type: index.type,
|
|
744
|
-
expression: index.expression,
|
|
756
|
+
expression: this.processIndexExpression(index.expression, meta),
|
|
745
757
|
options: index.options,
|
|
746
758
|
deferMode: index.deferMode,
|
|
747
759
|
});
|
package/typings.d.ts
CHANGED