@dbsp/adapter-pgsql 1.2.0 → 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 +42 -1
- package/dist/index.js +1281 -819
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
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 */
|
|
@@ -282,6 +295,7 @@ declare class PlanCompiler {
|
|
|
282
295
|
private joinAliasMap;
|
|
283
296
|
/**
|
|
284
297
|
* Tracks all join aliases in use for the current query.
|
|
298
|
+
* Entries are stored in emitted database-alias space, after naming.toDatabase().
|
|
285
299
|
* Ensures no two JOINs share the same alias (DOUBLE-ALIAS prevention).
|
|
286
300
|
*/
|
|
287
301
|
private usedJoinAliases;
|
|
@@ -289,6 +303,8 @@ declare class PlanCompiler {
|
|
|
289
303
|
/** Build immutable context for handler-based WHERE compilation */
|
|
290
304
|
private handlerCtx;
|
|
291
305
|
private findAliasForLegacySourceTable;
|
|
306
|
+
private emittedJoinAlias;
|
|
307
|
+
private resolvedJoinAliases;
|
|
292
308
|
/**
|
|
293
309
|
* Dispatch a PlanDecision through the unified WHERE handler system.
|
|
294
310
|
* Bridges PlanCompiler's state to handler types, calls dispatcher, syncs back.
|
|
@@ -340,7 +356,9 @@ declare class PlanCompiler {
|
|
|
340
356
|
* Compile an includeStrategy decision and register its results.
|
|
341
357
|
* Pushes targets onto targetList, raw joins / CTEs onto instance collections.
|
|
342
358
|
*/
|
|
359
|
+
private registerIncludeCompilationResult;
|
|
343
360
|
private compileIncludeDecision;
|
|
361
|
+
private compileJoinIncludeAllocationPass;
|
|
344
362
|
/**
|
|
345
363
|
* Fold a WHERE-family decision into an existing where expression.
|
|
346
364
|
* Returns the updated (or new) where node.
|
|
@@ -362,6 +380,7 @@ declare class PlanCompiler {
|
|
|
362
380
|
* column refs like `project_id` resolve against the joined table, not root.
|
|
363
381
|
*/
|
|
364
382
|
private compileIncludeWhereConditions;
|
|
383
|
+
private reserveManualJoinAliases;
|
|
365
384
|
/**
|
|
366
385
|
* Apply a single join decision to the FROM clause in-place.
|
|
367
386
|
* Chains multiple joins by wrapping from[0] as the left-arg each time.
|
|
@@ -377,11 +396,21 @@ declare class PlanCompiler {
|
|
|
377
396
|
* Returns undefined when neither expressionIntent nor column is present.
|
|
378
397
|
*/
|
|
379
398
|
private compileOrderByDecision;
|
|
399
|
+
/**
|
|
400
|
+
* Compile a column reference that may use dotted 'relation.column' notation.
|
|
401
|
+
*/
|
|
402
|
+
private compileRelationAwareColumnRef;
|
|
380
403
|
/**
|
|
381
404
|
* Compile a single groupBy decision into a ColumnRef AST node.
|
|
382
405
|
* Supports dotted 'relation.column' notation for joined tables.
|
|
383
406
|
*/
|
|
384
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;
|
|
385
414
|
/**
|
|
386
415
|
* Assemble the final SelectStmt from all accumulated clause nodes.
|
|
387
416
|
* Also handles the default SELECT *, CTEs, and row-level locking.
|
|
@@ -1042,6 +1071,8 @@ interface CompilerContext {
|
|
|
1042
1071
|
readonly rootTable: string;
|
|
1043
1072
|
/** Current table alias (for JOINs) */
|
|
1044
1073
|
readonly currentAlias?: string;
|
|
1074
|
+
/** Final relation path/name → SQL join alias map for relation-aware expression contexts */
|
|
1075
|
+
readonly aliases?: ReadonlyMap<string, string>;
|
|
1045
1076
|
/** Maximum recursive depth (default: 100) */
|
|
1046
1077
|
readonly maxRecursiveDepth: number;
|
|
1047
1078
|
/** Optional callback for raw SQL audit trail */
|
|
@@ -1052,6 +1083,8 @@ interface CompilerContext {
|
|
|
1052
1083
|
readonly deriveFkColumnName?: FkColumnDerivation;
|
|
1053
1084
|
/** Alias of the outer (parent) query — used for FieldRef scope:'outer' resolution in EXISTS subqueries */
|
|
1054
1085
|
readonly outerAlias?: string;
|
|
1086
|
+
/** Query-local CTE/binding names that must not be schema-qualified. */
|
|
1087
|
+
readonly bindingNames?: BindingNameRegistry;
|
|
1055
1088
|
/**
|
|
1056
1089
|
* Optional callback to compile a QueryIntent into an AST Node (SubLink subselect).
|
|
1057
1090
|
* Set by PlanCompiler when compiling selectCustomExpression — enables SubqueryExpressionIntent
|
|
@@ -1405,6 +1438,12 @@ interface UpsertConfig {
|
|
|
1405
1438
|
conflictAction: ConflictAction;
|
|
1406
1439
|
/** Columns to update on conflict (for 'update' action) */
|
|
1407
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;
|
|
1408
1447
|
/** Use EXCLUDED.column for update values (default: true) */
|
|
1409
1448
|
useExcluded?: boolean;
|
|
1410
1449
|
/** Columns to return (RETURNING clause) */
|
|
@@ -1608,6 +1647,7 @@ declare class PgsqlAdapter<DB = unknown> implements Adapter<DB> {
|
|
|
1608
1647
|
private cloneOptions;
|
|
1609
1648
|
private buildCompileDeps;
|
|
1610
1649
|
private requireNqlCompileModel;
|
|
1650
|
+
private assertNqlBindingNamesDisjointFromTables;
|
|
1611
1651
|
private compileNqlMutation;
|
|
1612
1652
|
private compileNqlBundleLeaf;
|
|
1613
1653
|
private compileNqlBundle;
|
|
@@ -1712,6 +1752,7 @@ declare class PgsqlAdapter<DB = unknown> implements Adapter<DB> {
|
|
|
1712
1752
|
* Compile a set operation (UNION / INTERSECT / EXCEPT) to SQL.
|
|
1713
1753
|
*/
|
|
1714
1754
|
compileSetOperation(intent: SetOperationIntent, model: ModelIR, options?: CompileOptions): CompiledQuery;
|
|
1755
|
+
private compileSetOperationWithBindings;
|
|
1715
1756
|
/**
|
|
1716
1757
|
* Create a dump for observability.
|
|
1717
1758
|
*/
|