metal-orm 1.0.85 → 1.0.87

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.
@@ -68,7 +68,7 @@ import { SelectCTEFacet } from './select/cte-facet.js';
68
68
  import { SelectSetOpFacet } from './select/setop-facet.js';
69
69
  import { SelectRelationFacet } from './select/relation-facet.js';
70
70
  import { buildFilterParameters, extractSchema, SchemaOptions, OpenApiSchemaBundle } from '../openapi/index.js';
71
- import { hasParamOperandsInQuery } from '../core/ast/ast-validation.js';
71
+ import { findFirstParamOperandName } from '../core/ast/ast-validation.js';
72
72
 
73
73
  type ColumnSelectionValue =
74
74
  | ColumnDef
@@ -82,10 +82,14 @@ type SelectionValueType<TValue> =
82
82
  TValue extends ColumnDef ? ColumnToTs<TValue> :
83
83
  unknown;
84
84
 
85
- type SelectionResult<TSelection extends Record<string, ColumnSelectionValue>> = {
86
- [K in keyof TSelection]: SelectionValueType<TSelection[K]>;
87
- };
88
-
85
+ type SelectionResult<TSelection extends Record<string, ColumnSelectionValue>> = {
86
+ [K in keyof TSelection]: SelectionValueType<TSelection[K]>;
87
+ };
88
+
89
+ type ParamOperandCompileOptions = {
90
+ allowParamOperands?: boolean;
91
+ };
92
+
89
93
  type SelectionFromKeys<
90
94
  TTable extends TableDef,
91
95
  K extends keyof TTable['columns'] & string
@@ -732,9 +736,9 @@ export class SelectQueryBuilder<T = EntityInstance<TableDef>, TTable extends Tab
732
736
  */
733
737
  private validateNoParamOperands(): void {
734
738
  const ast = this.context.hydration.applyToAst(this.context.state.ast);
735
- const hasParams = hasParamOperandsInQuery(ast);
736
- if (hasParams) {
737
- throw new Error('Cannot execute query containing Param operands. Param proxies are only for schema generation (getSchema()). If you need real parameters, use literal values.');
739
+ const paramName = findFirstParamOperandName(ast);
740
+ if (paramName) {
741
+ throw new Error(`Cannot execute query containing Param operand "${paramName}". Param proxies are only for schema generation (getSchema()). If you need real parameters, use literal values.`);
738
742
  }
739
743
  }
740
744
 
@@ -1109,10 +1113,18 @@ export class SelectQueryBuilder<T = EntityInstance<TableDef>, TTable extends Tab
1109
1113
  * .compile('postgres');
1110
1114
  * console.log(compiled.sql); // SELECT "id", "name" FROM "users" WHERE "active" = true
1111
1115
  */
1112
- compile(dialect: SelectDialectInput): CompiledQuery {
1113
- const resolved = resolveDialectInput(dialect);
1114
- return resolved.compileSelect(this.getAST());
1115
- }
1116
+ compile(dialect: SelectDialectInput, options?: ParamOperandCompileOptions): CompiledQuery {
1117
+ const resolved = resolveDialectInput(dialect);
1118
+ const ast = this.getAST();
1119
+ if (!options?.allowParamOperands) {
1120
+ const paramName = findFirstParamOperandName(ast);
1121
+ if (paramName) {
1122
+ throw new Error(`Cannot compile query containing Param operand "${paramName}". Param proxies are only for schema generation (getSchema()). If you need real parameters, use literal values.`);
1123
+ }
1124
+ return resolved.compileSelect(ast);
1125
+ }
1126
+ return resolved.compileSelectWithOptions(ast, { allowParams: true });
1127
+ }
1116
1128
 
1117
1129
  /**
1118
1130
  * Converts the query to SQL string for a specific dialect
@@ -1124,9 +1136,9 @@ export class SelectQueryBuilder<T = EntityInstance<TableDef>, TTable extends Tab
1124
1136
  * .toSql('postgres');
1125
1137
  * console.log(sql); // SELECT "id", "name" FROM "users" WHERE "active" = true
1126
1138
  */
1127
- toSql(dialect: SelectDialectInput): string {
1128
- return this.compile(dialect).sql;
1129
- }
1139
+ toSql(dialect: SelectDialectInput, options?: ParamOperandCompileOptions): string {
1140
+ return this.compile(dialect, options).sql;
1141
+ }
1130
1142
 
1131
1143
  /**
1132
1144
  * Gets hydration plan for query