metal-orm 1.0.85 → 1.0.86

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.
package/dist/index.js CHANGED
@@ -770,6 +770,8 @@ var registerExpressionDispatcher = (type, dispatcher) => {
770
770
  var registerOperandDispatcher = (type, dispatcher) => {
771
771
  operandRegistry = operandRegistry.register(type, dispatcher);
772
772
  };
773
+ var hasExpressionDispatcher = (type) => expressionRegistry.get(type) !== void 0;
774
+ var hasOperandDispatcher = (type) => operandRegistry.get(type) !== void 0;
773
775
  var clearExpressionDispatchers = () => {
774
776
  expressionRegistry = expressionRegistry.clear();
775
777
  };
@@ -864,6 +866,12 @@ var visitOperand = (node, visitor) => {
864
866
  case "Collate":
865
867
  if (visitor.visitCollate) return visitor.visitCollate(node);
866
868
  break;
869
+ case "ArithmeticExpression":
870
+ if (visitor.visitArithmeticExpression) return visitor.visitArithmeticExpression(node);
871
+ break;
872
+ case "BitwiseExpression":
873
+ if (visitor.visitBitwiseExpression) return visitor.visitBitwiseExpression(node);
874
+ break;
867
875
  default:
868
876
  break;
869
877
  }
@@ -6152,9 +6160,9 @@ var flattenResults = (results) => {
6152
6160
  }
6153
6161
  return rows;
6154
6162
  };
6155
- var executeWithContexts = async (execCtx, entityCtx, qb) => {
6163
+ var executeWithContexts = async (execCtx, entityCtx, qb, options) => {
6156
6164
  const ast = qb.getAST();
6157
- const compiled = execCtx.dialect.compileSelect(ast);
6165
+ const compiled = options?.allowParamOperands ? execCtx.dialect.compileSelectWithOptions(ast, { allowParams: true }) : execCtx.dialect.compileSelect(ast);
6158
6166
  const executed = await execCtx.interceptors.run({ sql: compiled.sql, params: compiled.params }, execCtx.executor);
6159
6167
  const rows = flattenResults(executed);
6160
6168
  const lazyRelations = qb.getLazyRelations();
@@ -6172,9 +6180,9 @@ var executeWithContexts = async (execCtx, entityCtx, qb) => {
6172
6180
  await preloadRelationIncludes(entities, includeTree);
6173
6181
  return entities;
6174
6182
  };
6175
- var executePlainWithContexts = async (execCtx, qb) => {
6183
+ var executePlainWithContexts = async (execCtx, qb, options) => {
6176
6184
  const ast = qb.getAST();
6177
- const compiled = execCtx.dialect.compileSelect(ast);
6185
+ const compiled = options?.allowParamOperands ? execCtx.dialect.compileSelectWithOptions(ast, { allowParams: true }) : execCtx.dialect.compileSelect(ast);
6178
6186
  const executed = await execCtx.interceptors.run({ sql: compiled.sql, params: compiled.params }, execCtx.executor);
6179
6187
  const rows = flattenResults(executed);
6180
6188
  if (ast.setOps && ast.setOps.length > 0) {
@@ -6182,21 +6190,21 @@ var executePlainWithContexts = async (execCtx, qb) => {
6182
6190
  }
6183
6191
  return hydrateRows(rows, qb.getHydrationPlan());
6184
6192
  };
6185
- async function executeHydrated(session, qb) {
6186
- return executeWithContexts(session.getExecutionContext(), session, qb);
6193
+ async function executeHydrated(session, qb, options) {
6194
+ return executeWithContexts(session.getExecutionContext(), session, qb, options);
6187
6195
  }
6188
- async function executeHydratedPlain(session, qb) {
6189
- return executePlainWithContexts(session.getExecutionContext(), qb);
6196
+ async function executeHydratedPlain(session, qb, options) {
6197
+ return executePlainWithContexts(session.getExecutionContext(), qb, options);
6190
6198
  }
6191
- async function executeHydratedWithContexts(execCtx, hydCtx, qb) {
6199
+ async function executeHydratedWithContexts(execCtx, hydCtx, qb, options) {
6192
6200
  const entityCtx = hydCtx.entityContext;
6193
6201
  if (!entityCtx) {
6194
6202
  throw new Error("Hydration context is missing an EntityContext");
6195
6203
  }
6196
- return executeWithContexts(execCtx, entityCtx, qb);
6204
+ return executeWithContexts(execCtx, entityCtx, qb, options);
6197
6205
  }
6198
- async function executeHydratedPlainWithContexts(execCtx, qb) {
6199
- return executePlainWithContexts(execCtx, qb);
6206
+ async function executeHydratedPlainWithContexts(execCtx, qb, options) {
6207
+ return executePlainWithContexts(execCtx, qb, options);
6200
6208
  }
6201
6209
  var loadLazyRelationsForTable = async (ctx, table, lazyRelations, lazyRelationOptions) => {
6202
6210
  if (!lazyRelations.length) return;
@@ -6397,7 +6405,7 @@ function applyOrderBy(context, predicateFacet, term, directionOrOptions) {
6397
6405
  const dir = options.direction ?? ORDER_DIRECTIONS.ASC;
6398
6406
  return predicateFacet.orderBy(context, term, dir, options.nulls, options.collation);
6399
6407
  }
6400
- async function executeCount(context, env, session) {
6408
+ async function executeCount(context, env, session, options) {
6401
6409
  const unpagedAst = {
6402
6410
  ...context.state.ast,
6403
6411
  orderBy: void 0,
@@ -6417,7 +6425,7 @@ async function executeCount(context, env, session) {
6417
6425
  joins: []
6418
6426
  };
6419
6427
  const execCtx = session.getExecutionContext();
6420
- const compiled = execCtx.dialect.compileSelect(countQuery);
6428
+ const compiled = options?.allowParamOperands ? execCtx.dialect.compileSelectWithOptions(countQuery, { allowParams: true }) : execCtx.dialect.compileSelect(countQuery);
6421
6429
  const results = await execCtx.interceptors.run({ sql: compiled.sql, params: compiled.params }, execCtx.executor);
6422
6430
  const value = results[0]?.values?.[0]?.[0];
6423
6431
  if (typeof value === "number") return value;
@@ -6425,7 +6433,7 @@ async function executeCount(context, env, session) {
6425
6433
  if (typeof value === "string") return Number(value);
6426
6434
  return value === null || value === void 0 ? 0 : Number(value);
6427
6435
  }
6428
- async function executePagedQuery(builder, session, options, countCallback) {
6436
+ async function executePagedQuery(builder, session, options, countCallback, paramOptions) {
6429
6437
  const { page, pageSize } = options;
6430
6438
  if (!Number.isInteger(page) || page < 1) {
6431
6439
  throw new Error("executePaged: page must be an integer >= 1");
@@ -6435,7 +6443,7 @@ async function executePagedQuery(builder, session, options, countCallback) {
6435
6443
  }
6436
6444
  const offset = (page - 1) * pageSize;
6437
6445
  const totalItems = await countCallback(session);
6438
- const items = await builder.limit(pageSize).offset(offset).execute(session);
6446
+ const items = await builder.limit(pageSize).offset(offset).execute(session, paramOptions);
6439
6447
  return { items, totalItems, page, pageSize };
6440
6448
  }
6441
6449
  function buildWhereHasPredicate(env, context, relationFacet, createChildBuilder, relationName, callbackOrOptions, maybeOptions, negate = false) {
@@ -7367,7 +7375,7 @@ var collectFilterColumns = (expr, table, rootTables) => {
7367
7375
  columns.add(node.name);
7368
7376
  }
7369
7377
  };
7370
- const visitOrderingTerm2 = (term) => {
7378
+ const visitOrderingTerm = (term) => {
7371
7379
  if (!term || typeof term !== "object") return;
7372
7380
  if (isOperandNode(term)) {
7373
7381
  visitOperand2(term);
@@ -7379,7 +7387,7 @@ var collectFilterColumns = (expr, table, rootTables) => {
7379
7387
  };
7380
7388
  const visitOrderBy = (orderBy) => {
7381
7389
  if (!orderBy) return;
7382
- orderBy.forEach((node) => visitOrderingTerm2(node.term));
7390
+ orderBy.forEach((node) => visitOrderingTerm(node.term));
7383
7391
  };
7384
7392
  const visitOperand2 = (node) => {
7385
7393
  switch (node.type) {
@@ -7531,137 +7539,174 @@ var getNodeType3 = (value) => {
7531
7539
  }
7532
7540
  return void 0;
7533
7541
  };
7534
- var visitOrderingTerm = (term, visitor) => {
7535
- if (isOperandNode(term)) {
7536
- visitOperandNode(term, visitor);
7537
- return;
7538
- }
7539
- visitExpressionNode(term, visitor);
7540
- };
7541
- var visitOrderByNode = (node, visitor) => {
7542
- visitor.visitOrderBy?.(node);
7543
- visitOrderingTerm(node.term, visitor);
7544
- };
7545
- var visitTableSource = (source, visitor) => {
7546
- visitor.visitTableSource?.(source);
7547
- if (source.type === "DerivedTable") {
7548
- visitor.visitDerivedTable?.(source);
7549
- visitSelectQuery(source.query, visitor);
7550
- return;
7551
- }
7552
- if (source.type === "FunctionTable") {
7553
- visitor.visitFunctionTable?.(source);
7554
- source.args?.forEach((arg) => visitOperandNode(arg, visitor));
7555
- }
7556
- };
7557
- var visitExpressionNode = (node, visitor) => {
7558
- visitor.visitExpression?.(node);
7559
- const type = getNodeType3(node);
7560
- if (!type) return;
7561
- switch (type) {
7562
- case "BinaryExpression":
7563
- visitOperandNode(node.left, visitor);
7564
- visitOperandNode(node.right, visitor);
7565
- if (node.escape) {
7566
- visitOperandNode(node.escape, visitor);
7567
- }
7542
+ var visitSelectQuery = (ast, visitor) => {
7543
+ const visitExpressionNode = (node) => {
7544
+ visitExpression(node, expressionVisitor);
7545
+ };
7546
+ const visitOperandNode = (node) => {
7547
+ visitOperand(node, operandVisitor);
7548
+ };
7549
+ const visitOrderingTerm = (term) => {
7550
+ if (!term || typeof term !== "object") return;
7551
+ if (isOperandNode(term)) {
7552
+ visitOperandNode(term);
7568
7553
  return;
7569
- case "LogicalExpression":
7570
- node.operands.forEach((operand) => visitExpressionNode(operand, visitor));
7554
+ }
7555
+ const type = getNodeType3(term);
7556
+ if (type && hasOperandDispatcher(type)) {
7557
+ visitOperandNode(term);
7571
7558
  return;
7572
- case "NullExpression":
7573
- visitOperandNode(node.left, visitor);
7559
+ }
7560
+ if (type) {
7561
+ visitExpressionNode(term);
7562
+ }
7563
+ };
7564
+ const visitOrderByNode = (node) => {
7565
+ visitor.visitOrderBy?.(node);
7566
+ visitOrderingTerm(node.term);
7567
+ };
7568
+ const visitTableSource = (source) => {
7569
+ visitor.visitTableSource?.(source);
7570
+ if (source.type === "DerivedTable") {
7571
+ visitor.visitDerivedTable?.(source);
7572
+ visitSelectQuery(source.query, visitor);
7574
7573
  return;
7575
- case "InExpression":
7576
- visitOperandNode(node.left, visitor);
7574
+ }
7575
+ if (source.type === "FunctionTable") {
7576
+ visitor.visitFunctionTable?.(source);
7577
+ source.args?.forEach((arg) => visitOperandNode(arg));
7578
+ }
7579
+ };
7580
+ const expressionVisitor = {
7581
+ visitBinaryExpression: (node) => {
7582
+ visitor.visitExpression?.(node);
7583
+ visitOperandNode(node.left);
7584
+ visitOperandNode(node.right);
7585
+ if (node.escape) {
7586
+ visitOperandNode(node.escape);
7587
+ }
7588
+ },
7589
+ visitLogicalExpression: (node) => {
7590
+ visitor.visitExpression?.(node);
7591
+ node.operands.forEach((operand) => visitExpressionNode(operand));
7592
+ },
7593
+ visitNullExpression: (node) => {
7594
+ visitor.visitExpression?.(node);
7595
+ visitOperandNode(node.left);
7596
+ },
7597
+ visitInExpression: (node) => {
7598
+ visitor.visitExpression?.(node);
7599
+ visitOperandNode(node.left);
7577
7600
  if (Array.isArray(node.right)) {
7578
- node.right.forEach((operand) => visitOperandNode(operand, visitor));
7601
+ node.right.forEach((operand) => visitOperandNode(operand));
7579
7602
  } else {
7580
- visitOperandNode(node.right, visitor);
7603
+ visitOperandNode(node.right);
7581
7604
  }
7582
- return;
7583
- case "ExistsExpression":
7605
+ },
7606
+ visitExistsExpression: (node) => {
7607
+ visitor.visitExpression?.(node);
7584
7608
  visitSelectQuery(node.subquery, visitor);
7585
- return;
7586
- case "BetweenExpression":
7587
- visitOperandNode(node.left, visitor);
7588
- visitOperandNode(node.lower, visitor);
7589
- visitOperandNode(node.upper, visitor);
7590
- return;
7591
- case "ArithmeticExpression":
7592
- visitOperandNode(node.left, visitor);
7593
- visitOperandNode(node.right, visitor);
7594
- return;
7595
- case "BitwiseExpression":
7596
- visitOperandNode(node.left, visitor);
7597
- visitOperandNode(node.right, visitor);
7598
- return;
7599
- default: {
7600
- return;
7609
+ },
7610
+ visitBetweenExpression: (node) => {
7611
+ visitor.visitExpression?.(node);
7612
+ visitOperandNode(node.left);
7613
+ visitOperandNode(node.lower);
7614
+ visitOperandNode(node.upper);
7615
+ },
7616
+ visitArithmeticExpression: (node) => {
7617
+ visitor.visitExpression?.(node);
7618
+ visitOperandNode(node.left);
7619
+ visitOperandNode(node.right);
7620
+ },
7621
+ visitBitwiseExpression: (node) => {
7622
+ visitor.visitExpression?.(node);
7623
+ visitOperandNode(node.left);
7624
+ visitOperandNode(node.right);
7625
+ },
7626
+ visitOperand: (node) => {
7627
+ visitOperandNode(node);
7628
+ },
7629
+ visitSelectQuery: (node) => {
7630
+ visitSelectQuery(node, visitor);
7631
+ },
7632
+ otherwise: (node) => {
7633
+ visitor.visitExpression?.(node);
7601
7634
  }
7602
- }
7603
- };
7604
- var visitOperandNode = (node, visitor) => {
7605
- visitor.visitOperand?.(node);
7606
- const type = getNodeType3(node);
7607
- if (type === "Param") {
7608
- visitor.visitParam?.(node);
7609
- }
7610
- if (!type) return;
7611
- switch (type) {
7612
- case "Column":
7613
- case "Literal":
7614
- case "Param":
7615
- case "AliasRef":
7616
- return;
7617
- case "Function":
7618
- node.args?.forEach((arg) => visitOperandNode(arg, visitor));
7619
- node.orderBy?.forEach((order) => visitOrderByNode(order, visitor));
7635
+ };
7636
+ const operandVisitor = {
7637
+ visitColumn: (node) => {
7638
+ visitor.visitOperand?.(node);
7639
+ },
7640
+ visitLiteral: (node) => {
7641
+ visitor.visitOperand?.(node);
7642
+ },
7643
+ visitParam: (node) => {
7644
+ visitor.visitOperand?.(node);
7645
+ visitor.visitParam?.(node);
7646
+ },
7647
+ visitFunction: (node) => {
7648
+ visitor.visitOperand?.(node);
7649
+ node.args?.forEach((arg) => visitOperandNode(arg));
7650
+ node.orderBy?.forEach((order) => visitOrderByNode(order));
7620
7651
  if (node.separator) {
7621
- visitOperandNode(node.separator, visitor);
7652
+ visitOperandNode(node.separator);
7622
7653
  }
7623
- return;
7624
- case "JsonPath":
7625
- visitOperandNode(node.column, visitor);
7626
- return;
7627
- case "ScalarSubquery":
7654
+ },
7655
+ visitJsonPath: (node) => {
7656
+ visitor.visitOperand?.(node);
7657
+ visitOperandNode(node.column);
7658
+ },
7659
+ visitScalarSubquery: (node) => {
7660
+ visitor.visitOperand?.(node);
7628
7661
  visitSelectQuery(node.query, visitor);
7629
- return;
7630
- case "CaseExpression":
7662
+ },
7663
+ visitCaseExpression: (node) => {
7664
+ visitor.visitOperand?.(node);
7631
7665
  node.conditions.forEach((cond) => {
7632
- visitExpressionNode(cond.when, visitor);
7633
- visitOperandNode(cond.then, visitor);
7666
+ visitExpressionNode(cond.when);
7667
+ visitOperandNode(cond.then);
7634
7668
  });
7635
7669
  if (node.else) {
7636
- visitOperandNode(node.else, visitor);
7670
+ visitOperandNode(node.else);
7637
7671
  }
7638
- return;
7639
- case "Cast":
7640
- visitOperandNode(node.expression, visitor);
7641
- return;
7642
- case "WindowFunction":
7643
- node.args?.forEach((arg) => visitOperandNode(arg, visitor));
7644
- node.partitionBy?.forEach((term) => visitOperandNode(term, visitor));
7645
- node.orderBy?.forEach((order) => visitOrderByNode(order, visitor));
7646
- return;
7647
- case "ArithmeticExpression":
7648
- visitOperandNode(node.left, visitor);
7649
- visitOperandNode(node.right, visitor);
7650
- return;
7651
- case "BitwiseExpression":
7652
- visitOperandNode(node.left, visitor);
7653
- visitOperandNode(node.right, visitor);
7654
- return;
7655
- case "Collate":
7656
- visitOperandNode(node.expression, visitor);
7657
- return;
7658
- default: {
7659
- const _exhaustive = node;
7660
- return _exhaustive;
7672
+ },
7673
+ visitCast: (node) => {
7674
+ visitor.visitOperand?.(node);
7675
+ visitOperandNode(node.expression);
7676
+ },
7677
+ visitWindowFunction: (node) => {
7678
+ visitor.visitOperand?.(node);
7679
+ node.args?.forEach((arg) => visitOperandNode(arg));
7680
+ node.partitionBy?.forEach((term) => visitOperandNode(term));
7681
+ node.orderBy?.forEach((order) => visitOrderByNode(order));
7682
+ },
7683
+ visitArithmeticExpression: (node) => {
7684
+ visitor.visitOperand?.(node);
7685
+ visitOperandNode(node.left);
7686
+ visitOperandNode(node.right);
7687
+ },
7688
+ visitBitwiseExpression: (node) => {
7689
+ visitor.visitOperand?.(node);
7690
+ visitOperandNode(node.left);
7691
+ visitOperandNode(node.right);
7692
+ },
7693
+ visitExpression: (node) => {
7694
+ visitExpressionNode(node);
7695
+ },
7696
+ visitSelectQuery: (node) => {
7697
+ visitSelectQuery(node, visitor);
7698
+ },
7699
+ visitCollate: (node) => {
7700
+ visitor.visitOperand?.(node);
7701
+ visitOperandNode(node.expression);
7702
+ },
7703
+ visitAliasRef: (node) => {
7704
+ visitor.visitOperand?.(node);
7705
+ },
7706
+ otherwise: (node) => {
7707
+ visitor.visitOperand?.(node);
7661
7708
  }
7662
- }
7663
- };
7664
- var visitSelectQuery = (ast, visitor) => {
7709
+ };
7665
7710
  visitor.visitSelectQuery?.(ast);
7666
7711
  if (ast.ctes) {
7667
7712
  for (const cte of ast.ctes) {
@@ -7669,29 +7714,29 @@ var visitSelectQuery = (ast, visitor) => {
7669
7714
  visitSelectQuery(cte.query, visitor);
7670
7715
  }
7671
7716
  }
7672
- visitTableSource(ast.from, visitor);
7717
+ visitTableSource(ast.from);
7673
7718
  ast.columns?.forEach((col2) => {
7674
- visitOperandNode(col2, visitor);
7719
+ visitOperandNode(col2);
7675
7720
  });
7676
7721
  ast.joins?.forEach((join) => {
7677
7722
  visitor.visitJoin?.(join);
7678
- visitTableSource(join.table, visitor);
7679
- visitExpressionNode(join.condition, visitor);
7723
+ visitTableSource(join.table);
7724
+ visitExpressionNode(join.condition);
7680
7725
  });
7681
7726
  if (ast.where) {
7682
- visitExpressionNode(ast.where, visitor);
7727
+ visitExpressionNode(ast.where);
7683
7728
  }
7684
7729
  ast.groupBy?.forEach((term) => {
7685
- visitOrderingTerm(term, visitor);
7730
+ visitOrderingTerm(term);
7686
7731
  });
7687
7732
  if (ast.having) {
7688
- visitExpressionNode(ast.having, visitor);
7733
+ visitExpressionNode(ast.having);
7689
7734
  }
7690
7735
  ast.orderBy?.forEach((order) => {
7691
- visitOrderByNode(order, visitor);
7736
+ visitOrderByNode(order);
7692
7737
  });
7693
7738
  ast.distinct?.forEach((col2) => {
7694
- visitOperandNode(col2, visitor);
7739
+ visitOperandNode(col2);
7695
7740
  });
7696
7741
  ast.setOps?.forEach((op) => {
7697
7742
  visitor.visitSetOperation?.(op);
@@ -7700,14 +7745,16 @@ var visitSelectQuery = (ast, visitor) => {
7700
7745
  };
7701
7746
 
7702
7747
  // src/core/ast/ast-validation.ts
7703
- var hasParamOperandsInQuery = (ast) => {
7704
- let hasParams = false;
7748
+ var findFirstParamOperandName = (ast) => {
7749
+ let name;
7705
7750
  visitSelectQuery(ast, {
7706
- visitParam: () => {
7707
- hasParams = true;
7751
+ visitParam: (node) => {
7752
+ if (!name) {
7753
+ name = node.name;
7754
+ }
7708
7755
  }
7709
7756
  });
7710
- return hasParams;
7757
+ return name;
7711
7758
  };
7712
7759
 
7713
7760
  // src/query-builder/select.ts
@@ -8187,11 +8234,12 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
8187
8234
  * Validates that the query does not contain Param operands.
8188
8235
  * Param proxies are only for schema generation, not execution.
8189
8236
  */
8190
- validateNoParamOperands() {
8237
+ validateNoParamOperands(options) {
8238
+ if (options?.allowParamOperands) return;
8191
8239
  const ast = this.context.hydration.applyToAst(this.context.state.ast);
8192
- const hasParams = hasParamOperandsInQuery(ast);
8193
- if (hasParams) {
8194
- 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.");
8240
+ const paramName = findFirstParamOperandName(ast);
8241
+ if (paramName) {
8242
+ 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.`);
8195
8243
  }
8196
8244
  }
8197
8245
  /**
@@ -8206,13 +8254,13 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
8206
8254
  * // users is User[]
8207
8255
  * users[0] instanceof User; // true
8208
8256
  */
8209
- async execute(ctx) {
8210
- this.validateNoParamOperands();
8257
+ async execute(ctx, options) {
8258
+ this.validateNoParamOperands(options);
8211
8259
  if (this.entityConstructor) {
8212
- return this.executeAs(this.entityConstructor, ctx);
8260
+ return this.executeAs(this.entityConstructor, ctx, options);
8213
8261
  }
8214
8262
  const builder = this.ensureDefaultSelection();
8215
- return executeHydrated(ctx, builder);
8263
+ return executeHydrated(ctx, builder, options);
8216
8264
  }
8217
8265
  /**
8218
8266
  * Executes the query and returns plain row objects (POJOs), ignoring any entity materialization.
@@ -8225,10 +8273,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
8225
8273
  * // rows is EntityInstance<UserTable>[] (plain objects)
8226
8274
  * rows[0] instanceof User; // false
8227
8275
  */
8228
- async executePlain(ctx) {
8229
- this.validateNoParamOperands();
8276
+ async executePlain(ctx, options) {
8277
+ this.validateNoParamOperands(options);
8230
8278
  const builder = this.ensureDefaultSelection();
8231
- const rows = await executeHydratedPlain(ctx, builder);
8279
+ const rows = await executeHydratedPlain(ctx, builder, options);
8232
8280
  return rows;
8233
8281
  }
8234
8282
  /**
@@ -8245,10 +8293,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
8245
8293
  * users[0] instanceof User; // true!
8246
8294
  * users[0].getFullName(); // works!
8247
8295
  */
8248
- async executeAs(entityClass, ctx) {
8249
- this.validateNoParamOperands();
8296
+ async executeAs(entityClass, ctx, options) {
8297
+ this.validateNoParamOperands(options);
8250
8298
  const builder = this.ensureDefaultSelection();
8251
- const results = await executeHydrated(ctx, builder);
8299
+ const results = await executeHydrated(ctx, builder, options);
8252
8300
  return materializeAs(entityClass, results);
8253
8301
  }
8254
8302
  /**
@@ -8257,9 +8305,9 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
8257
8305
  * @example
8258
8306
  * const total = await qb.count(session);
8259
8307
  */
8260
- async count(session) {
8261
- this.validateNoParamOperands();
8262
- return executeCount(this.context, this.env, session);
8308
+ async count(session, options) {
8309
+ this.validateNoParamOperands(options);
8310
+ return executeCount(this.context, this.env, session, options);
8263
8311
  }
8264
8312
  /**
8265
8313
  * Executes the query and returns both the paged items and the total.
@@ -8268,9 +8316,9 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
8268
8316
  * const { items, totalItems, page, pageSize } = await qb.executePaged(session, { page: 1, pageSize: 20 });
8269
8317
  */
8270
8318
  async executePaged(session, options) {
8271
- this.validateNoParamOperands();
8319
+ this.validateNoParamOperands(options);
8272
8320
  const builder = this.ensureDefaultSelection();
8273
- return executePagedQuery(builder, session, options, (sess) => builder.count(sess));
8321
+ return executePagedQuery(builder, session, options, (sess) => builder.count(sess, options), options);
8274
8322
  }
8275
8323
  /**
8276
8324
  * Executes the query with provided execution and hydration contexts
@@ -8282,10 +8330,10 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
8282
8330
  * const hydCtx = new HydrationContext();
8283
8331
  * const users = await qb.executeWithContexts(execCtx, hydCtx);
8284
8332
  */
8285
- async executeWithContexts(execCtx, hydCtx) {
8286
- this.validateNoParamOperands();
8333
+ async executeWithContexts(execCtx, hydCtx, options) {
8334
+ this.validateNoParamOperands(options);
8287
8335
  const builder = this.ensureDefaultSelection();
8288
- const results = await executeHydratedWithContexts(execCtx, hydCtx, builder);
8336
+ const results = await executeHydratedWithContexts(execCtx, hydCtx, builder, options);
8289
8337
  if (this.entityConstructor) {
8290
8338
  return materializeAs(this.entityConstructor, results);
8291
8339
  }
@@ -8518,9 +8566,17 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
8518
8566
  * .compile('postgres');
8519
8567
  * console.log(compiled.sql); // SELECT "id", "name" FROM "users" WHERE "active" = true
8520
8568
  */
8521
- compile(dialect) {
8569
+ compile(dialect, options) {
8522
8570
  const resolved = resolveDialectInput(dialect);
8523
- return resolved.compileSelect(this.getAST());
8571
+ const ast = this.getAST();
8572
+ if (!options?.allowParamOperands) {
8573
+ const paramName = findFirstParamOperandName(ast);
8574
+ if (paramName) {
8575
+ 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.`);
8576
+ }
8577
+ return resolved.compileSelect(ast);
8578
+ }
8579
+ return resolved.compileSelectWithOptions(ast, { allowParams: true });
8524
8580
  }
8525
8581
  /**
8526
8582
  * Converts the query to SQL string for a specific dialect
@@ -8532,8 +8588,8 @@ var SelectQueryBuilder = class _SelectQueryBuilder {
8532
8588
  * .toSql('postgres');
8533
8589
  * console.log(sql); // SELECT "id", "name" FROM "users" WHERE "active" = true
8534
8590
  */
8535
- toSql(dialect) {
8536
- return this.compile(dialect).sql;
8591
+ toSql(dialect, options) {
8592
+ return this.compile(dialect, options).sql;
8537
8593
  }
8538
8594
  /**
8539
8595
  * Gets hydration plan for query
@@ -14221,8 +14277,10 @@ export {
14221
14277
  groupConcat,
14222
14278
  gt,
14223
14279
  gte,
14280
+ hasExpressionDispatcher,
14224
14281
  hasMany,
14225
14282
  hasOne,
14283
+ hasOperandDispatcher,
14226
14284
  hour,
14227
14285
  hydrateRows,
14228
14286
  ifNull,