@mikro-orm/knex 6.0.2-dev.0 → 6.0.2-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.
@@ -130,7 +130,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
130
130
  return res;
131
131
  }
132
132
  async wrapVirtualExpressionInSubquery(meta, expression, where, options, type) {
133
- const qb = this.createQueryBuilder(meta.className, options?.ctx, options.connectionType, options.convertCustomTypes)
133
+ const qb = this.createQueryBuilder(meta.className, options?.ctx, options.connectionType, options.convertCustomTypes, options.logging)
134
134
  .indexHint(options.indexHint)
135
135
  .comment(options.comments)
136
136
  .hintComment(options.hintComments);
@@ -285,7 +285,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
285
285
  if (meta?.virtual) {
286
286
  return this.countVirtual(entityName, where, options);
287
287
  }
288
- const qb = this.createQueryBuilder(entityName, options.ctx, options.connectionType, false)
288
+ const qb = this.createQueryBuilder(entityName, options.ctx, options.connectionType, false, options.logging)
289
289
  .indexHint(options.indexHint)
290
290
  .comment(options.comments)
291
291
  .hintComment(options.hintComments)
@@ -664,7 +664,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
664
664
  const pivotProp2 = pivotMeta.relations[prop.owner ? 0 : 1];
665
665
  const ownerMeta = this.metadata.find(pivotProp2.type);
666
666
  options = { ...options };
667
- const qb = this.createQueryBuilder(prop.pivotEntity, ctx, options.connectionType)
667
+ const qb = this.createQueryBuilder(prop.pivotEntity, ctx, options.connectionType, undefined, options?.logging)
668
668
  .withSchema(this.getSchemaName(pivotMeta, options))
669
669
  .indexHint(options.indexHint)
670
670
  .comment(options.comments)
@@ -972,7 +972,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
972
972
  }
973
973
  async lockPessimistic(entity, options) {
974
974
  const meta = (0, core_1.helper)(entity).__meta;
975
- const qb = this.createQueryBuilder(entity.constructor.name, options.ctx).withSchema(options.schema ?? meta.schema);
975
+ const qb = this.createQueryBuilder(entity.constructor.name, options.ctx, undefined, undefined, options.logging).withSchema(options.schema ?? meta.schema);
976
976
  const cond = core_1.Utils.getPrimaryKeyCond(entity, meta.primaryKeys);
977
977
  qb.select((0, core_1.raw)('1')).where(cond).setLockMode(options.lockMode, options.lockTableAliases);
978
978
  await this.rethrow(qb.execute());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "6.0.2-dev.0",
3
+ "version": "6.0.2-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,6 +66,6 @@
66
66
  "@mikro-orm/core": "^6.0.1"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.0.2-dev.0"
69
+ "@mikro-orm/core": "6.0.2-dev.10"
70
70
  }
71
71
  }
@@ -27,8 +27,11 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
27
27
  throw new Error('Mixing collection operators with other filters is not allowed.');
28
28
  }
29
29
  const payload = this.payload[key].unwrap();
30
- const sub = qb.clone(true).innerJoin(this.key, qb.getNextAlias(this.prop.type));
31
- sub.select(this.prop.targetMeta.primaryKeys);
30
+ const sub = qb
31
+ .clone(true)
32
+ .from(this.parent.entityName)
33
+ .innerJoin(this.key, qb.getNextAlias(this.prop.type))
34
+ .select(this.prop.targetMeta.primaryKeys);
32
35
  if (key === '$every') {
33
36
  sub.where({ $not: { [this.key]: payload } });
34
37
  }
@@ -153,7 +153,7 @@ class DatabaseTable {
153
153
  }
154
154
  getEntityDeclaration(namingStrategy, schemaHelper, scalarPropertiesForRelations) {
155
155
  const { fksOnColumnProps, fksOnStandaloneProps, columnFks, fkIndexes, nullableForeignKeys, skippedColumnNames, } = this.foreignKeysToProps(namingStrategy, scalarPropertiesForRelations);
156
- let name = namingStrategy.getClassName(this.name, '_');
156
+ let name = namingStrategy.getEntityName(this.name, this.schema);
157
157
  name = name.match(/^\d/) ? 'E' + name : name;
158
158
  const schema = new core_1.EntitySchema({ name, collection: this.name, schema: this.schema });
159
159
  const compositeFkIndexes = {};
@@ -561,7 +561,7 @@ class DatabaseTable {
561
561
  }
562
562
  getPropertyTypeForForeignKey(namingStrategy, fk) {
563
563
  const parts = fk.referencedTableName.split('.', 2);
564
- return namingStrategy.getClassName(parts.length > 1 ? parts[1] : parts[0], '_');
564
+ return namingStrategy.getEntityName(...parts.reverse());
565
565
  }
566
566
  getPropertyTypeForColumn(namingStrategy, column, fk) {
567
567
  if (fk) {
package/typings.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Knex } from 'knex';
2
- import type { CheckCallback, Dictionary, EntityProperty, GroupOperator, RawQueryFragment, QBFilterQuery, QueryOrderMap, Type, QueryFlag } from '@mikro-orm/core';
2
+ import type { CheckCallback, Dictionary, EntityProperty, GroupOperator, RawQueryFragment, QBFilterQuery, QueryOrderMap, Type, QueryFlag, AnyEntity, EntityName } from '@mikro-orm/core';
3
3
  import type { JoinType, QueryType } from './query/enums';
4
4
  import type { DatabaseSchema, DatabaseTable } from './schema';
5
5
  export interface Table {
@@ -120,6 +120,7 @@ export interface IQueryBuilder<T> {
120
120
  _fields?: Field<T>[];
121
121
  select(fields: Field<T> | Field<T>[], distinct?: boolean): this;
122
122
  addSelect(fields: string | string[]): this;
123
+ from<T extends AnyEntity<T> = AnyEntity>(target: EntityName<T> | IQueryBuilder<T>, aliasName?: string): IQueryBuilder<T>;
123
124
  insert(data: any): this;
124
125
  update(data: any): this;
125
126
  delete(cond?: QBFilterQuery): this;