@mikro-orm/sql 7.2.2-dev.1 → 7.2.2-dev.3

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.
@@ -17,7 +17,7 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
17
17
  /** Evaluates a formula callback, handling both string and Raw return values. */
18
18
  evaluateFormula(formula: (...args: any[]) => string | Raw, columns: any, table: FormulaTable): string;
19
19
  /** For TPT entities, returns ownProps (columns in this table); otherwise returns all props. */
20
- private getTableProps;
20
+ protected getTableProps<T extends object>(meta: EntityMetadata<T>): EntityProperty<T>[];
21
21
  /** Creates a FormulaTable object for use in formula callbacks. */
22
22
  private createFormulaTable;
23
23
  private validateSqlOptions;
@@ -6,6 +6,7 @@ export declare class MsSqlNativeQueryBuilder extends NativeQueryBuilder {
6
6
  params: unknown[];
7
7
  };
8
8
  protected compileInsert(): void;
9
+ protected addOutputClause(type: 'inserted' | 'deleted'): void;
9
10
  private appendOutputTable;
10
11
  private compileUpsert;
11
12
  protected compileSelect(): void;
@@ -22,6 +22,9 @@ export class MsSqlNativeQueryBuilder extends NativeQueryBuilder {
22
22
  this.compileCtes();
23
23
  if (this.options.onConflict && !Utils.isEmpty(Utils.asArray(this.options.data)[0])) {
24
24
  this.compileUpsert();
25
+ if (suffix) {
26
+ this.parts.push(suffix);
27
+ }
25
28
  }
26
29
  else {
27
30
  switch (this.type) {
@@ -72,20 +75,23 @@ export class MsSqlNativeQueryBuilder extends NativeQueryBuilder {
72
75
  return;
73
76
  }
74
77
  const parts = this.processInsertData();
75
- if (this.options.flags?.has(QueryFlag.OUTPUT_TABLE)) {
76
- this.parts[this.parts.length - 2] += ' into #out ';
77
- }
78
78
  this.parts.push(parts.join(', '));
79
79
  }
80
+ addOutputClause(type) {
81
+ super.addOutputClause(type);
82
+ if (this.options.returning?.length && this.options.flags?.has(QueryFlag.OUTPUT_TABLE)) {
83
+ this.parts[this.parts.length - 1] += ' into #out';
84
+ }
85
+ }
80
86
  appendOutputTable() {
81
- if (!this.options.flags?.has(QueryFlag.OUTPUT_TABLE)) {
87
+ if (!this.options.flags?.has(QueryFlag.OUTPUT_TABLE) || !this.options.returning?.length) {
82
88
  return { prefix: '', suffix: '' };
83
89
  }
84
90
  const returningFields = this.options.returning;
85
91
  const selections = returningFields.map(field => `[t].${this.platform.quoteIdentifier(field)}`).join(',');
86
92
  return {
87
93
  prefix: `select top(0) ${selections} into #out from ${this.getTableName()} as t left join ${this.getTableName()} on 0 = 1;`,
88
- suffix: `select ${selections} from #out as t; drop table #out`,
94
+ suffix: `select ${selections} from #out as t; select @@rowcount as [__mikro_orm_row_count__]; drop table #out`,
89
95
  };
90
96
  }
91
97
  compileUpsert() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/sql",
3
- "version": "7.2.2-dev.1",
3
+ "version": "7.2.2-dev.3",
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
  "keywords": [
6
6
  "data-mapper",
@@ -53,7 +53,7 @@
53
53
  "@mikro-orm/core": "^7.2.1"
54
54
  },
55
55
  "peerDependencies": {
56
- "@mikro-orm/core": "7.2.2-dev.1"
56
+ "@mikro-orm/core": "7.2.2-dev.3"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">= 22.17.0"
@@ -2010,9 +2010,11 @@ export class QueryBuilder {
2010
2010
  }))
2011
2011
  .forEach(field => this.#state.fields.push(raw(field)));
2012
2012
  }
2013
- QueryHelper.processObjectParams(this.#state.data);
2014
- QueryHelper.processObjectParams(this.#state.cond);
2015
- QueryHelper.processObjectParams(this.#state.having);
2013
+ if (this.#state.data) {
2014
+ this.#state.data = QueryHelper.processObjectParams(this.#state.data);
2015
+ }
2016
+ this.#state.cond = QueryHelper.processObjectParams(this.#state.cond);
2017
+ this.#state.having = QueryHelper.processObjectParams(this.#state.having);
2016
2018
  // automatically enable paginate flag when we detect to-many joins, but only if there is no `group by` clause
2017
2019
  if (!this.#state.flags.has(QueryFlag.DISABLE_PAGINATE) &&
2018
2020
  this.#state.groupBy.length === 0 &&