@dbsp/adapter-pgsql 7.1.1 → 7.1.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.
@@ -26292,7 +26292,12 @@ function compileUpdate(config, ctx, state) {
26292
26292
  )
26293
26293
  }));
26294
26294
  let whereClause;
26295
- if (config.where && config.where.length > 0) {
26295
+ if (config.whereCompiler) {
26296
+ whereClause = config.whereCompiler(
26297
+ { ...ctx, currentAlias: tableAlias },
26298
+ state
26299
+ );
26300
+ } else if (config.where && config.where.length > 0) {
26296
26301
  const dispatch = createWhereDispatcher(compileWhereIntent);
26297
26302
  const subCtx = { ...ctx, currentAlias: tableAlias };
26298
26303
  if (config.where.length === 1) {
@@ -26410,7 +26415,12 @@ function compileUnnestUpdate(config, ctx, state) {
26410
26415
  function compileDelete(config, ctx, state) {
26411
26416
  const tableAlias = config.tableMetadata?.physicalName ?? config.table;
26412
26417
  let whereClause;
26413
- if (config.where && config.where.length > 0) {
26418
+ if (config.whereCompiler) {
26419
+ whereClause = config.whereCompiler(
26420
+ { ...ctx, currentAlias: tableAlias },
26421
+ state
26422
+ );
26423
+ } else if (config.where && config.where.length > 0) {
26414
26424
  const dispatch = createWhereDispatcher(compileWhereIntent);
26415
26425
  const subCtx = { ...ctx, currentAlias: tableAlias };
26416
26426
  if (config.where.length === 1) {
@@ -27064,8 +27074,8 @@ import {
27064
27074
  POSTGRESQL_CAPABILITIES as POSTGRESQL_CAPABILITIES3,
27065
27075
  plan as planFn
27066
27076
  } from "@dbsp/core";
27067
- import { inspectMutationRows } from "@dbsp/core/internal";
27068
- import { isParamIntent as isParamIntent8 } from "@dbsp/types";
27077
+ import { inspectMutationRows, resolveSelectWhere } from "@dbsp/core/internal";
27078
+ import { isParamIntent as isParamIntent8, RangeAllocator } from "@dbsp/types";
27069
27079
 
27070
27080
  // src/resolved-include-decisions.ts
27071
27081
  function lowerResolvedIncludes(execution, defaultPk) {
@@ -29197,12 +29207,37 @@ function compileInsertFrom2(intent, options, deps) {
29197
29207
  sourceCte
29198
29208
  );
29199
29209
  }
29210
+ function resolvedMutationWhere(where, table2, deps) {
29211
+ if (!where || deps.model === void 0) return void 0;
29212
+ const allocator = new RangeAllocator();
29213
+ const root = allocator.bind(table2, table2);
29214
+ for (const name of [
29215
+ ...deps.bindingNames ?? [],
29216
+ ...deps.scope?.bindings.keys() ?? []
29217
+ ]) {
29218
+ allocator.reserve(name);
29219
+ }
29220
+ const resolved = resolveSelectWhere(
29221
+ where,
29222
+ root,
29223
+ [root],
29224
+ allocator,
29225
+ deps.model
29226
+ );
29227
+ if (!resolved) {
29228
+ throw new Error(
29229
+ `Internal error: the mutation WHERE on '${table2}' resolved to nothing.`
29230
+ );
29231
+ }
29232
+ return (ctx, state) => compileResolvedCondition(resolved, ctx, state);
29233
+ }
29200
29234
  function compileUpdate2(intent, options, deps) {
29201
29235
  const ctx = mutationContext(deps, intent.table, MAX_DEPTH_LIMIT);
29202
29236
  const state = createCompilerState();
29203
29237
  const setColumns = Object.keys(intent.set ?? {});
29204
29238
  const columnTypes = getColumnTypes(intent.table, setColumns, deps);
29205
- const resolvedWhere = intent.where ? resolveExistsIntent(intent.where, intent.table, deps) : void 0;
29239
+ const whereCompiler = resolvedMutationWhere(intent.where, intent.table, deps);
29240
+ const resolvedWhere = intent.where && !whereCompiler ? resolveExistsIntent(intent.where, intent.table, deps) : void 0;
29206
29241
  const config = {
29207
29242
  table: declaredMutationTable(deps, intent.table),
29208
29243
  tableMetadata: declaredMutationTableMetadata(deps, intent.table),
@@ -29211,6 +29246,7 @@ function compileUpdate2(intent, options, deps) {
29211
29246
  value
29212
29247
  })),
29213
29248
  ...resolvedWhere && { where: [whereIntentAsDecision(resolvedWhere)] },
29249
+ ...whereCompiler && { whereCompiler },
29214
29250
  ...intent.returning && { returning: [...intent.returning] },
29215
29251
  ...intent.returning && {
29216
29252
  returningSources: mutationReturningSources(
@@ -29344,11 +29380,13 @@ function compileBatchUpdate(intent, options, deps) {
29344
29380
  function compileDelete2(intent, options, deps) {
29345
29381
  const ctx = mutationContext(deps, intent.table, MAX_DEPTH_LIMIT);
29346
29382
  const state = createCompilerState();
29347
- const resolvedWhere = intent.where ? resolveExistsIntent(intent.where, intent.table, deps) : void 0;
29383
+ const whereCompiler = resolvedMutationWhere(intent.where, intent.table, deps);
29384
+ const resolvedWhere = intent.where && !whereCompiler ? resolveExistsIntent(intent.where, intent.table, deps) : void 0;
29348
29385
  const config = {
29349
29386
  table: declaredMutationTable(deps, intent.table),
29350
29387
  tableMetadata: declaredMutationTableMetadata(deps, intent.table),
29351
29388
  ...resolvedWhere && { where: [whereIntentAsDecision(resolvedWhere)] },
29389
+ ...whereCompiler && { whereCompiler },
29352
29390
  ...intent.returning && { returning: [...intent.returning] },
29353
29391
  ...intent.returning && {
29354
29392
  returningSources: mutationReturningSources(
@@ -29444,7 +29482,12 @@ function compileUpsert2(intent, options, deps, rowShape) {
29444
29482
  );
29445
29483
  const hasRawExprs = Object.keys(rawExprs).length > 0;
29446
29484
  const actionWhere = intent.action.type === "doUpdate" && intent.action.where ? intent.action.where : void 0;
29447
- const resolvedActionWhere = actionWhere ? resolveExistsIntent(actionWhere, intent.table, deps) : void 0;
29485
+ const actionWhereCompiler = resolvedMutationWhere(
29486
+ actionWhere,
29487
+ intent.table,
29488
+ deps
29489
+ );
29490
+ const resolvedActionWhere = actionWhere ? actionWhereCompiler ? actionWhere : resolveExistsIntent(actionWhere, intent.table, deps) : void 0;
29448
29491
  const config = {
29449
29492
  table: declaredMutationTable(deps, intent.table),
29450
29493
  tableMetadata: declaredMutationTableMetadata(deps, intent.table),
@@ -29491,7 +29534,13 @@ function compileUpsert2(intent, options, deps, rowShape) {
29491
29534
  actionWhereIntent: resolvedActionWhere,
29492
29535
  compileActionWhere: (where, paramState) => {
29493
29536
  const actionState = createCompilerState();
29494
- const actionWhere2 = compileUpsertActionWhere(
29537
+ const actionWhere2 = actionWhereCompiler ? actionWhereCompiler(
29538
+ {
29539
+ ...mutationContext(deps, intent.table, MAX_DEPTH_LIMIT),
29540
+ currentAlias: declaredMutationTable(deps, intent.table)
29541
+ },
29542
+ actionState
29543
+ ) : compileUpsertActionWhere(
29495
29544
  where,
29496
29545
  intent.table,
29497
29546
  actionState,
@@ -33943,6 +33992,21 @@ var PgAdapter = class {
33943
33992
  // correctly via a fresh inner PlanCompiler (same pattern as PlanCompiler
33944
33993
  // case 'selectCustomExpression').
33945
33994
  compileSubquery(query, paramOffset) {
33995
+ if (deps.model !== void 0) {
33996
+ const issued = planFn3(query, deps.model, {
33997
+ ...options?.defaultFilters && {
33998
+ defaultFilters: options.defaultFilters
33999
+ },
34000
+ ...dialectCapabilities !== void 0 && { dialectCapabilities }
34001
+ });
34002
+ const envelope = compileSelectEnvelope(issued, options, deps);
34003
+ if (envelope.ast === void 0)
34004
+ throw new Error("A planned selectExpression body produced no AST.");
34005
+ return {
34006
+ ast: renumberParamRefsInAst(envelope.ast, paramOffset),
34007
+ parameters: envelope.parameters
34008
+ };
34009
+ }
33946
34010
  const innerCompiler = new PlanCompiler({
33947
34011
  dbCasing: deps.dbCasing ?? "preserve",
33948
34012
  defaultPkColumnName: deps.defaultPk,
@@ -59280,4 +59344,4 @@ export {
59280
59344
  planPgTransitionRun,
59281
59345
  applyPgTransitionRun
59282
59346
  };
59283
- //# sourceMappingURL=chunk-XFAIB2BL.js.map
59347
+ //# sourceMappingURL=chunk-ZFU56LKS.js.map