@mikro-orm/knex 6.4.17-dev.4 → 6.4.17-dev.40
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 +16 -10
- package/dialects/mysql/MySqlSchemaHelper.js +8 -1
- package/index.mjs +2 -0
- package/package.json +2 -2
- package/query/CriteriaNodeFactory.js +3 -2
- package/schema/DatabaseTable.d.ts +5 -4
- package/schema/DatabaseTable.js +14 -1
- package/schema/SchemaHelper.js +1 -1
- package/typings.d.ts +2 -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 = {}) {
|
|
@@ -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) {
|
|
@@ -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.40",
|
|
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.40",
|
|
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) {
|
|
@@ -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
|
@@ -115,6 +115,7 @@ class DatabaseTable {
|
|
|
115
115
|
localTableName: this.getShortestName(),
|
|
116
116
|
referencedColumnNames: prop.referencedColumnNames,
|
|
117
117
|
referencedTableName: schema ? `${schema}.${prop.referencedTableName}` : prop.referencedTableName,
|
|
118
|
+
createForeignKeyConstraint: prop.createForeignKeyConstraint,
|
|
118
119
|
};
|
|
119
120
|
const cascade = prop.cascade.includes(core_1.Cascade.REMOVE) || prop.cascade.includes(core_1.Cascade.ALL);
|
|
120
121
|
if (prop.deleteRule || cascade || prop.nullable) {
|
|
@@ -699,6 +700,18 @@ class DatabaseTable {
|
|
|
699
700
|
}
|
|
700
701
|
return '' + val;
|
|
701
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
|
+
}
|
|
702
715
|
addIndex(meta, index, type) {
|
|
703
716
|
const properties = core_1.Utils.unique(core_1.Utils.flatten(core_1.Utils.asArray(index.properties).map(prop => {
|
|
704
717
|
const parts = prop.split('.');
|
|
@@ -740,7 +753,7 @@ class DatabaseTable {
|
|
|
740
753
|
primary: type === 'primary',
|
|
741
754
|
unique: type !== 'index',
|
|
742
755
|
type: index.type,
|
|
743
|
-
expression: index.expression,
|
|
756
|
+
expression: this.processIndexExpression(index.expression, meta),
|
|
744
757
|
options: index.options,
|
|
745
758
|
deferMode: index.deferMode,
|
|
746
759
|
});
|
package/schema/SchemaHelper.js
CHANGED
|
@@ -321,7 +321,7 @@ class SchemaHelper {
|
|
|
321
321
|
});
|
|
322
322
|
}
|
|
323
323
|
createForeignKey(table, foreignKey, schema) {
|
|
324
|
-
if (!this.options.createForeignKeyConstraints) {
|
|
324
|
+
if (!this.options.createForeignKeyConstraints || !foreignKey.createForeignKeyConstraint) {
|
|
325
325
|
return;
|
|
326
326
|
}
|
|
327
327
|
const builder = table
|
package/typings.d.ts
CHANGED
|
@@ -59,6 +59,7 @@ export interface ForeignKey {
|
|
|
59
59
|
updateRule?: string;
|
|
60
60
|
deleteRule?: string;
|
|
61
61
|
deferMode?: DeferMode;
|
|
62
|
+
createForeignKeyConstraint: boolean;
|
|
62
63
|
}
|
|
63
64
|
export interface IndexDef {
|
|
64
65
|
columnNames: string[];
|
|
@@ -74,7 +75,7 @@ export interface IndexDef {
|
|
|
74
75
|
storageEngineIndexType?: 'hash' | 'btree';
|
|
75
76
|
predicate?: Knex.QueryBuilder;
|
|
76
77
|
}>;
|
|
77
|
-
deferMode?: DeferMode
|
|
78
|
+
deferMode?: DeferMode | `${DeferMode}`;
|
|
78
79
|
}
|
|
79
80
|
export interface CheckDef<T = unknown> {
|
|
80
81
|
name: string;
|