@dbsp/adapter-pgsql 1.2.1 → 1.3.0

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.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ExpressionRef, IndexInfo, TruncateOptions, VacuumOptions, AlterColumnOptions, CreateIndexOptions, DropIndexOptions, ModelIR as ModelIR$1 } from '@dbsp/core';
2
2
  export { normalizeSQL } from '@dbsp/core';
3
3
  import * as _dbsp_types from '@dbsp/types';
4
- import { ParamIntent, DialectCapabilities, ModelIR, DbCasing, ColumnIR, HierarchyIR, Adapter, AdapterLogger, AdapterCapabilities, PlanReport, CompiledNqlQuery, CompileOptions, CompiledQuery, CompileResultWithIncludes, SubqueryIncludeInfo, ExpressionIntent, InsertIntent, InsertFromIntent, UpdateIntent, BatchUpdateIntent, DeleteIntent, UpsertIntent, UpsertFromIntent, RecursivePlanReport, CteQueryIntent, SetOperationIntent, DumpMeta, Dump, AdapterStreamOptions, CompileOnlyAdapter, QueryIntent } from '@dbsp/types';
4
+ import { ParamIntent, DialectCapabilities, ModelIR, DbCasing, ColumnIR, HierarchyIR, WhereIntent, Adapter, AdapterLogger, AdapterCapabilities, PlanReport, CompiledNqlQuery, CompileOptions, CompiledQuery, CompileResultWithIncludes, SubqueryIncludeInfo, ExpressionIntent, InsertIntent, InsertFromIntent, UpdateIntent, BatchUpdateIntent, DeleteIntent, UpsertIntent, UpsertFromIntent, RecursivePlanReport, CteQueryIntent, SetOperationIntent, DumpMeta, Dump, AdapterStreamOptions, CompileOnlyAdapter, QueryIntent } from '@dbsp/types';
5
5
  import * as _pgsql_types from '@pgsql/types';
6
6
  import { Node, OnConflictClause, ParamRef } from '@pgsql/types';
7
7
  import { Pool, PoolClient } from 'pg';
@@ -89,6 +89,16 @@ declare const camelCaseNaming: CamelCaseNamingPlugin;
89
89
  */
90
90
  declare function getNamingPluginForDbCasing(casing: 'snake_case' | 'camelCase' | 'preserve'): NamingPlugin;
91
91
 
92
+ /**
93
+ * Internal registry of NQL `| bind name` CTE names visible to a compile pass.
94
+ *
95
+ * Binding names are query-local identifiers, not physical tables. When an active
96
+ * schema is present, real table FROM sources must be schema-qualified, while CTE
97
+ * binding names must remain unqualified.
98
+ */
99
+
100
+ type BindingNameRegistry = ReadonlySet<string>;
101
+
92
102
  /**
93
103
  * Simplified PlanDecision for the spike
94
104
  * (In production, import from @dbsp/core)
@@ -257,6 +267,8 @@ interface CompilerOptions {
257
267
  readonly deriveFkColumnName?: FkColumnDerivation;
258
268
  /** ModelIR for type-aware parameter casting in WHERE clauses */
259
269
  readonly model?: _dbsp_types.ModelIR;
270
+ /** Query-local CTE/binding names that must not be schema-qualified. */
271
+ readonly bindingNames?: BindingNameRegistry;
260
272
  }
261
273
  declare class PlanCompiler {
262
274
  private readonly naming;
@@ -264,6 +276,7 @@ declare class PlanCompiler {
264
276
  private readonly defaultPk;
265
277
  private readonly deriveFk;
266
278
  private readonly model;
279
+ private readonly bindingNames;
267
280
  /** Mutable state shared with extracted condition/value compilation functions */
268
281
  private state;
269
282
  /** Track root table for EXISTS FK correlation */
@@ -383,11 +396,21 @@ declare class PlanCompiler {
383
396
  * Returns undefined when neither expressionIntent nor column is present.
384
397
  */
385
398
  private compileOrderByDecision;
399
+ /**
400
+ * Compile a column reference that may use dotted 'relation.column' notation.
401
+ */
402
+ private compileRelationAwareColumnRef;
386
403
  /**
387
404
  * Compile a single groupBy decision into a ColumnRef AST node.
388
405
  * Supports dotted 'relation.column' notation for joined tables.
389
406
  */
390
407
  private compileGroupByDecision;
408
+ /**
409
+ * Compile a DISTINCT ON column into a ColumnRef AST node.
410
+ * Mirrors GROUP BY relation-alias resolution while preserving unqualified
411
+ * DISTINCT ON columns as unqualified references.
412
+ */
413
+ private compileDistinctOnColumn;
391
414
  /**
392
415
  * Assemble the final SelectStmt from all accumulated clause nodes.
393
416
  * Also handles the default SELECT *, CTEs, and row-level locking.
@@ -1060,6 +1083,8 @@ interface CompilerContext {
1060
1083
  readonly deriveFkColumnName?: FkColumnDerivation;
1061
1084
  /** Alias of the outer (parent) query — used for FieldRef scope:'outer' resolution in EXISTS subqueries */
1062
1085
  readonly outerAlias?: string;
1086
+ /** Query-local CTE/binding names that must not be schema-qualified. */
1087
+ readonly bindingNames?: BindingNameRegistry;
1063
1088
  /**
1064
1089
  * Optional callback to compile a QueryIntent into an AST Node (SubLink subselect).
1065
1090
  * Set by PlanCompiler when compiling selectCustomExpression — enables SubqueryExpressionIntent
@@ -1413,6 +1438,12 @@ interface UpsertConfig {
1413
1438
  conflictAction: ConflictAction;
1414
1439
  /** Columns to update on conflict (for 'update' action) */
1415
1440
  updateColumns?: string[];
1441
+ /** Optional WHERE clause for ON CONFLICT DO UPDATE */
1442
+ actionWhere?: Decision[];
1443
+ /** Optional direct WHERE intent for ON CONFLICT DO UPDATE */
1444
+ actionWhereIntent?: WhereIntent;
1445
+ /** Compile the direct action WHERE intent using the caller's WHERE compiler */
1446
+ compileActionWhere?: (where: WhereIntent, state: CompilerState) => Node;
1416
1447
  /** Use EXCLUDED.column for update values (default: true) */
1417
1448
  useExcluded?: boolean;
1418
1449
  /** Columns to return (RETURNING clause) */
@@ -1616,6 +1647,7 @@ declare class PgsqlAdapter<DB = unknown> implements Adapter<DB> {
1616
1647
  private cloneOptions;
1617
1648
  private buildCompileDeps;
1618
1649
  private requireNqlCompileModel;
1650
+ private assertNqlBindingNamesDisjointFromTables;
1619
1651
  private compileNqlMutation;
1620
1652
  private compileNqlBundleLeaf;
1621
1653
  private compileNqlBundle;
@@ -1720,6 +1752,7 @@ declare class PgsqlAdapter<DB = unknown> implements Adapter<DB> {
1720
1752
  * Compile a set operation (UNION / INTERSECT / EXCEPT) to SQL.
1721
1753
  */
1722
1754
  compileSetOperation(intent: SetOperationIntent, model: ModelIR, options?: CompileOptions): CompiledQuery;
1755
+ private compileSetOperationWithBindings;
1723
1756
  /**
1724
1757
  * Create a dump for observability.
1725
1758
  */