@mikro-orm/knex 6.5.8-dev.1 → 6.5.8-dev.10

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.
@@ -52,6 +52,7 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
52
52
  * @internal
53
53
  */
54
54
  mergeJoinedResult<T extends object>(rawResults: EntityData<T>[], meta: EntityMetadata<T>, joinedProps: PopulateOptions<T>[]): EntityData<T>[];
55
+ protected shouldHaveColumn<T, U>(meta: EntityMetadata<T>, prop: EntityProperty<U>, populate: PopulateOptions<U>[], fields?: Field<U>[], exclude?: Field<U>[]): boolean;
55
56
  protected getFieldsForJoinedLoad<T extends object>(qb: QueryBuilder<T, any, any, any>, meta: EntityMetadata<T>, explicitFields?: Field<T>[], exclude?: Field<T>[], populate?: PopulateOptions<T>[], options?: {
56
57
  strategy?: Options['loadStrategy'];
57
58
  populateWhere?: FindOptions<any>['populateWhere'];
@@ -60,7 +61,7 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
60
61
  /**
61
62
  * @internal
62
63
  */
63
- mapPropToFieldNames<T extends object>(qb: QueryBuilder<T, any, any, any>, prop: EntityProperty<T>, tableAlias?: string): Field<T>[];
64
+ mapPropToFieldNames<T extends object>(qb: QueryBuilder<T, any, any, any>, prop: EntityProperty<T>, tableAlias?: string, explicitFields?: Field<T>[]): Field<T>[];
64
65
  /** @internal */
65
66
  createQueryBuilder<T extends object>(entityName: EntityName<T> | QueryBuilder<T, any, any, any>, ctx?: Transaction<Knex.Transaction>, preferredConnectionType?: ConnectionType, convertCustomTypes?: boolean, loggerContext?: LoggingOptions, alias?: string, em?: SqlEntityManager): QueryBuilder<T, any, any, any>;
66
67
  protected resolveConnectionType(args: {
@@ -922,25 +922,25 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
922
922
  }
923
923
  return res;
924
924
  }
925
+ shouldHaveColumn(meta, prop, populate, fields, exclude) {
926
+ if (!this.platform.shouldHaveColumn(prop, populate, exclude)) {
927
+ return false;
928
+ }
929
+ if (!fields || fields.includes('*') || prop.primary || meta.root.discriminatorColumn === prop.name) {
930
+ return true;
931
+ }
932
+ return fields.some(f => f === prop.name || f.toString().startsWith(prop.name + '.'));
933
+ }
925
934
  getFieldsForJoinedLoad(qb, meta, explicitFields, exclude, populate = [], options, parentTableAlias, parentJoinPath) {
926
935
  const fields = [];
927
936
  const joinedProps = this.joinedProps(meta, populate, options);
928
- const shouldHaveColumn = (meta, prop, populate, fields) => {
929
- if (!this.platform.shouldHaveColumn(prop, populate, exclude)) {
930
- return false;
931
- }
932
- if (!fields || fields.includes('*') || prop.primary || meta.root.discriminatorColumn === prop.name) {
933
- return true;
934
- }
935
- return fields.some(f => f === prop.name || f.toString().startsWith(prop.name + '.'));
936
- };
937
937
  const populateWhereAll = options?._populateWhere === 'all' || core_1.Utils.isEmpty(options?._populateWhere);
938
938
  // root entity is already handled, skip that
939
939
  if (parentJoinPath) {
940
940
  // alias all fields in the primary table
941
941
  meta.props
942
- .filter(prop => shouldHaveColumn(meta, prop, populate, explicitFields))
943
- .forEach(prop => fields.push(...this.mapPropToFieldNames(qb, prop, parentTableAlias)));
942
+ .filter(prop => this.shouldHaveColumn(meta, prop, populate, explicitFields, exclude))
943
+ .forEach(prop => fields.push(...this.mapPropToFieldNames(qb, prop, parentTableAlias, explicitFields)));
944
944
  }
945
945
  for (const hint of joinedProps) {
946
946
  const [propName, ref] = hint.field.split(':', 2);
@@ -991,10 +991,14 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
991
991
  /**
992
992
  * @internal
993
993
  */
994
- mapPropToFieldNames(qb, prop, tableAlias) {
994
+ mapPropToFieldNames(qb, prop, tableAlias, explicitFields) {
995
995
  if (prop.kind === core_1.ReferenceKind.EMBEDDED && !prop.object) {
996
- return Object.values(prop.embeddedProps).flatMap(childProp => {
997
- return this.mapPropToFieldNames(qb, childProp, tableAlias);
996
+ return Object.entries(prop.embeddedProps).flatMap(([name, childProp]) => {
997
+ const childFields = explicitFields ? core_1.Utils.extractChildElements(explicitFields, prop.name) : [];
998
+ if (childFields.length > 0 && !this.shouldHaveColumn(prop.targetMeta, { ...childProp, name }, [], childFields)) {
999
+ return [];
1000
+ }
1001
+ return this.mapPropToFieldNames(qb, childProp, tableAlias, childFields);
998
1002
  });
999
1003
  }
1000
1004
  const aliased = this.platform.quoteIdentifier(tableAlias ? `${tableAlias}__${prop.fieldNames[0]}` : prop.fieldNames[0]);
@@ -1286,7 +1290,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
1286
1290
  }
1287
1291
  }
1288
1292
  else if (!core_1.Utils.isEmpty(options.exclude) || lazyProps.some(p => !p.formula && (p.kind !== '1:1' || p.owner))) {
1289
- const props = meta.props.filter(prop => this.platform.shouldHaveColumn(prop, populate, options.exclude, false));
1293
+ const props = meta.props.filter(prop => this.platform.shouldHaveColumn(prop, populate, options.exclude, false, false));
1290
1294
  ret.push(...props.filter(p => !lazyProps.includes(p)).map(p => p.name));
1291
1295
  addFormulas = true;
1292
1296
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "6.5.8-dev.1",
3
+ "version": "6.5.8-dev.10",
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.5.7"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.5.8-dev.1",
69
+ "@mikro-orm/core": "6.5.8-dev.10",
70
70
  "better-sqlite3": "*",
71
71
  "libsql": "*",
72
72
  "mariadb": "*"
@@ -1310,10 +1310,11 @@ class QueryBuilder {
1310
1310
  }
1311
1311
  else if (join.parent?.type === enums_1.JoinType.nestedInnerJoin) {
1312
1312
  const group = lookupParentGroup(join.parent);
1313
+ const nested = group ?? ((join.parent).nested ??= new Set());
1313
1314
  join.type = join.type === enums_1.JoinType.innerJoin
1314
1315
  ? enums_1.JoinType.nestedInnerJoin
1315
1316
  : enums_1.JoinType.nestedLeftJoin;
1316
- group?.add(join);
1317
+ nested.add(join);
1317
1318
  }
1318
1319
  }
1319
1320
  }
@@ -108,10 +108,15 @@ class DatabaseSchema {
108
108
  table.addIndex(meta, { properties: meta.props.filter(prop => prop.primary).map(prop => prop.name) }, 'primary');
109
109
  meta.checks.forEach(check => {
110
110
  const columnName = check.property ? meta.properties[check.property].fieldNames[0] : undefined;
111
+ let expression = check.expression;
112
+ const raw = core_1.RawQueryFragment.getKnownFragment(expression);
113
+ if (raw) {
114
+ expression = platform.formatQuery(raw.sql, raw.params);
115
+ }
111
116
  table.addCheck({
112
117
  name: check.name,
113
- expression: check.expression,
114
- definition: `check ((${check.expression}))`,
118
+ expression,
119
+ definition: `check ((${expression}))`,
115
120
  columnName,
116
121
  });
117
122
  });