@mikro-orm/knex 6.4.17-dev.2 → 6.4.17-dev.20

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.
@@ -1311,16 +1311,19 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
1311
1311
  ret.push('*');
1312
1312
  }
1313
1313
  if (ret.length > 0 && !hasExplicitFields && addFormulas) {
1314
- meta.props
1315
- .filter(prop => prop.formula && !lazyProps.includes(prop))
1316
- .forEach(prop => {
1317
- const a = this.platform.quoteIdentifier(alias);
1318
- const aliased = this.platform.quoteIdentifier(prop.fieldNames[0]);
1319
- ret.push((0, core_1.raw)(`${prop.formula(a)} as ${aliased}`));
1320
- });
1321
- meta.props
1322
- .filter(prop => !prop.object && (prop.hasConvertToDatabaseValueSQL || prop.hasConvertToJSValueSQL))
1323
- .forEach(prop => ret.push(prop.name));
1314
+ for (const prop of meta.props) {
1315
+ if (lazyProps.includes(prop)) {
1316
+ continue;
1317
+ }
1318
+ if (prop.formula) {
1319
+ const a = this.platform.quoteIdentifier(alias);
1320
+ const aliased = this.platform.quoteIdentifier(prop.fieldNames[0]);
1321
+ ret.push((0, core_1.raw)(`${prop.formula(a)} as ${aliased}`));
1322
+ }
1323
+ if (!prop.object && (prop.hasConvertToDatabaseValueSQL || prop.hasConvertToJSValueSQL)) {
1324
+ ret.push(prop.name);
1325
+ }
1326
+ }
1324
1327
  }
1325
1328
  // add joined relations after the root entity fields
1326
1329
  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
- col.defaultTo(knex.raw(column.default + (column.extra ? ' ' + column.extra : '')));
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "6.4.17-dev.2",
3
+ "version": "6.4.17-dev.20",
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.2",
69
+ "@mikro-orm/core": "6.4.17-dev.20",
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
- if (prop?.customType instanceof core_1.JsonType) {
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 (prop?.kind !== core_1.ReferenceKind.EMBEDDED) {
59
+ if (isNotEmbedded) {
59
60
  return this.createNode(metadata, childEntity, payload[key], node, key);
60
61
  }
61
62
  if (payload[key] == null) {
@@ -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) {
@@ -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[];