@mikro-orm/knex 6.1.5-dev.3 → 6.1.5-dev.5

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.
@@ -1129,6 +1129,9 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
1129
1129
  }
1130
1130
  return;
1131
1131
  }
1132
+ if (prop.persist === false && !prop.embedded && !prop.formula) {
1133
+ return;
1134
+ }
1132
1135
  ret.push(prop.name);
1133
1136
  }
1134
1137
  buildFields(meta, populate, joinedProps, qb, alias, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "6.1.5-dev.3",
3
+ "version": "6.1.5-dev.5",
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": "^6.1.4"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.1.5-dev.3"
69
+ "@mikro-orm/core": "6.1.5-dev.5"
70
70
  }
71
71
  }
@@ -909,6 +909,9 @@ class QueryBuilder {
909
909
  if (prop && [core_1.ReferenceKind.ONE_TO_MANY, core_1.ReferenceKind.MANY_TO_MANY].includes(prop.kind)) {
910
910
  return;
911
911
  }
912
+ if (prop?.persist === false && !prop.embedded && !prop.formula && type === 'where') {
913
+ return;
914
+ }
912
915
  if (prop?.embedded) {
913
916
  const name = prop.embeddedPath?.join('.') ?? prop.fieldNames[0];
914
917
  const aliased = this._aliases[a] ? `${a}.${name}` : name;
@@ -477,8 +477,11 @@ class DatabaseTable {
477
477
  const columnOptions = {};
478
478
  if (fk.columnNames.length === 1) {
479
479
  const column = this.getColumn(fk.columnNames[0]);
480
- columnOptions.default = this.getPropertyDefaultValue(schemaHelper, column, type);
481
- columnOptions.defaultRaw = this.getPropertyDefaultValue(schemaHelper, column, type, true);
480
+ const defaultRaw = this.getPropertyDefaultValue(schemaHelper, column, column.type, true);
481
+ const defaultTs = this.getPropertyDefaultValue(schemaHelper, column, column.type);
482
+ columnOptions.default = defaultRaw !== defaultTs ? defaultTs : undefined;
483
+ columnOptions.defaultRaw = (column.nullable && defaultRaw === 'null') ? undefined : defaultRaw;
484
+ columnOptions.optional = typeof column.generated !== 'undefined' || defaultTs != null;
482
485
  columnOptions.generated = column.generated;
483
486
  columnOptions.nullable = column.nullable;
484
487
  columnOptions.primary = column.primary;
@@ -507,6 +510,9 @@ class DatabaseTable {
507
510
  const unique = compositeFkUniques[prop] || this.indexes.find(idx => idx.columnNames[0] === column.name && !idx.composite && idx.unique && !idx.primary);
508
511
  const kind = this.getReferenceKind(fk, unique);
509
512
  const type = this.getPropertyTypeForColumn(namingStrategy, column, fk);
513
+ const defaultRaw = this.getPropertyDefaultValue(schemaHelper, column, type, true);
514
+ const defaultParsed = this.getPropertyDefaultValue(schemaHelper, column, type);
515
+ const defaultTs = defaultRaw !== defaultParsed ? defaultParsed : undefined;
510
516
  const fkOptions = {};
511
517
  if (fk) {
512
518
  fkOptions.fieldNames = fk.columnNames;
@@ -520,9 +526,10 @@ class DatabaseTable {
520
526
  type,
521
527
  kind,
522
528
  generated: column.generated,
529
+ optional: defaultRaw !== 'null' || defaultTs != null || typeof column.generated !== 'undefined',
523
530
  columnType: column.type,
524
- default: this.getPropertyDefaultValue(schemaHelper, column, type),
525
- defaultRaw: this.getPropertyDefaultValue(schemaHelper, column, type, true),
531
+ default: defaultTs,
532
+ defaultRaw: (column.nullable && defaultRaw === 'null') ? undefined : defaultRaw,
526
533
  nullable: column.nullable,
527
534
  primary: column.primary && persist,
528
535
  autoincrement: column.autoincrement,
@@ -591,7 +598,7 @@ class DatabaseTable {
591
598
  if (propType === 'boolean' && !raw) {
592
599
  return !['0', 'false', 'f', 'n', 'no', 'off'].includes('' + column.default);
593
600
  }
594
- if (propType === 'number') {
601
+ if (propType === 'number' && !raw) {
595
602
  return +column.default;
596
603
  }
597
604
  // unquote string defaults if `raw = false`