@mikro-orm/knex 5.7.8-dev.0 → 5.7.8-dev.2

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.
@@ -85,14 +85,14 @@ class AbstractSqlConnection extends core_1.Connection {
85
85
  }
86
86
  const formatted = this.platform.formatQuery(queryOrKnex, params);
87
87
  const sql = this.getSql(queryOrKnex, formatted);
88
- const res = await this.executeQuery(sql, () => {
88
+ return this.executeQuery(sql, async () => {
89
89
  const query = this.client.raw(formatted);
90
90
  if (ctx) {
91
91
  query.transacting(ctx);
92
92
  }
93
- return query;
93
+ const res = await query;
94
+ return this.transformRawResult(res, method);
94
95
  }, { query: queryOrKnex, params });
95
- return this.transformRawResult(res, method);
96
96
  }
97
97
  /**
98
98
  * Execute raw SQL queries from file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "5.7.8-dev.0",
3
+ "version": "5.7.8-dev.2",
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,9 +66,9 @@
66
66
  "@mikro-orm/core": "^5.7.7"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "~5.7.8-dev.0",
70
- "@mikro-orm/entity-generator": "~5.7.8-dev.0",
71
- "@mikro-orm/migrations": "~5.7.8-dev.0",
69
+ "@mikro-orm/core": "~5.7.8-dev.2",
70
+ "@mikro-orm/entity-generator": "~5.7.8-dev.2",
71
+ "@mikro-orm/migrations": "~5.7.8-dev.2",
72
72
  "better-sqlite3": "*",
73
73
  "mssql": "*",
74
74
  "mysql": "*",
@@ -90,9 +90,10 @@ export declare class QueryBuilder<T extends object = AnyEntity> {
90
90
  count(field?: string | string[], distinct?: boolean): CountQueryBuilder<T>;
91
91
  join(field: string, alias: string, cond?: QBFilterQuery, type?: 'leftJoin' | 'innerJoin' | 'pivotJoin', path?: string): this;
92
92
  leftJoin(field: string, alias: string, cond?: QBFilterQuery): this;
93
- joinAndSelect(field: string, alias: string, cond?: QBFilterQuery, type?: 'leftJoin' | 'innerJoin' | 'pivotJoin', path?: string): SelectQueryBuilder<T>;
94
- leftJoinAndSelect(field: string, alias: string, cond?: QBFilterQuery): SelectQueryBuilder<T>;
95
- protected getFieldsForJoinedLoad<U extends object>(prop: EntityProperty<U>, alias: string): Field<U>[];
93
+ joinAndSelect(field: string, alias: string, cond?: QBFilterQuery, type?: 'leftJoin' | 'innerJoin' | 'pivotJoin', path?: string, fields?: string[]): SelectQueryBuilder<T>;
94
+ leftJoinAndSelect(field: string, alias: string, cond?: QBFilterQuery, fields?: string[]): SelectQueryBuilder<T>;
95
+ innerJoinAndSelect(field: string, alias: string, cond?: QBFilterQuery, fields?: string[]): SelectQueryBuilder<T>;
96
+ protected getFieldsForJoinedLoad<U extends object>(prop: EntityProperty<U>, alias: string, explicitFields?: string[]): Field<U>[];
96
97
  withSubQuery(subQuery: Knex.QueryBuilder, alias: string): this;
97
98
  where(cond: QBFilterQuery<T>, operator?: keyof typeof GroupOperator): this;
98
99
  where(cond: string, params?: any[], operator?: keyof typeof GroupOperator): this;
@@ -130,12 +130,12 @@ class QueryBuilder {
130
130
  leftJoin(field, alias, cond = {}) {
131
131
  return this.join(field, alias, cond, 'leftJoin');
132
132
  }
133
- joinAndSelect(field, alias, cond = {}, type = 'innerJoin', path) {
133
+ joinAndSelect(field, alias, cond = {}, type = 'innerJoin', path, fields) {
134
134
  if (!this.type) {
135
135
  this.select('*');
136
136
  }
137
137
  const prop = this.joinReference(field, alias, cond, type, path);
138
- this.addSelect(this.getFieldsForJoinedLoad(prop, alias));
138
+ this.addSelect(this.getFieldsForJoinedLoad(prop, alias, fields));
139
139
  const [fromAlias] = this.helper.splitField(field);
140
140
  const populate = this._joinedProps.get(fromAlias);
141
141
  const item = { field: prop.name, strategy: core_1.LoadStrategy.JOINED, children: [] };
@@ -148,13 +148,16 @@ class QueryBuilder {
148
148
  this._joinedProps.set(alias, item);
149
149
  return this;
150
150
  }
151
- leftJoinAndSelect(field, alias, cond = {}) {
152
- return this.joinAndSelect(field, alias, cond, 'leftJoin');
151
+ leftJoinAndSelect(field, alias, cond = {}, fields) {
152
+ return this.joinAndSelect(field, alias, cond, 'leftJoin', undefined, fields);
153
153
  }
154
- getFieldsForJoinedLoad(prop, alias) {
154
+ innerJoinAndSelect(field, alias, cond = {}, fields) {
155
+ return this.joinAndSelect(field, alias, cond, 'innerJoin', undefined, fields);
156
+ }
157
+ getFieldsForJoinedLoad(prop, alias, explicitFields) {
155
158
  const fields = [];
156
159
  prop.targetMeta.props
157
- .filter(prop => this.platform.shouldHaveColumn(prop, this._populate))
160
+ .filter(prop => explicitFields ? explicitFields.includes(prop.name) || prop.primary : this.platform.shouldHaveColumn(prop, this._populate))
158
161
  .forEach(prop => fields.push(...this.driver.mapPropToFieldNames(this, prop, alias)));
159
162
  return fields;
160
163
  }
package/typings.d.ts CHANGED
@@ -122,7 +122,8 @@ export interface IQueryBuilder<T> {
122
122
  join(field: string, alias: string, cond?: QBFilterQuery, type?: 'leftJoin' | 'innerJoin' | 'pivotJoin', path?: string): this;
123
123
  leftJoin(field: string, alias: string, cond?: QBFilterQuery): this;
124
124
  joinAndSelect(field: string, alias: string, cond?: QBFilterQuery): this;
125
- leftJoinAndSelect(field: string, alias: string, cond?: QBFilterQuery): this;
125
+ leftJoinAndSelect(field: string, alias: string, cond?: QBFilterQuery, fields?: string[]): this;
126
+ innerJoinAndSelect(field: string, alias: string, cond?: QBFilterQuery, fields?: string[]): this;
126
127
  withSubQuery(subQuery: Knex.QueryBuilder, alias: string): this;
127
128
  where(cond: QBFilterQuery<T>, operator?: keyof typeof GroupOperator): this;
128
129
  where(cond: string, params?: any[], operator?: keyof typeof GroupOperator): this;