@mikro-orm/knex 6.6.3-dev.1 → 6.6.3-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.
@@ -31,7 +31,8 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
31
31
  }
32
32
  const populate = this.autoJoinOneToOneOwner(meta, options.populate, options.fields);
33
33
  const joinedProps = this.joinedProps(meta, populate, options);
34
- const qb = this.createQueryBuilder(entityName, options.ctx, options.connectionType, false, options.logging);
34
+ const qb = this.createQueryBuilder(entityName, options.ctx, options.connectionType, false, options.logging)
35
+ .withSchema(this.getSchemaName(meta, options));
35
36
  const fields = this.buildFields(meta, populate, joinedProps, qb, qb.alias, options);
36
37
  const orderBy = this.buildOrderBy(qb, meta, populate, options);
37
38
  const populateWhere = this.buildPopulateWhere(meta, joinedProps, options);
@@ -50,8 +51,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
50
51
  .having(options.having)
51
52
  .indexHint(options.indexHint)
52
53
  .comment(options.comments)
53
- .hintComment(options.hintComments)
54
- .withSchema(this.getSchemaName(meta, options));
54
+ .hintComment(options.hintComments);
55
55
  if (isCursorPagination) {
56
56
  const { orderBy: newOrderBy, where } = this.processCursorOptions(meta, options, orderBy);
57
57
  qb.andWhere(where).orderBy(newOrderBy);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "6.6.3-dev.1",
3
+ "version": "6.6.3-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.6.2"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.6.3-dev.1",
69
+ "@mikro-orm/core": "6.6.3-dev.10",
70
70
  "better-sqlite3": "*",
71
71
  "libsql": "*",
72
72
  "mariadb": "*"
@@ -38,7 +38,7 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
38
38
  throw new Error('Mixing collection operators with other filters is not allowed.');
39
39
  }
40
40
  const payload = this.payload[key].unwrap();
41
- const qb2 = qb.clone(true);
41
+ const qb2 = qb.clone(true, ['_schema']);
42
42
  const sub = qb2
43
43
  .from(parentMeta.className)
44
44
  .innerJoin(this.key, qb2.getNextAlias(this.prop.type))
@@ -278,7 +278,7 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
278
278
  * You can provide `EntityName.propName` as alias, then the field name will be used based on the metadata
279
279
  */
280
280
  as(alias: string): Knex.QueryBuilder;
281
- clone(reset?: boolean | string[]): QueryBuilder<Entity>;
281
+ clone(reset?: boolean | string[], preserve?: string[]): QueryBuilder<Entity>;
282
282
  getKnex(processVirtualEntity?: boolean): Knex.QueryBuilder;
283
283
  /**
284
284
  * Sets logger context for this query builder.
@@ -833,11 +833,8 @@ class QueryBuilder {
833
833
  Object.defineProperty(ret, '__as', { enumerable: false, value: alias });
834
834
  return ret;
835
835
  }
836
- clone(reset) {
836
+ clone(reset, preserve) {
837
837
  const qb = new QueryBuilder(this.mainAlias.entityName, this.metadata, this.driver, this.context, this.mainAlias.aliasName, this.connectionType, this.em);
838
- if (reset === true) {
839
- return qb;
840
- }
841
838
  reset = reset || [];
842
839
  // clone array/object properties
843
840
  const properties = [
@@ -847,14 +844,14 @@ class QueryBuilder {
847
844
  ];
848
845
  core_1.RawQueryFragment.cloneRegistry = this.rawFragments;
849
846
  for (const prop of Object.keys(this)) {
850
- if (reset.includes(prop) || prop === '_helper') {
847
+ if (!preserve?.includes(prop) && (reset === true || reset.includes(prop) || prop === '_helper')) {
851
848
  continue;
852
849
  }
853
850
  qb[prop] = properties.includes(prop) ? core_1.Utils.copy(this[prop]) : this[prop];
854
851
  }
855
852
  delete core_1.RawQueryFragment.cloneRegistry;
856
853
  /* istanbul ignore else */
857
- if (this._fields && !reset.includes('_fields')) {
854
+ if (this._fields && reset !== true && !reset.includes('_fields')) {
858
855
  qb._fields = [...this._fields];
859
856
  }
860
857
  qb._aliases = { ...this._aliases };
@@ -187,7 +187,7 @@ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
187
187
  options.dropTables ??= true;
188
188
  const toSchema = this.getTargetSchema(options.schema);
189
189
  const schemas = toSchema.getNamespaces();
190
- const fromSchema = options.fromSchema ?? await DatabaseSchema_1.DatabaseSchema.create(this.connection, this.platform, this.config, options.schema, schemas);
190
+ const fromSchema = options.fromSchema ?? await DatabaseSchema_1.DatabaseSchema.create(this.connection, this.platform, this.config, options.schema, schemas, undefined, this.options.skipTables);
191
191
  const wildcardSchemaTables = Object.values(this.metadata.getAll()).filter(meta => meta.schema === '*').map(meta => meta.tableName);
192
192
  fromSchema.prune(options.schema, wildcardSchemaTables);
193
193
  toSchema.prune(options.schema, wildcardSchemaTables);
package/typings.d.ts CHANGED
@@ -160,11 +160,12 @@ export interface IQueryBuilder<T> {
160
160
  getAliasForJoinPath(path: string, options?: ICriteriaNodeProcessOptions): string | undefined;
161
161
  getJoinForPath(path?: string, options?: ICriteriaNodeProcessOptions): JoinOptions | undefined;
162
162
  getNextAlias(entityName?: string): string;
163
- clone(reset?: boolean): IQueryBuilder<T>;
163
+ clone(reset?: boolean | string[], preserve?: string[]): IQueryBuilder<T>;
164
164
  setFlag(flag: QueryFlag): this;
165
165
  unsetFlag(flag: QueryFlag): this;
166
166
  hasFlag(flag: QueryFlag): boolean;
167
167
  scheduleFilterCheck(path: string): void;
168
+ withSchema(schema: string): this;
168
169
  }
169
170
  export interface ICriteriaNodeProcessOptions {
170
171
  alias?: string;