@prisma/orm-family-sql 8.0.0-rc.1-dev.41 → 8.0.0-rc.1-dev.43

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.
Files changed (102) hide show
  1. package/dist/{aggregate-descriptor-registry-DSap8YyW.mjs → aggregate-descriptor-registry-CTo0ry7h.mjs} +2 -2
  2. package/dist/{aggregate-descriptor-registry-DSap8YyW.mjs.map → aggregate-descriptor-registry-CTo0ry7h.mjs.map} +1 -1
  3. package/dist/{ast-B-eeN74F.mjs → ast-BJdOHZrL.mjs} +2 -2
  4. package/dist/{ast-B-eeN74F.mjs.map → ast-BJdOHZrL.mjs.map} +1 -1
  5. package/dist/{ast-DRbUiQ-9.d.mts → ast-D8qqdDX_.d.mts} +5 -82
  6. package/dist/ast-D8qqdDX_.d.mts.map +1 -0
  7. package/dist/builder.d.mts +2 -2
  8. package/dist/builder__runtime.d.mts +6 -6
  9. package/dist/builder__runtime.mjs +2 -2
  10. package/dist/builder__types.d.mts +2 -2
  11. package/dist/{control-DI9DC2AS.d.mts → control-DssujEJW.d.mts} +7 -6
  12. package/dist/control-DssujEJW.d.mts.map +1 -0
  13. package/dist/{control-adapter-C99J7aEF-DsxImHyk.d.mts → control-adapter-C99J7aEF-Vx9xXYOy.d.mts} +5 -4
  14. package/dist/control-adapter-C99J7aEF-Vx9xXYOy.d.mts.map +1 -0
  15. package/dist/control-adapter-CLID4Q6Z.d.mts +1 -0
  16. package/dist/{db-C5jmOFPM-BGm-QfKd.d.mts → db-C5jmOFPM-Cd-fni61.d.mts} +6 -6
  17. package/dist/{db-C5jmOFPM-BGm-QfKd.d.mts.map → db-C5jmOFPM-Cd-fni61.d.mts.map} +1 -1
  18. package/dist/{ddl-types-CnLSuwXa-Bv46yIe9.d.mts → ddl-types-BtT82FGO-Du_-9SlZ.d.mts} +3 -3
  19. package/dist/{ddl-types-CnLSuwXa-Bv46yIe9.d.mts.map → ddl-types-BtT82FGO-Du_-9SlZ.d.mts.map} +1 -1
  20. package/dist/{diff-DVvZXmFv.d.mts → diff-pl1Xal4J.d.mts} +3 -3
  21. package/dist/{diff-DVvZXmFv.d.mts.map → diff-pl1Xal4J.d.mts.map} +1 -1
  22. package/dist/driver-types-BQtRkOJ0-Bv2RPSfr.d.mts +81 -0
  23. package/dist/driver-types-BQtRkOJ0-Bv2RPSfr.d.mts.map +1 -0
  24. package/dist/{expression-CYVKobXp.mjs → expression-D30W-gkF.mjs} +2 -2
  25. package/dist/{expression-CYVKobXp.mjs.map → expression-D30W-gkF.mjs.map} +1 -1
  26. package/dist/{expression-D7H1kyVG.d.mts → expression-Q_yaDQPb.d.mts} +2 -2
  27. package/dist/{expression-D7H1kyVG.d.mts.map → expression-Q_yaDQPb.d.mts.map} +1 -1
  28. package/dist/family.d.mts +7 -7
  29. package/dist/family__control-adapter.d.mts +2 -2
  30. package/dist/family__control.d.mts +2 -2
  31. package/dist/family__diff.d.mts +2 -2
  32. package/dist/family__migration.d.mts +1 -1
  33. package/dist/family__runtime.d.mts +1 -1
  34. package/dist/index-DIHXLCbY.d.mts +84 -0
  35. package/dist/index-DIHXLCbY.d.mts.map +1 -0
  36. package/dist/{middleware-Bp5oIYM0-Ek8bISDH.d.mts → middleware-BS7u8VFR-DyUcAFid.d.mts} +3 -3
  37. package/dist/{middleware-Bp5oIYM0-Ek8bISDH.d.mts.map → middleware-BS7u8VFR-DyUcAFid.d.mts.map} +1 -1
  38. package/dist/middleware-Cy_OqpBi.d.mts +1 -0
  39. package/dist/{migration-Dtymew3g.d.mts → migration-CGlaINey.d.mts} +2 -2
  40. package/dist/{migration-Dtymew3g.d.mts.map → migration-CGlaINey.d.mts.map} +1 -1
  41. package/dist/orm-client.d.mts +7 -7
  42. package/dist/orm-client.mjs +32 -49
  43. package/dist/orm-client.mjs.map +1 -1
  44. package/dist/{plan-DfLDIdep-6R1mLkcW.d.mts → plan-BC_trt1i-In5gOKCT.d.mts} +3 -3
  45. package/dist/plan-BC_trt1i-In5gOKCT.d.mts.map +1 -0
  46. package/dist/plan-DrOMooQt.d.mts +2 -0
  47. package/dist/prepared-query-BDLztUzY-CaDR0Rqc.mjs +14 -0
  48. package/dist/prepared-query-BDLztUzY-CaDR0Rqc.mjs.map +1 -0
  49. package/dist/{index-Ddquditw.d.mts → prepared-statement-z9bBbTph-BlzhaRTY.d.mts} +96 -142
  50. package/dist/prepared-statement-z9bBbTph-BlzhaRTY.d.mts.map +1 -0
  51. package/dist/query-lane-context-D62vkQhf.d.mts +1 -0
  52. package/dist/{query-lane-context-DyDSQVS--CyCznt67.d.mts → query-lane-context-gwWUcacE-DdWNrc8q.d.mts} +3 -3
  53. package/dist/{query-lane-context-DyDSQVS--CyCznt67.d.mts.map → query-lane-context-gwWUcacE-DdWNrc8q.d.mts.map} +1 -1
  54. package/dist/relational-core.d.mts +12 -11
  55. package/dist/relational-core.mjs +3 -3
  56. package/dist/relational-core__aggregate-descriptor-registry.d.mts +1 -1
  57. package/dist/relational-core__aggregate-descriptor-registry.mjs +1 -1
  58. package/dist/relational-core__ast.d.mts +4 -3
  59. package/dist/relational-core__ast.mjs +2 -2
  60. package/dist/relational-core__codec-descriptor-registry.d.mts +2 -2
  61. package/dist/relational-core__contract-free.d.mts +2 -2
  62. package/dist/relational-core__contract-free.mjs +1 -1
  63. package/dist/relational-core__contract-free.mjs.map +1 -1
  64. package/dist/relational-core__expression.d.mts +1 -1
  65. package/dist/relational-core__expression.mjs +1 -1
  66. package/dist/relational-core__middleware.d.mts +2 -2
  67. package/dist/relational-core__plan.d.mts +3 -3
  68. package/dist/relational-core__query-lane-context.d.mts +2 -2
  69. package/dist/relational-core__types.d.mts +2 -2
  70. package/dist/{runtime-CjXCGPS4.d.mts → runtime-cPrAp99G.d.mts} +3 -2
  71. package/dist/runtime-cPrAp99G.d.mts.map +1 -0
  72. package/dist/runtime.d.mts +5 -4
  73. package/dist/runtime.mjs +187 -130
  74. package/dist/runtime.mjs.map +1 -1
  75. package/dist/runtime__internal__prepared-query.d.mts +2 -0
  76. package/dist/runtime__internal__prepared-query.mjs +2 -0
  77. package/dist/{sql-execution-plan-qxvHnFcA-HjRSS3l9.d.mts → sql-execution-plan-D0ZTnszb-DnCRtfQO.d.mts} +3 -3
  78. package/dist/sql-execution-plan-D0ZTnszb-DnCRtfQO.d.mts.map +1 -0
  79. package/dist/types-0c4HyrXd.d.mts +1 -0
  80. package/dist/{types-CSP6WmWn-DVuxsZJW.mjs → types-B7_v-z12-De5tf8LE.mjs} +3 -3
  81. package/dist/types-B7_v-z12-De5tf8LE.mjs.map +1 -0
  82. package/dist/{types-CLN9Y3BH-BHUrV7MD.d.mts → types-C9FZXc9Q-C6LM1k-O.d.mts} +14 -11
  83. package/dist/types-C9FZXc9Q-C6LM1k-O.d.mts.map +1 -0
  84. package/dist/{types-ZzeQKmYD-kI_QWHEx.d.mts → types-DH6Sqzxu-DfzaLX0o.d.mts} +3 -3
  85. package/dist/{types-ZzeQKmYD-kI_QWHEx.d.mts.map → types-DH6Sqzxu-DfzaLX0o.d.mts.map} +1 -1
  86. package/dist/{types-IqZMLrFC-Dk3bHKmk.d.mts → types-IqZMLrFC-B0YziCVx.d.mts} +2 -2
  87. package/dist/{types-IqZMLrFC-Dk3bHKmk.d.mts.map → types-IqZMLrFC-B0YziCVx.d.mts.map} +1 -1
  88. package/package.json +19 -18
  89. package/dist/ast-DRbUiQ-9.d.mts.map +0 -1
  90. package/dist/control-DI9DC2AS.d.mts.map +0 -1
  91. package/dist/control-adapter-BdOcXTOm.d.mts +0 -1
  92. package/dist/control-adapter-C99J7aEF-DsxImHyk.d.mts.map +0 -1
  93. package/dist/index-Ddquditw.d.mts.map +0 -1
  94. package/dist/middleware-aFpB1ZhU.d.mts +0 -1
  95. package/dist/plan-DfLDIdep-6R1mLkcW.d.mts.map +0 -1
  96. package/dist/plan-HWPzzUxh.d.mts +0 -2
  97. package/dist/query-lane-context-qfJzguc9.d.mts +0 -1
  98. package/dist/runtime-CjXCGPS4.d.mts.map +0 -1
  99. package/dist/sql-execution-plan-qxvHnFcA-HjRSS3l9.d.mts.map +0 -1
  100. package/dist/types-4u1EPYY6.d.mts +0 -1
  101. package/dist/types-CLN9Y3BH-BHUrV7MD.d.mts.map +0 -1
  102. package/dist/types-CSP6WmWn-DVuxsZJW.mjs.map +0 -1
@@ -1,8 +1,8 @@
1
1
  import { t as resolveStorageTable } from "./resolve-storage-table-DZsfnzeW.mjs";
2
2
  import { i as isUniqueConstraintViolation } from "./dist-x6jvtkKM.mjs";
3
- import { C as LiteralExpr, D as OrExpr, F as SubqueryExpr, I as TableSource, L as UpdateAst, O as OrderByItem, P as SelectAst, R as WindowFuncExpr, S as ListExpression, T as NullCheckExpr, U as isWhereExpr, V as isAggregateFn, _ as InsertAst, b as JsonArrayAggExpr, c as DeleteAst, f as EqColJoinOn, j as ProjectionItem, k as ParamRef, l as DerivedTableSource, n as AndExpr, o as ColumnRef, p as ExistsExpr, r as BinaryExpr, s as DefaultValueExpr, t as AggregateExpr, v as InsertOnConflict, w as NotExpr, x as JsonObjectExpr, y as JoinAst } from "./types-CSP6WmWn-DVuxsZJW.mjs";
3
+ import { C as LiteralExpr, D as OrExpr, F as SubqueryExpr, I as TableSource, L as UpdateAst, O as OrderByItem, P as SelectAst, R as WindowFuncExpr, S as ListExpression, T as NullCheckExpr, U as isWhereExpr, V as isAggregateFn, _ as InsertAst, b as JsonArrayAggExpr, c as DeleteAst, f as EqColJoinOn, j as ProjectionItem, k as ParamRef, l as DerivedTableSource, n as AndExpr, o as ColumnRef, p as ExistsExpr, r as BinaryExpr, s as DefaultValueExpr, t as AggregateExpr, v as InsertOnConflict, w as NotExpr, x as JsonObjectExpr, y as JoinAst } from "./types-B7_v-z12-De5tf8LE.mjs";
4
4
  import { t as collectOrderedParamRefs } from "./util-DQQgv2j1-D6INZaRG.mjs";
5
- import { n as JsonDocumentProjection, r as NativeJsonValueProjection, t as CodecJsonValueProjection } from "./ast-B-eeN74F.mjs";
5
+ import { n as JsonDocumentProjection, r as NativeJsonValueProjection, t as CodecJsonValueProjection } from "./ast-BJdOHZrL.mjs";
6
6
  import { n as codecRefForStorageColumn } from "./codec-descriptor-registry-N0dhtKaH.mjs";
7
7
  import { structuredError } from "@prisma/orm-framework/utils/structured-error";
8
8
  import { InternalError } from "@prisma/orm-framework/utils/internal-error";
@@ -547,9 +547,6 @@ async function acquireRuntimeScope(runtime) {
547
547
  };
548
548
  return { scope: connection };
549
549
  }
550
- function executeQueryPlan(scope, plan) {
551
- return scope.execute(plan);
552
- }
553
550
  function deriveParamsFromAst(ast) {
554
551
  return { params: collectOrderedParamRefs(ast).map((p) => p.kind === "param-ref" ? p.value : void 0) };
555
552
  }
@@ -1790,6 +1787,9 @@ function compileSelectWithIncludes(contract, aggregates, namespaceId, tableName,
1790
1787
  const { params } = deriveParamsFromAst(ast);
1791
1788
  return buildOrmQueryPlan(contract, ast, params, state.annotations);
1792
1789
  }
1790
+ function queryPlanRows(scope, plan) {
1791
+ return scope.query(plan);
1792
+ }
1793
1793
  function emptyState() {
1794
1794
  return {
1795
1795
  filters: [],
@@ -1885,7 +1885,7 @@ function dispatchCollectionRows(options) {
1885
1885
  const { context, runtime, state, tableName, modelName, namespaceId } = options;
1886
1886
  const { contract } = context;
1887
1887
  const polyInfo = resolvePolymorphismInfo(contract, namespaceId, modelName);
1888
- if (state.includes.length === 0) return mapResultRows(executeQueryPlan(runtime, compileSelect(contract, namespaceId, tableName, state, modelName)), polyInfo ? (rawRow) => blindCast(mapPolymorphicRow(contract, namespaceId, modelName, polyInfo, rawRow, state.variantName)) : (rawRow) => blindCast(mapStorageRowToModelFields(contract, namespaceId, modelName, rawRow)));
1888
+ if (state.includes.length === 0) return mapResultRows(queryPlanRows(runtime, compileSelect(contract, namespaceId, tableName, state, modelName)), polyInfo ? (rawRow) => blindCast(mapPolymorphicRow(contract, namespaceId, modelName, polyInfo, rawRow, state.variantName)) : (rawRow) => blindCast(mapStorageRowToModelFields(contract, namespaceId, modelName, rawRow)));
1889
1889
  return dispatchWithIncludes(options);
1890
1890
  }
1891
1891
  function dispatchWithIncludes(options) {
@@ -1894,7 +1894,7 @@ function dispatchWithIncludes(options) {
1894
1894
  const generator = async function* () {
1895
1895
  const { scope, release } = await acquireRuntimeScope(runtime);
1896
1896
  try {
1897
- const parentRowsRaw = await executeQueryPlan(scope, compileSelectWithIncludes(contract, context.aggregateDescriptors, namespaceId, tableName, state, modelName)).toArray();
1897
+ const parentRowsRaw = await queryPlanRows(scope, compileSelectWithIncludes(contract, context.aggregateDescriptors, namespaceId, tableName, state, modelName)).toArray();
1898
1898
  if (parentRowsRaw.length === 0) return;
1899
1899
  const polyInfo = resolvePolymorphismInfo(contract, namespaceId, modelName);
1900
1900
  const parentRows = parentRowsRaw.map((row) => {
@@ -2211,13 +2211,13 @@ function dispatchMutationRows(options) {
2211
2211
  const { context, runtime, compiled, tableName, modelName, namespaceId, variantName, includes, selectedFields, hiddenColumns, mapRow } = options;
2212
2212
  const { contract } = context;
2213
2213
  const mapStorageRow = createMutationRowMapper(contract, namespaceId, modelName, variantName);
2214
- if (includes.length === 0) return mapResultRows(executeQueryPlan(runtime, compiled), (rawRow) => {
2214
+ if (includes.length === 0) return mapResultRows(queryPlanRows(runtime, compiled), (rawRow) => {
2215
2215
  const mapped = mapStorageRow(rawRow);
2216
2216
  if (hiddenColumns.length > 0) stripHiddenMappedFields(contract, namespaceId, modelName, mapped, hiddenColumns);
2217
2217
  return mapRow(mapped);
2218
2218
  });
2219
2219
  const generator = async function* () {
2220
- const identityRows = await executeQueryPlan(runtime, compiled).toArray();
2220
+ const identityRows = await queryPlanRows(runtime, compiled).toArray();
2221
2221
  yield* reloadMutationRowsByIdentities({
2222
2222
  context,
2223
2223
  runtime,
@@ -2238,7 +2238,7 @@ function dispatchSplitMutationRows(options) {
2238
2238
  const generator = async function* () {
2239
2239
  if (includes.length > 0) {
2240
2240
  const identityRows = [];
2241
- for (const plan of plans) identityRows.push(...await executeQueryPlan(runtime, plan).toArray());
2241
+ for (const plan of plans) identityRows.push(...await queryPlanRows(runtime, plan).toArray());
2242
2242
  yield* reloadMutationRowsByIdentities({
2243
2243
  context,
2244
2244
  runtime,
@@ -2251,7 +2251,7 @@ function dispatchSplitMutationRows(options) {
2251
2251
  });
2252
2252
  return;
2253
2253
  }
2254
- for (const plan of plans) for await (const rawRow of executeQueryPlan(runtime, plan)) {
2254
+ for (const plan of plans) for await (const rawRow of queryPlanRows(runtime, plan)) {
2255
2255
  const mapped = mapStorageRow(rawRow);
2256
2256
  if (hiddenColumns.length > 0) stripHiddenMappedFields(contract, namespaceId, modelName, mapped, hiddenColumns);
2257
2257
  yield mapRow(mapped);
@@ -2264,13 +2264,13 @@ async function executeMutationReturningSingleRow(options) {
2264
2264
  const { contract } = context;
2265
2265
  const mapStorageRow = createMutationRowMapper(contract, namespaceId, modelName, variantName);
2266
2266
  if (includes.length === 0) {
2267
- const first = (await executeQueryPlan(runtime, compiled).toArray())[0];
2267
+ const first = (await queryPlanRows(runtime, compiled).toArray())[0];
2268
2268
  if (!first) return null;
2269
2269
  const mapped = mapStorageRow(first);
2270
2270
  if (hiddenColumns.length > 0) stripHiddenMappedFields(contract, namespaceId, modelName, mapped, hiddenColumns);
2271
2271
  return mapRow(mapped);
2272
2272
  }
2273
- const identityRows = await executeQueryPlan(runtime, compiled).toArray();
2273
+ const identityRows = await queryPlanRows(runtime, compiled).toArray();
2274
2274
  if (identityRows.length === 0) return null;
2275
2275
  for await (const row of reloadMutationRowsByIdentities({
2276
2276
  context,
@@ -2386,7 +2386,7 @@ var GroupedCollection = class GroupedCollection {
2386
2386
  if (meta.annotations.size > 0) annotationsMap = meta.annotations;
2387
2387
  }
2388
2388
  const compiled = mergeAnnotations(compileGroupedAggregate(this.contract, this.ctx.context.aggregateDescriptors, this.namespaceId, this.tableName, this.baseFilters, this.groupByColumns, aggregateSpec, combineWhereExprs(this.havingFilters)), annotationsMap);
2389
- return (await executeQueryPlan(this.ctx.runtime, compiled).toArray()).map((row) => {
2389
+ return (await queryPlanRows(this.ctx.runtime, compiled).toArray()).map((row) => {
2390
2390
  const mapped = mapStorageRowToModelFields(this.contract, this.namespaceId, this.modelName, row);
2391
2391
  for (const [alias] of aggregateEntries) mapped[alias] = row[alias];
2392
2392
  return mapped;
@@ -2916,7 +2916,7 @@ async function updateFirstGraph(scope, context, namespaceId, modelName, filters,
2916
2916
  for (const def of appliedUpdateDefaults) mappedUpdateData[def.column] = def.value;
2917
2917
  const pkWhere = shorthandToWhereExpr(context, namespaceId, modelName, castAs(buildPrimaryKeyFilterFromRow(contract, namespaceId, modelName, existingRow)));
2918
2918
  if (!pkWhere) throw new InternalError(`Failed to build primary key filter for model "${modelName}"`);
2919
- const updatedRaw = (await executeQueryPlan(scope, compileUpdateReturning(contract, namespaceId, tableName, mappedUpdateData, [pkWhere], void 0)).toArray())[0];
2919
+ const updatedRaw = (await queryPlanRows(scope, compileUpdateReturning(contract, namespaceId, tableName, mappedUpdateData, [pkWhere], void 0)).toArray())[0];
2920
2920
  if (updatedRaw) parentRow = mapStorageRowToModelFields(contract, namespaceId, modelName, updatedRaw);
2921
2921
  }
2922
2922
  for (const relationMutation of childOwned) await applyChildOwnedMutation(scope, context, namespaceId, modelName, parentRow, relationMutation.relation, relationMutation.mutation);
@@ -3184,7 +3184,7 @@ async function insertJunctionLink(scope, context, relation, parentPkValues, targ
3184
3184
  for (const def of applied) junctionRow[def.column] = def.value;
3185
3185
  const compiled = compileInsertCount(context.contract, through.namespaceId, through.table, [junctionRow]);
3186
3186
  try {
3187
- await executeQueryPlan(scope, compiled).toArray();
3187
+ await scope.execute(compiled);
3188
3188
  } catch (error) {
3189
3189
  if (mutationKind === "connect" && isUniqueConstraintViolation(error)) throw ormError("ORM.RELATION_LINK_DUPLICATE", `connect() nested mutation for relation "${relation.relationName}" violated a unique constraint on junction "${through.table}"; the junction link may already be present`, {
3190
3190
  meta: {
@@ -3205,7 +3205,8 @@ async function deleteJunctionLink(scope, context, relation, parentPkValues, targ
3205
3205
  for (const [column, value] of Object.entries(junctionRow)) exprs.push(BinaryExpr.eq(ColumnRef.of(through.table, column), LiteralExpr.of(value)));
3206
3206
  const first = exprs[0];
3207
3207
  const where = exprs.length === 1 && first !== void 0 ? first : and(...exprs);
3208
- await executeQueryPlan(scope, compileDeleteCount(context.contract, through.namespaceId, through.table, [where])).toArray();
3208
+ const compiled = compileDeleteCount(context.contract, through.namespaceId, through.table, [where]);
3209
+ await scope.execute(compiled);
3209
3210
  }
3210
3211
  function readParentColumnValues(contract, parentNamespaceId, parentModelName, relation, parentRow) {
3211
3212
  const values = /* @__PURE__ */ new Map();
@@ -3238,7 +3239,7 @@ async function insertSingleRow(scope, context, namespaceId, modelName, data) {
3238
3239
  values: mappedData
3239
3240
  });
3240
3241
  for (const def of applied) mappedData[def.column] = def.value;
3241
- const firstRow = (await executeQueryPlan(scope, compileInsertReturning(contract, namespaceId, tableName, [mappedData], void 0)).toArray())[0];
3242
+ const firstRow = (await queryPlanRows(scope, compileInsertReturning(contract, namespaceId, tableName, [mappedData], void 0)).toArray())[0];
3242
3243
  if (!firstRow) throw ormError("ORM.MUTATION_ROW_MISSING", `Nested create for model "${modelName}" did not return a row`, { meta: {
3243
3244
  operation: "create",
3244
3245
  model: modelName,
@@ -3254,7 +3255,7 @@ async function findRowByCriterion(scope, context, namespaceId, modelName, criter
3254
3255
  model: modelName,
3255
3256
  problem: "empty-criterion"
3256
3257
  } });
3257
- const firstRow = (await executeQueryPlan(scope, compileSelect(contract, namespaceId, resolveModelTableName(contract, namespaceId, modelName), {
3258
+ const firstRow = (await queryPlanRows(scope, compileSelect(contract, namespaceId, resolveModelTableName(contract, namespaceId, modelName), {
3258
3259
  ...emptyState(),
3259
3260
  filters: [whereExpr],
3260
3261
  limit: 1
@@ -3263,7 +3264,7 @@ async function findRowByCriterion(scope, context, namespaceId, modelName, criter
3263
3264
  return mapStorageRowToModelFields(contract, namespaceId, modelName, firstRow);
3264
3265
  }
3265
3266
  async function findFirstByFilters(scope, contract, namespaceId, modelName, filters) {
3266
- const firstRow = (await executeQueryPlan(scope, compileSelect(contract, namespaceId, resolveModelTableName(contract, namespaceId, modelName), {
3267
+ const firstRow = (await queryPlanRows(scope, compileSelect(contract, namespaceId, resolveModelTableName(contract, namespaceId, modelName), {
3267
3268
  ...emptyState(),
3268
3269
  filters,
3269
3270
  limit: 1
@@ -3272,7 +3273,8 @@ async function findFirstByFilters(scope, contract, namespaceId, modelName, filte
3272
3273
  return mapStorageRowToModelFields(contract, namespaceId, modelName, firstRow);
3273
3274
  }
3274
3275
  async function executeUpdateCount(scope, contract, namespaceId, tableName, setValues, filters) {
3275
- await executeQueryPlan(scope, compileUpdateCount(contract, namespaceId, tableName, setValues, filters)).toArray();
3276
+ const compiled = compileUpdateCount(contract, namespaceId, tableName, setValues, filters);
3277
+ await scope.execute(compiled);
3276
3278
  }
3277
3279
  const relationDefsCache = /* @__PURE__ */ new WeakMap();
3278
3280
  function getRelationDefinitions(contract, namespaceId, modelName) {
@@ -3808,7 +3810,7 @@ var CollectionImpl = class CollectionImpl {
3808
3810
  } });
3809
3811
  const annotationsMap = this.#collectAnnotationsFromMeta(configure, "read", "aggregate");
3810
3812
  const compiled = mergeAnnotations(compileAggregate(this.contract, this.ctx.context.aggregateDescriptors, this.namespaceId, this.tableName, this.state.filters, aggregateSpec), annotationsMap);
3811
- const row = (await executeQueryPlan(this.ctx.runtime, compiled).toArray())[0] ?? {};
3813
+ const row = (await queryPlanRows(this.ctx.runtime, compiled).toArray())[0] ?? {};
3812
3814
  const result = {};
3813
3815
  for (const [alias, selector] of entries) result[alias] = row[alias] ?? this.#emptyAggregateValue(selector);
3814
3816
  return blindCast(result);
@@ -3966,7 +3968,7 @@ var CollectionImpl = class CollectionImpl {
3966
3968
  }
3967
3969
  yield blindCast(await withMutationScope(runtime, async (scope) => {
3968
3970
  applyCreateDefaults(collectionCtx, namespaceId, tableName, [baseRow]);
3969
- const baseCreated = (await executeQueryPlan(scope, compileInsertReturning(contract, namespaceId, tableName, [baseRow], void 0)).toArray())[0];
3971
+ const baseCreated = (await queryPlanRows(scope, compileInsertReturning(contract, namespaceId, tableName, [baseRow], void 0)).toArray())[0];
3970
3972
  if (!baseCreated) throw ormError("ORM.MUTATION_ROW_MISSING", `MTI base INSERT for model "${modelName}" did not return a row`, { meta: {
3971
3973
  operation: "create",
3972
3974
  model: modelName,
@@ -3976,7 +3978,7 @@ var CollectionImpl = class CollectionImpl {
3976
3978
  const pkValue = baseCreated[pkColumn];
3977
3979
  variantRow[pkColumn] = pkValue;
3978
3980
  applyCreateDefaults(collectionCtx, namespaceId, variant.table, [variantRow]);
3979
- const variantCreated = (await executeQueryPlan(scope, compileInsertReturning(contract, namespaceId, variant.table, [variantRow], void 0)).toArray())[0];
3981
+ const variantCreated = (await queryPlanRows(scope, compileInsertReturning(contract, namespaceId, variant.table, [variantRow], void 0)).toArray())[0];
3980
3982
  if (!variantCreated) throw ormError("ORM.MUTATION_ROW_MISSING", `MTI variant INSERT for model "${modelName}" into "${variant.table}" did not return a row`, { meta: {
3981
3983
  operation: "create",
3982
3984
  model: modelName,
@@ -4048,11 +4050,11 @@ var CollectionImpl = class CollectionImpl {
4048
4050
  applyCreateDefaults(this.ctx, this.namespaceId, this.tableName, mappedRows);
4049
4051
  if (this.contract.capabilities?.["sql"]?.["defaultInInsert"] !== true) {
4050
4052
  const plans = compileInsertCountSplit(this.contract, this.namespaceId, this.tableName, mappedRows).map((plan) => mergeAnnotations(plan, annotationsMap));
4051
- for (const plan of plans) await executeQueryPlan(this.ctx.runtime, plan).toArray();
4053
+ for (const plan of plans) await this.ctx.runtime.execute(plan);
4052
4054
  return data.length;
4053
4055
  }
4054
4056
  const compiled = mergeAnnotations(compileInsertCount(this.contract, this.namespaceId, this.tableName, mappedRows), annotationsMap);
4055
- await executeQueryPlan(this.ctx.runtime, compiled).toArray();
4057
+ await this.ctx.runtime.execute(compiled);
4056
4058
  return data.length;
4057
4059
  }
4058
4060
  /**
@@ -4260,18 +4262,8 @@ var CollectionImpl = class CollectionImpl {
4260
4262
  if (Object.keys(mappedData).length === 0) return 0;
4261
4263
  applyUpdateDefaults(this.ctx, this.namespaceId, this.tableName, mappedData);
4262
4264
  const annotationsMap = this.#collectAnnotationsFromMeta(configure, "write", "updateAndCount");
4263
- const primaryKeyColumn = resolvePrimaryKeyColumn(this.contract, this.namespaceId, this.tableName);
4264
- const countState = {
4265
- ...emptyState(),
4266
- filters: this.state.filters,
4267
- selectedFields: [primaryKeyColumn],
4268
- variantName: this.state.variantName
4269
- };
4270
- const countCompiled = compileSelect(this.contract, this.namespaceId, this.tableName, countState, this.modelName);
4271
- const matchingRows = await executeQueryPlan(this.ctx.runtime, countCompiled).toArray();
4272
4265
  const compiled = mergeAnnotations(compileUpdateCount(this.contract, this.namespaceId, this.tableName, mappedData, this.state.filters, this.state.variantName, this.modelName), annotationsMap);
4273
- await executeQueryPlan(this.ctx.runtime, compiled).toArray();
4274
- return matchingRows.length;
4266
+ return (await this.ctx.runtime.execute(compiled)).affectedRows;
4275
4267
  }
4276
4268
  /**
4277
4269
  * Write terminal: delete a single matching row — the first one the
@@ -4370,7 +4362,8 @@ var CollectionImpl = class CollectionImpl {
4370
4362
  modelName: collection.modelName,
4371
4363
  namespaceId: collection.namespaceId
4372
4364
  }).toArray();
4373
- await executeQueryPlan(scope, mergeAnnotations(compileDeleteCount(collection.contract, collection.namespaceId, collection.tableName, collection.state.filters, collection.state.variantName, collection.modelName), annotationsMap)).toArray();
4365
+ const deletePlan = mergeAnnotations(compileDeleteCount(collection.contract, collection.namespaceId, collection.tableName, collection.state.filters, collection.state.variantName, collection.modelName), annotationsMap);
4366
+ await scope.execute(deletePlan);
4374
4367
  return rows;
4375
4368
  });
4376
4369
  for (const row of snapshot) yield row;
@@ -4391,18 +4384,8 @@ var CollectionImpl = class CollectionImpl {
4391
4384
  */
4392
4385
  async deleteAndCount(configure) {
4393
4386
  const annotationsMap = this.#collectAnnotationsFromMeta(configure, "write", "deleteAndCount");
4394
- const primaryKeyColumn = resolvePrimaryKeyColumn(this.contract, this.namespaceId, this.tableName);
4395
- const countState = {
4396
- ...emptyState(),
4397
- filters: this.state.filters,
4398
- selectedFields: [primaryKeyColumn],
4399
- variantName: this.state.variantName
4400
- };
4401
- const countCompiled = compileSelect(this.contract, this.namespaceId, this.tableName, countState, this.modelName);
4402
- const matchingRows = await executeQueryPlan(this.ctx.runtime, countCompiled).toArray();
4403
4387
  const compiled = mergeAnnotations(compileDeleteCount(this.contract, this.namespaceId, this.tableName, this.state.filters, this.state.variantName, this.modelName), annotationsMap);
4404
- await executeQueryPlan(this.ctx.runtime, compiled).toArray();
4405
- return matchingRows.length;
4388
+ return (await this.ctx.runtime.execute(compiled)).affectedRows;
4406
4389
  }
4407
4390
  #buildUpsertConflictCriterion(createValues, conflictColumns) {
4408
4391
  const columnToField = getColumnToFieldMap(this.contract, this.namespaceId, this.modelName);