postgrelize 0.0.0-stage → 1.1.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/CHANGELOG.md +289 -0
- package/LICENSE +21 -0
- package/README.md +131 -2
- package/dist/associations/alias-minifier.d.ts +43 -0
- package/dist/associations/association-accessors.d.ts +21 -0
- package/dist/associations/association-key-types.d.ts +44 -0
- package/dist/associations/association-keys.d.ts +98 -0
- package/dist/associations/association-lookup.d.ts +26 -0
- package/dist/associations/association-shape.d.ts +25 -0
- package/dist/associations/association.d.ts +95 -0
- package/dist/associations/belongs-to-many.d.ts +86 -0
- package/dist/associations/belongs-to.d.ts +45 -0
- package/dist/associations/has-many.d.ts +79 -0
- package/dist/associations/has-one.d.ts +44 -0
- package/dist/associations/include-assembler.d.ts +21 -0
- package/dist/associations/include-columns.d.ts +24 -0
- package/dist/associations/include-joins.d.ts +17 -0
- package/dist/associations/include-loader.d.ts +48 -0
- package/dist/associations/include-order.d.ts +22 -0
- package/dist/associations/include-query-builder.d.ts +54 -0
- package/dist/associations/include-resolver.d.ts +29 -0
- package/dist/associations/include-rows.d.ts +47 -0
- package/dist/associations/include-sub-query.d.ts +35 -0
- package/dist/associations/include.d.ts +112 -0
- package/dist/associations/junction-keys.d.ts +23 -0
- package/dist/associations/nested-creator.d.ts +44 -0
- package/dist/associations/nested-saver.d.ts +30 -0
- package/dist/associations/owner-keys.d.ts +34 -0
- package/dist/associations/separate-include-loader.d.ts +24 -0
- package/dist/associations/types.d.ts +139 -0
- package/dist/connection/after-connect-hook.d.ts +24 -0
- package/dist/connection/connect-hooks.d.ts +26 -0
- package/dist/connection/connection-config.d.ts +33 -0
- package/dist/connection/connection-manager.d.ts +65 -0
- package/dist/connection/connection-types.d.ts +21 -0
- package/dist/connection/copy-from-stdin.d.ts +52 -0
- package/dist/connection/copy-runner.d.ts +30 -0
- package/dist/connection/copy-to-stdout.d.ts +49 -0
- package/dist/connection/copy.d.ts +22 -0
- package/dist/connection/notifications.d.ts +28 -0
- package/dist/connection/options.d.ts +165 -0
- package/dist/connection/query-logger.d.ts +41 -0
- package/dist/connection/replica-router.d.ts +20 -0
- package/dist/connection/statement-cache.d.ts +36 -0
- package/dist/connection/statement-timeout.d.ts +22 -0
- package/dist/data-types/abstract-data-type.d.ts +58 -0
- package/dist/data-types/array-literal-parser.d.ts +17 -0
- package/dist/data-types/array-type.d.ts +18 -0
- package/dist/data-types/bit-type.d.ts +14 -0
- package/dist/data-types/blob-type.d.ts +12 -0
- package/dist/data-types/char-type.d.ts +12 -0
- package/dist/data-types/composite-fields.d.ts +26 -0
- package/dist/data-types/composite-type.d.ts +32 -0
- package/dist/data-types/data-types.d.ts +176 -0
- package/dist/data-types/date-type.d.ts +14 -0
- package/dist/data-types/decimal-type.d.ts +13 -0
- package/dist/data-types/default-value-generator.d.ts +15 -0
- package/dist/data-types/enum-type.d.ts +19 -0
- package/dist/data-types/ewkb-reader.d.ts +18 -0
- package/dist/data-types/ewkb-writer.d.ts +17 -0
- package/dist/data-types/float-type.d.ts +12 -0
- package/dist/data-types/geometric-text.d.ts +65 -0
- package/dist/data-types/geometric-type.d.ts +46 -0
- package/dist/data-types/hstore-type.d.ts +16 -0
- package/dist/data-types/integer-type.d.ts +24 -0
- package/dist/data-types/json-type.d.ts +16 -0
- package/dist/data-types/multirange-type.d.ts +19 -0
- package/dist/data-types/range-type.d.ts +28 -0
- package/dist/data-types/record-text.d.ts +29 -0
- package/dist/data-types/scalar-type.d.ts +13 -0
- package/dist/data-types/spatial-type.d.ts +20 -0
- package/dist/data-types/string-type.d.ts +12 -0
- package/dist/data-types/text-type.d.ts +12 -0
- package/dist/data-types/timestamp-type.d.ts +15 -0
- package/dist/data-types/virtual-type.d.ts +15 -0
- package/dist/data-types/wall-clock.d.ts +14 -0
- package/dist/ddl/column-ddl.d.ts +73 -0
- package/dist/ddl/constraint-ddl.d.ts +30 -0
- package/dist/ddl/ddl-generator.d.ts +181 -0
- package/dist/ddl/ddl-guards.d.ts +60 -0
- package/dist/ddl/ddl-types.d.ts +204 -0
- package/dist/ddl/enum-ddl.d.ts +42 -0
- package/dist/ddl/extension-ddl.d.ts +57 -0
- package/dist/ddl/function-ddl.d.ts +98 -0
- package/dist/ddl/index-ddl.d.ts +29 -0
- package/dist/ddl/index-element-ddl.d.ts +19 -0
- package/dist/ddl/partition-ddl.d.ts +88 -0
- package/dist/ddl/partition-types.d.ts +94 -0
- package/dist/ddl/policy-ddl.d.ts +137 -0
- package/dist/ddl/routine-guards.d.ts +63 -0
- package/dist/ddl/sequence-ddl.d.ts +103 -0
- package/dist/ddl/sql-literal.d.ts +61 -0
- package/dist/ddl/table-ddl.d.ts +35 -0
- package/dist/ddl/trigger-ddl.d.ts +81 -0
- package/dist/ddl/view-ddl.d.ts +122 -0
- package/dist/decorators/association-applier.d.ts +18 -0
- package/dist/decorators/association-decorators.d.ts +72 -0
- package/dist/decorators/column-decorators.d.ts +147 -0
- package/dist/decorators/decorator-factory.d.ts +45 -0
- package/dist/decorators/decorator-signature.d.ts +26 -0
- package/dist/decorators/decorator-types.d.ts +24 -0
- package/dist/decorators/foreign-key-decorator.d.ts +21 -0
- package/dist/decorators/hook-decorators.d.ts +393 -0
- package/dist/decorators/init-arguments.d.ts +29 -0
- package/dist/decorators/model-decorators.d.ts +18 -0
- package/dist/decorators/model-metadata.d.ts +70 -0
- package/dist/decorators/table-decorators.d.ts +43 -0
- package/dist/decorators/timestamp-decorators.d.ts +38 -0
- package/dist/errors/base-error.d.ts +40 -0
- package/dist/errors/connection-errors.d.ts +152 -0
- package/dist/errors/database-errors.d.ts +186 -0
- package/dist/errors/errors.d.ts +5 -0
- package/dist/errors/map-pg-error.d.ts +27 -0
- package/dist/errors/misc-errors.d.ts +232 -0
- package/dist/errors/validation-errors.d.ts +141 -0
- package/dist/exports-associations.d.ts +6 -0
- package/dist/exports-core.d.ts +95 -0
- package/dist/exports-decorators.d.ts +8 -0
- package/dist/exports-errors.d.ts +2 -0
- package/dist/exports-model.d.ts +21 -0
- package/dist/exports-schema.d.ts +19 -0
- package/dist/expressions/call-expressions.d.ts +54 -0
- package/dist/expressions/condition-expressions.d.ts +51 -0
- package/dist/expressions/expression.d.ts +52 -0
- package/dist/expressions/jsonpath-helpers.d.ts +37 -0
- package/dist/expressions/logic.d.ts +25 -0
- package/dist/expressions/methods.d.ts +188 -0
- package/dist/expressions/op.d.ts +182 -0
- package/dist/expressions/query-expressions.d.ts +110 -0
- package/dist/expressions/row-expressions.d.ts +35 -0
- package/dist/expressions/search-helpers.d.ts +138 -0
- package/dist/expressions/trigram-helpers.d.ts +40 -0
- package/dist/hooks/hooks.d.ts +125 -0
- package/dist/index.cjs +21864 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +21688 -0
- package/dist/index.js.map +1 -0
- package/dist/model/attribute-columns.d.ts +85 -0
- package/dist/model/attribute-normalizer.d.ts +42 -0
- package/dist/model/attribute-options.d.ts +121 -0
- package/dist/model/bulk-insert-builder.d.ts +24 -0
- package/dist/model/bulk-options.d.ts +173 -0
- package/dist/model/copy-options.d.ts +51 -0
- package/dist/model/cte-builder.d.ts +134 -0
- package/dist/model/definition-normalizer.d.ts +26 -0
- package/dist/model/delete-query-builder.d.ts +42 -0
- package/dist/model/find-options.d.ts +144 -0
- package/dist/model/find-query-builder.d.ts +38 -0
- package/dist/model/inflector.d.ts +28 -0
- package/dist/model/insert-query-builder.d.ts +41 -0
- package/dist/model/instance-destroyer.d.ts +44 -0
- package/dist/model/instance-lifecycle-services.d.ts +61 -0
- package/dist/model/instance-lifecycle.d.ts +128 -0
- package/dist/model/instance-saver.d.ts +25 -0
- package/dist/model/instance-state.d.ts +48 -0
- package/dist/model/instance-validation.d.ts +35 -0
- package/dist/model/instance-values.d.ts +88 -0
- package/dist/model/instance-writer.d.ts +59 -0
- package/dist/model/join-source-builder.d.ts +25 -0
- package/dist/model/lateral-keys-builder.d.ts +25 -0
- package/dist/model/merge-action-builder.d.ts +31 -0
- package/dist/model/merge-options.d.ts +72 -0
- package/dist/model/merge-query-builder.d.ts +29 -0
- package/dist/model/merge-source-builder.d.ts +22 -0
- package/dist/model/mixins/model-aggregates.d.ts +69 -0
- package/dist/model/mixins/model-associations.d.ts +113 -0
- package/dist/model/mixins/model-constructor.d.ts +7 -0
- package/dist/model/mixins/model-finders.d.ts +140 -0
- package/dist/model/mixins/model-hooks.d.ts +142 -0
- package/dist/model/mixins/model-postgres.d.ts +198 -0
- package/dist/model/mixins/model-schema-binding.d.ts +36 -0
- package/dist/model/mixins/model-schema.d.ts +100 -0
- package/dist/model/mixins/model-scopes.d.ts +57 -0
- package/dist/model/mixins/model-writers.d.ts +175 -0
- package/dist/model/mixins/named-hooks.d.ts +28 -0
- package/dist/model/model-accessors.d.ts +22 -0
- package/dist/model/model-base.d.ts +83 -0
- package/dist/model/model-definition.d.ts +130 -0
- package/dist/model/model-instance-persistence.d.ts +132 -0
- package/dist/model/model-instance-values.d.ts +197 -0
- package/dist/model/model-operations.d.ts +22 -0
- package/dist/model/model-registry.d.ts +152 -0
- package/dist/model/model-services.d.ts +46 -0
- package/dist/model/model-state.d.ts +68 -0
- package/dist/model/model-values.d.ts +86 -0
- package/dist/model/model.d.ts +629 -0
- package/dist/model/on-conflict-builder.d.ts +111 -0
- package/dist/model/operations/bulk-create-operation.d.ts +40 -0
- package/dist/model/operations/copy-from-source.d.ts +51 -0
- package/dist/model/operations/copy-operation.d.ts +54 -0
- package/dist/model/operations/count-operation.d.ts +52 -0
- package/dist/model/operations/create-operation.d.ts +31 -0
- package/dist/model/operations/destroy-operation.d.ts +65 -0
- package/dist/model/operations/find-cursor.d.ts +23 -0
- package/dist/model/operations/find-lookups.d.ts +99 -0
- package/dist/model/operations/find-operation.d.ts +47 -0
- package/dist/model/operations/increment-operation.d.ts +40 -0
- package/dist/model/operations/insert-operation.d.ts +71 -0
- package/dist/model/operations/merge-operation.d.ts +56 -0
- package/dist/model/operations/model-operation.d.ts +33 -0
- package/dist/model/operations/update-operation.d.ts +45 -0
- package/dist/model/operations/upsert-operation.d.ts +39 -0
- package/dist/model/options.d.ts +103 -0
- package/dist/model/returning-old.d.ts +52 -0
- package/dist/model/row-mapper.d.ts +78 -0
- package/dist/model/row-plan.d.ts +31 -0
- package/dist/model/runtime.d.ts +56 -0
- package/dist/model/scope-registry.d.ts +81 -0
- package/dist/model/select-aggregates.d.ts +37 -0
- package/dist/model/select-lock.d.ts +13 -0
- package/dist/model/select-options.d.ts +92 -0
- package/dist/model/select-query-builder.d.ts +73 -0
- package/dist/model/select-targets.d.ts +77 -0
- package/dist/model/source-option-builder.d.ts +23 -0
- package/dist/model/source-options.d.ts +108 -0
- package/dist/model/statement-builder.d.ts +77 -0
- package/dist/model/statement-services.d.ts +2 -0
- package/dist/model/sync-hooks.d.ts +18 -0
- package/dist/model/table-sample-builder.d.ts +13 -0
- package/dist/model/types.d.ts +85 -0
- package/dist/model/unnest-insert-builder.d.ts +24 -0
- package/dist/model/update-query-builder.d.ts +39 -0
- package/dist/model/v6-conflict-builder.d.ts +37 -0
- package/dist/model/value-cloner.d.ts +17 -0
- package/dist/model/values-writer.d.ts +12 -0
- package/dist/model/where-options.d.ts +164 -0
- package/dist/model/write-options.d.ts +160 -0
- package/dist/model/written-rows.d.ts +56 -0
- package/dist/package-version.d.ts +8 -0
- package/dist/query/query-result-shaper.d.ts +93 -0
- package/dist/query/raw-query.d.ts +27 -0
- package/dist/query-interface/alter-planner.d.ts +40 -0
- package/dist/query-interface/bulk-data.d.ts +44 -0
- package/dist/query-interface/column-commands.d.ts +52 -0
- package/dist/query-interface/column-describer.d.ts +17 -0
- package/dist/query-interface/enum-commands.d.ts +36 -0
- package/dist/query-interface/index-commands.d.ts +57 -0
- package/dist/query-interface/model-tables.d.ts +58 -0
- package/dist/query-interface/object-commands.d.ts +71 -0
- package/dist/query-interface/partition-commands.d.ts +43 -0
- package/dist/query-interface/policy-commands.d.ts +54 -0
- package/dist/query-interface/query-interface-catalog.d.ts +180 -0
- package/dist/query-interface/query-interface-objects.d.ts +108 -0
- package/dist/query-interface/query-interface-partitions.d.ts +66 -0
- package/dist/query-interface/query-interface-policies.d.ts +86 -0
- package/dist/query-interface/query-interface-routines.d.ts +120 -0
- package/dist/query-interface/query-interface-tables.d.ts +179 -0
- package/dist/query-interface/query-interface-types.d.ts +62 -0
- package/dist/query-interface/query-interface-views.d.ts +84 -0
- package/dist/query-interface/query-interface.d.ts +256 -0
- package/dist/query-interface/routine-commands.d.ts +71 -0
- package/dist/query-interface/schema-synchronizer.d.ts +110 -0
- package/dist/query-interface/statement-runner.d.ts +40 -0
- package/dist/query-interface/sync-planner.d.ts +26 -0
- package/dist/query-interface/table-commands.d.ts +63 -0
- package/dist/query-interface/table-introspector.d.ts +58 -0
- package/dist/query-interface/view-commands.d.ts +47 -0
- package/dist/sequelize/instance-hook-adders.d.ts +72 -0
- package/dist/sequelize/sequelize-base.d.ts +196 -0
- package/dist/sequelize/sequelize-constructor.d.ts +7 -0
- package/dist/sequelize/sequelize-helpers.d.ts +133 -0
- package/dist/sequelize/sequelize-hooks.d.ts +99 -0
- package/dist/sequelize/sequelize-internals.d.ts +87 -0
- package/dist/sequelize/sequelize-notifications.d.ts +66 -0
- package/dist/sequelize/sequelize-schema.d.ts +125 -0
- package/dist/sequelize/sequelize-transactions.d.ts +96 -0
- package/dist/sequelize.d.ts +1175 -0
- package/dist/sql/ast-clauses.d.ts +137 -0
- package/dist/sql/ast-expressions.d.ts +88 -0
- package/dist/sql/ast-statements.d.ts +80 -0
- package/dist/sql/ast.d.ts +21 -0
- package/dist/sql/compile.d.ts +21 -0
- package/dist/sql/dml-compiler.d.ts +54 -0
- package/dist/sql/expression-compiler.d.ts +56 -0
- package/dist/sql/from-compiler.d.ts +39 -0
- package/dist/sql/identifier-quoter.d.ts +15 -0
- package/dist/sql/merge-compiler.d.ts +20 -0
- package/dist/sql/order.d.ts +15 -0
- package/dist/sql/query-compiler.d.ts +45 -0
- package/dist/sql/sql-chunks.d.ts +50 -0
- package/dist/sql/with-compiler.d.ts +19 -0
- package/dist/transaction/advisory-locks.d.ts +28 -0
- package/dist/transaction/cls-namespace.d.ts +44 -0
- package/dist/transaction/transaction-constants.d.ts +35 -0
- package/dist/transaction/transaction-runner.d.ts +78 -0
- package/dist/transaction/transaction-starter.d.ts +25 -0
- package/dist/transaction/transaction-statements.d.ts +29 -0
- package/dist/transaction/transaction.d.ts +201 -0
- package/dist/validation/attribute-validators.d.ts +23 -0
- package/dist/validation/builtin-attribute-validator.d.ts +19 -0
- package/dist/validation/builtin-validators.d.ts +16 -0
- package/dist/validation/core-validator.d.ts +16 -0
- package/dist/validation/custom-validators.d.ts +13 -0
- package/dist/validation/instance-validator.d.ts +25 -0
- package/dist/validation/schema-items.d.ts +22 -0
- package/dist/validation/standard-schema-validator.d.ts +30 -0
- package/dist/validation/standard-schema.d.ts +39 -0
- package/dist/validation/types.d.ts +36 -0
- package/dist/validation/validation-target.d.ts +13 -0
- package/dist/where/comparison-compiler.d.ts +27 -0
- package/dist/where/condition-compiler.d.ts +18 -0
- package/dist/where/operand-resolver.d.ts +10 -0
- package/dist/where/operator-allowlist.d.ts +14 -0
- package/dist/where/where-support.d.ts +52 -0
- package/dist/where/where.d.ts +46 -0
- package/dist/where/window-compiler.d.ts +14 -0
- package/llm/USAGE.md +423 -0
- package/package.json +103 -4
- package/skills/postgrelize/SKILL.md +57 -0
- package/skills/postgrelize/reference/associations.md +108 -0
- package/skills/postgrelize/reference/errors.md +37 -0
- package/skills/postgrelize/reference/migrating-from-sequelize.md +15 -0
- package/skills/postgrelize/reference/postgresql-features.md +157 -0
- package/skills/postgrelize/reference/querying.md +111 -0
- package/skills/postgrelize/reference/schema.md +135 -0
- package/skills/postgrelize/reference/security.md +34 -0
- package/skills/postgrelize/reference/transactions-and-sessions.md +122 -0
- package/skills/postgrelize/reference/writing.md +198 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { ExprNode } from './ast-expressions.ts';
|
|
2
|
+
import { ModifyingNode, QueryNode } from './ast-statements.ts';
|
|
3
|
+
/** `TABLESAMPLE method (percent) [REPEATABLE (seed)]` of a FROM table. */
|
|
4
|
+
export type TableSample = Readonly<{
|
|
5
|
+
method: 'BERNOULLI' | 'SYSTEM';
|
|
6
|
+
percent: ExprNode;
|
|
7
|
+
seed?: ExprNode;
|
|
8
|
+
}>;
|
|
9
|
+
export type TableRef = Readonly<{
|
|
10
|
+
name: string;
|
|
11
|
+
schema?: string;
|
|
12
|
+
alias?: string;
|
|
13
|
+
/** Only rendered where the table is a FROM source. */
|
|
14
|
+
sample?: TableSample;
|
|
15
|
+
}>;
|
|
16
|
+
export type SubquerySource = Readonly<{
|
|
17
|
+
subquery: QueryNode;
|
|
18
|
+
alias: string;
|
|
19
|
+
lateral?: boolean;
|
|
20
|
+
}>;
|
|
21
|
+
/** `(VALUES (...), ...) AS alias(columns)`. */
|
|
22
|
+
export type ValuesSource = Readonly<{
|
|
23
|
+
values: readonly (readonly ExprNode[])[];
|
|
24
|
+
alias: string;
|
|
25
|
+
columns: readonly string[];
|
|
26
|
+
}>;
|
|
27
|
+
/** `fn(args) [WITH ORDINALITY] AS alias[(columns)]`; `function` is the identifier path of the name. */
|
|
28
|
+
export type FunctionSource = Readonly<{
|
|
29
|
+
function: readonly string[];
|
|
30
|
+
args: readonly ExprNode[];
|
|
31
|
+
alias: string;
|
|
32
|
+
columns?: readonly string[];
|
|
33
|
+
/** Name of the ordinality column, which `columns` must list last. */
|
|
34
|
+
ordinality?: string;
|
|
35
|
+
}>;
|
|
36
|
+
/** One column of `JSON_TABLE`; `path` is an already escaped SQL string literal. */
|
|
37
|
+
export type JsonTableColumn = Readonly<{
|
|
38
|
+
name: string;
|
|
39
|
+
kind: 'ordinality';
|
|
40
|
+
}> | Readonly<{
|
|
41
|
+
name: string;
|
|
42
|
+
kind: 'value' | 'exists';
|
|
43
|
+
type: string;
|
|
44
|
+
path?: string;
|
|
45
|
+
}>;
|
|
46
|
+
/** `JSON_TABLE(doc, path COLUMNS (...)) AS alias` (PostgreSQL 17+); `path` is an escaped literal. */
|
|
47
|
+
export type JsonTableSource = Readonly<{
|
|
48
|
+
jsonTable: Readonly<{
|
|
49
|
+
doc: ExprNode;
|
|
50
|
+
path: string;
|
|
51
|
+
columns: readonly JsonTableColumn[];
|
|
52
|
+
}>;
|
|
53
|
+
alias: string;
|
|
54
|
+
}>;
|
|
55
|
+
export type JoinNode = Readonly<{
|
|
56
|
+
type: 'INNER' | 'LEFT OUTER' | 'RIGHT OUTER';
|
|
57
|
+
table: FromItem;
|
|
58
|
+
on: ExprNode;
|
|
59
|
+
}>;
|
|
60
|
+
export type FromItem = TableRef | SubquerySource | ValuesSource | FunctionSource | JsonTableSource;
|
|
61
|
+
export type LockNode = Readonly<{
|
|
62
|
+
strength: 'UPDATE' | 'NO KEY UPDATE' | 'SHARE' | 'KEY SHARE';
|
|
63
|
+
of?: readonly string[];
|
|
64
|
+
wait?: 'NOWAIT' | 'SKIP LOCKED';
|
|
65
|
+
}>;
|
|
66
|
+
export type SetOperator = 'UNION' | 'INTERSECT' | 'EXCEPT';
|
|
67
|
+
/** `left UNION | INTERSECT | EXCEPT [ALL] right`. */
|
|
68
|
+
export type SetOperationNode = Readonly<{
|
|
69
|
+
kind: 'setop';
|
|
70
|
+
op: SetOperator;
|
|
71
|
+
all: boolean;
|
|
72
|
+
left: QueryNode;
|
|
73
|
+
right: QueryNode;
|
|
74
|
+
}>;
|
|
75
|
+
/** `SEARCH { BREADTH | DEPTH } FIRST BY columns SET column` of a recursive CTE. */
|
|
76
|
+
export type CteSearch = Readonly<{
|
|
77
|
+
mode: 'BREADTH' | 'DEPTH';
|
|
78
|
+
by: readonly string[];
|
|
79
|
+
set: string;
|
|
80
|
+
}>;
|
|
81
|
+
/** `CYCLE columns SET column [USING path]` of a recursive CTE. */
|
|
82
|
+
export type CteCycle = Readonly<{
|
|
83
|
+
columns: readonly string[];
|
|
84
|
+
set: string;
|
|
85
|
+
using: string;
|
|
86
|
+
}>;
|
|
87
|
+
export type CteNode = Readonly<{
|
|
88
|
+
name: string;
|
|
89
|
+
/** A query, or (non-recursive only) a data-modifying statement with RETURNING. */
|
|
90
|
+
query: QueryNode | ModifyingNode;
|
|
91
|
+
materialized?: boolean;
|
|
92
|
+
search?: CteSearch;
|
|
93
|
+
cycle?: CteCycle;
|
|
94
|
+
}>;
|
|
95
|
+
export type WithClause = Readonly<{
|
|
96
|
+
recursive: boolean;
|
|
97
|
+
ctes: readonly CteNode[];
|
|
98
|
+
}>;
|
|
99
|
+
export type ConflictTarget = Readonly<{
|
|
100
|
+
kind: 'columns';
|
|
101
|
+
items: readonly ExprNode[];
|
|
102
|
+
where?: ExprNode;
|
|
103
|
+
}> | Readonly<{
|
|
104
|
+
kind: 'constraint';
|
|
105
|
+
name: string;
|
|
106
|
+
}>;
|
|
107
|
+
export type SetItem = Readonly<{
|
|
108
|
+
column: string;
|
|
109
|
+
value: ExprNode;
|
|
110
|
+
}>;
|
|
111
|
+
export type OnConflictNode = Readonly<{
|
|
112
|
+
target?: ConflictTarget;
|
|
113
|
+
action: Readonly<{
|
|
114
|
+
kind: 'nothing';
|
|
115
|
+
}> | Readonly<{
|
|
116
|
+
kind: 'update';
|
|
117
|
+
set: readonly SetItem[];
|
|
118
|
+
where?: ExprNode;
|
|
119
|
+
}>;
|
|
120
|
+
}>;
|
|
121
|
+
export type MergeAction = Readonly<{
|
|
122
|
+
kind: 'update';
|
|
123
|
+
set: readonly SetItem[];
|
|
124
|
+
}> | Readonly<{
|
|
125
|
+
kind: 'delete';
|
|
126
|
+
}> | Readonly<{
|
|
127
|
+
kind: 'insert';
|
|
128
|
+
columns: readonly string[];
|
|
129
|
+
values: readonly ExprNode[];
|
|
130
|
+
}> | Readonly<{
|
|
131
|
+
kind: 'nothing';
|
|
132
|
+
}>;
|
|
133
|
+
export type MergeWhen = Readonly<{
|
|
134
|
+
match: 'MATCHED' | 'NOT MATCHED' | 'NOT MATCHED BY SOURCE';
|
|
135
|
+
condition?: ExprNode;
|
|
136
|
+
action: MergeAction;
|
|
137
|
+
}>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { QueryNode } from './ast-statements.ts';
|
|
2
|
+
export type ParamNode = Readonly<{
|
|
3
|
+
kind: 'param';
|
|
4
|
+
value: unknown;
|
|
5
|
+
}>;
|
|
6
|
+
export type RawNode = Readonly<{
|
|
7
|
+
kind: 'raw';
|
|
8
|
+
sql: string;
|
|
9
|
+
}>;
|
|
10
|
+
export type IdentNode = Readonly<{
|
|
11
|
+
kind: 'ident';
|
|
12
|
+
path: readonly string[];
|
|
13
|
+
}>;
|
|
14
|
+
export type StarNode = Readonly<{
|
|
15
|
+
kind: 'star';
|
|
16
|
+
table?: string;
|
|
17
|
+
}>;
|
|
18
|
+
export type FnNode = Readonly<{
|
|
19
|
+
kind: 'fn';
|
|
20
|
+
name: string;
|
|
21
|
+
args: readonly ExprNode[];
|
|
22
|
+
distinct?: boolean;
|
|
23
|
+
}>;
|
|
24
|
+
export type CastNode = Readonly<{
|
|
25
|
+
kind: 'cast';
|
|
26
|
+
expr: ExprNode;
|
|
27
|
+
type: string;
|
|
28
|
+
}>;
|
|
29
|
+
export type BinaryNode = Readonly<{
|
|
30
|
+
kind: 'binary';
|
|
31
|
+
op: string;
|
|
32
|
+
left: ExprNode;
|
|
33
|
+
right: ExprNode;
|
|
34
|
+
}>;
|
|
35
|
+
export type PrefixNode = Readonly<{
|
|
36
|
+
kind: 'prefix';
|
|
37
|
+
op: string;
|
|
38
|
+
expr: ExprNode;
|
|
39
|
+
}>;
|
|
40
|
+
export type PostfixNode = Readonly<{
|
|
41
|
+
kind: 'postfix';
|
|
42
|
+
op: string;
|
|
43
|
+
expr: ExprNode;
|
|
44
|
+
}>;
|
|
45
|
+
export type LogicalNode = Readonly<{
|
|
46
|
+
kind: 'and' | 'or';
|
|
47
|
+
items: readonly ExprNode[];
|
|
48
|
+
}>;
|
|
49
|
+
export type ListNode = Readonly<{
|
|
50
|
+
kind: 'list';
|
|
51
|
+
items: readonly ExprNode[];
|
|
52
|
+
}>;
|
|
53
|
+
export type BetweenNode = Readonly<{
|
|
54
|
+
kind: 'between';
|
|
55
|
+
expr: ExprNode;
|
|
56
|
+
low: ExprNode;
|
|
57
|
+
high: ExprNode;
|
|
58
|
+
negated: boolean;
|
|
59
|
+
}>;
|
|
60
|
+
export type ExcludedNode = Readonly<{
|
|
61
|
+
kind: 'excluded';
|
|
62
|
+
column: string;
|
|
63
|
+
}>;
|
|
64
|
+
export type SubqueryNode = Readonly<{
|
|
65
|
+
kind: 'subquery';
|
|
66
|
+
query: QueryNode;
|
|
67
|
+
}>;
|
|
68
|
+
export type AliasNode = Readonly<{
|
|
69
|
+
kind: 'alias';
|
|
70
|
+
expr: ExprNode;
|
|
71
|
+
alias: string;
|
|
72
|
+
}>;
|
|
73
|
+
export type OverNode = Readonly<{
|
|
74
|
+
kind: 'over';
|
|
75
|
+
expr: ExprNode;
|
|
76
|
+
partitionBy: readonly ExprNode[];
|
|
77
|
+
orderBy: readonly OrderNode[];
|
|
78
|
+
}>;
|
|
79
|
+
export type ValuesNode = Readonly<{
|
|
80
|
+
kind: 'values';
|
|
81
|
+
rows: readonly (readonly ExprNode[])[];
|
|
82
|
+
}>;
|
|
83
|
+
export type ExprNode = ParamNode | RawNode | IdentNode | StarNode | FnNode | CastNode | BinaryNode | PrefixNode | PostfixNode | LogicalNode | ListNode | BetweenNode | ExcludedNode | SubqueryNode | AliasNode | ValuesNode | OverNode;
|
|
84
|
+
export type OrderNode = Readonly<{
|
|
85
|
+
expr: ExprNode;
|
|
86
|
+
direction?: 'ASC' | 'DESC';
|
|
87
|
+
nulls?: 'FIRST' | 'LAST';
|
|
88
|
+
}>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { ExprNode, OrderNode } from './ast-expressions.ts';
|
|
2
|
+
import { FromItem, JoinNode, LockNode, MergeWhen, OnConflictNode, SetOperationNode, SetItem, TableRef, WithClause } from './ast-clauses.ts';
|
|
3
|
+
export type SelectNode = Readonly<{
|
|
4
|
+
kind: 'select';
|
|
5
|
+
with?: WithClause;
|
|
6
|
+
extraFrom?: readonly FromItem[];
|
|
7
|
+
distinct?: boolean;
|
|
8
|
+
distinctOn?: readonly ExprNode[];
|
|
9
|
+
columns: readonly ExprNode[];
|
|
10
|
+
from: FromItem;
|
|
11
|
+
joins?: readonly JoinNode[];
|
|
12
|
+
where?: ExprNode;
|
|
13
|
+
groupBy?: readonly ExprNode[];
|
|
14
|
+
having?: ExprNode;
|
|
15
|
+
orderBy?: readonly OrderNode[];
|
|
16
|
+
limit?: number;
|
|
17
|
+
/** `FETCH FIRST n ROWS WITH TIES` instead of `LIMIT n`; needs `limit` and `orderBy`. */
|
|
18
|
+
withTies?: boolean;
|
|
19
|
+
offset?: number;
|
|
20
|
+
lock?: LockNode;
|
|
21
|
+
}>;
|
|
22
|
+
/** A query expression: a SELECT or a set operation over query expressions. */
|
|
23
|
+
export type QueryNode = SelectNode | SetOperationNode;
|
|
24
|
+
export type InsertNode = Readonly<{
|
|
25
|
+
kind: 'insert';
|
|
26
|
+
table: TableRef;
|
|
27
|
+
columns: readonly string[];
|
|
28
|
+
rows: readonly (readonly ExprNode[])[];
|
|
29
|
+
select?: QueryNode;
|
|
30
|
+
overriding?: 'system' | 'user';
|
|
31
|
+
onConflict?: OnConflictNode;
|
|
32
|
+
returning?: readonly ExprNode[];
|
|
33
|
+
/** Alias of the pre-statement row in RETURNING (`WITH (OLD AS ...)`, PostgreSQL 18+). */
|
|
34
|
+
returningOld?: string;
|
|
35
|
+
}>;
|
|
36
|
+
export type UpdateNode = Readonly<{
|
|
37
|
+
kind: 'update';
|
|
38
|
+
table: TableRef;
|
|
39
|
+
set: readonly SetItem[];
|
|
40
|
+
from?: readonly FromItem[];
|
|
41
|
+
where?: ExprNode;
|
|
42
|
+
returning?: readonly ExprNode[];
|
|
43
|
+
/** Alias of the pre-statement row in RETURNING (`WITH (OLD AS ...)`, PostgreSQL 18+). */
|
|
44
|
+
returningOld?: string;
|
|
45
|
+
}>;
|
|
46
|
+
export type DeleteNode = Readonly<{
|
|
47
|
+
kind: 'delete';
|
|
48
|
+
table: TableRef;
|
|
49
|
+
using?: readonly FromItem[];
|
|
50
|
+
where?: ExprNode;
|
|
51
|
+
returning?: readonly ExprNode[];
|
|
52
|
+
}>;
|
|
53
|
+
export type TruncateNode = Readonly<{
|
|
54
|
+
kind: 'truncate';
|
|
55
|
+
table: TableRef;
|
|
56
|
+
cascade?: boolean;
|
|
57
|
+
restartIdentity?: boolean;
|
|
58
|
+
}>;
|
|
59
|
+
export type MergeNode = Readonly<{
|
|
60
|
+
kind: 'merge';
|
|
61
|
+
table: TableRef;
|
|
62
|
+
source: Readonly<{
|
|
63
|
+
kind: 'query';
|
|
64
|
+
query: QueryNode;
|
|
65
|
+
alias: string;
|
|
66
|
+
}> | Readonly<{
|
|
67
|
+
kind: 'values';
|
|
68
|
+
columns: readonly string[];
|
|
69
|
+
rows: readonly (readonly ExprNode[])[];
|
|
70
|
+
alias: string;
|
|
71
|
+
}>;
|
|
72
|
+
on: ExprNode;
|
|
73
|
+
when: readonly MergeWhen[];
|
|
74
|
+
returning?: readonly ExprNode[];
|
|
75
|
+
/** Alias of the pre-statement row in RETURNING (`WITH (OLD AS ...)`, PostgreSQL 18+). */
|
|
76
|
+
returningOld?: string;
|
|
77
|
+
}>;
|
|
78
|
+
/** Data-modifying statement usable as a CTE body. */
|
|
79
|
+
export type ModifyingNode = InsertNode | UpdateNode | DeleteNode;
|
|
80
|
+
export type StatementNode = SelectNode | SetOperationNode | InsertNode | UpdateNode | DeleteNode | TruncateNode | MergeNode;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BinaryNode, ExprNode, FnNode, IdentNode, LogicalNode, ParamNode, RawNode } from './ast-expressions.ts';
|
|
2
|
+
export type * from './ast-expressions.ts';
|
|
3
|
+
export type * from './ast-clauses.ts';
|
|
4
|
+
export type * from './ast-statements.ts';
|
|
5
|
+
/** Factories for the most common AST nodes. Stateless; nodes are plain immutable data. */
|
|
6
|
+
export declare class SqlAst {
|
|
7
|
+
/** Bound parameter (`$n`). */
|
|
8
|
+
param(value: unknown): ParamNode;
|
|
9
|
+
/** Raw SQL text inserted as-is. */
|
|
10
|
+
raw(sql: string): RawNode;
|
|
11
|
+
/** Quoted identifier path, e.g. `"table"."column"`. */
|
|
12
|
+
ident(...path: readonly string[]): IdentNode;
|
|
13
|
+
/** Binary operation `left op right`. */
|
|
14
|
+
binary(op: string, left: ExprNode, right: ExprNode): BinaryNode;
|
|
15
|
+
/** Conjunction of the items (`TRUE` when empty). */
|
|
16
|
+
and(items: readonly ExprNode[]): LogicalNode;
|
|
17
|
+
/** Disjunction of the items (`FALSE` when empty). */
|
|
18
|
+
or(items: readonly ExprNode[]): LogicalNode;
|
|
19
|
+
/** Function call `name(args)`. */
|
|
20
|
+
fnCall(name: string, args: readonly ExprNode[]): FnNode;
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ExprNode, StatementNode } from './ast.ts';
|
|
2
|
+
import { Chunks } from './sql-chunks.ts';
|
|
3
|
+
export type { Chunk, Chunks, ParamChunk } from './sql-chunks.ts';
|
|
4
|
+
/** Parameterized SQL text with its bound values. */
|
|
5
|
+
export type CompiledQuery = Readonly<{
|
|
6
|
+
text: string;
|
|
7
|
+
values: readonly unknown[];
|
|
8
|
+
}>;
|
|
9
|
+
/** Compiles SQL AST nodes into parameterized text with `$n` placeholders. Stateless. */
|
|
10
|
+
export declare class SqlCompiler {
|
|
11
|
+
#private;
|
|
12
|
+
constructor();
|
|
13
|
+
/** Quotes an identifier: `"name"`, doubling embedded quotes. */
|
|
14
|
+
static quoteIdent(name: string): string;
|
|
15
|
+
/** Compiles a statement. */
|
|
16
|
+
compile(node: StatementNode): CompiledQuery;
|
|
17
|
+
/** Compiles a standalone expression. */
|
|
18
|
+
compileExpr(node: ExprNode): CompiledQuery;
|
|
19
|
+
/** Joins chunks into text, numbering distinct parameter chunks `$1`, `$2`, ... */
|
|
20
|
+
finalize(chunks: Chunks): CompiledQuery;
|
|
21
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { DeleteNode, ExprNode, InsertNode, SetItem, TruncateNode, UpdateNode } from './ast.ts';
|
|
2
|
+
import { QueryCompiler } from './query-compiler.ts';
|
|
3
|
+
import { ChunkBuilder, Chunks } from './sql-chunks.ts';
|
|
4
|
+
/** Compiles INSERT, UPDATE, DELETE and TRUNCATE statements and their shared clauses. */
|
|
5
|
+
export declare class DmlCompiler extends ChunkBuilder {
|
|
6
|
+
#private;
|
|
7
|
+
/**
|
|
8
|
+
* @param query - SELECT compiler; its expression compiler is shared.
|
|
9
|
+
*/
|
|
10
|
+
constructor(query: QueryCompiler);
|
|
11
|
+
/**
|
|
12
|
+
* Compiles an INSERT statement.
|
|
13
|
+
*
|
|
14
|
+
* @param node - INSERT node.
|
|
15
|
+
* @returns Chunks.
|
|
16
|
+
*/
|
|
17
|
+
insert(node: InsertNode): Chunks;
|
|
18
|
+
/**
|
|
19
|
+
* Compiles an UPDATE statement.
|
|
20
|
+
*
|
|
21
|
+
* @param node - UPDATE node.
|
|
22
|
+
* @returns Chunks.
|
|
23
|
+
*/
|
|
24
|
+
update(node: UpdateNode): Chunks;
|
|
25
|
+
/**
|
|
26
|
+
* Compiles a DELETE statement.
|
|
27
|
+
*
|
|
28
|
+
* @param node - DELETE node.
|
|
29
|
+
* @returns Chunks.
|
|
30
|
+
*/
|
|
31
|
+
delete(node: DeleteNode): Chunks;
|
|
32
|
+
/**
|
|
33
|
+
* Compiles a TRUNCATE statement.
|
|
34
|
+
*
|
|
35
|
+
* @param node - TRUNCATE node.
|
|
36
|
+
* @returns Chunks.
|
|
37
|
+
*/
|
|
38
|
+
truncate(node: TruncateNode): Chunks;
|
|
39
|
+
/**
|
|
40
|
+
* Comma-separated `"column" = value` items.
|
|
41
|
+
*
|
|
42
|
+
* @param items - SET items.
|
|
43
|
+
* @returns Chunks.
|
|
44
|
+
*/
|
|
45
|
+
setList(items: readonly SetItem[]): Chunks;
|
|
46
|
+
/**
|
|
47
|
+
* Optional RETURNING clause.
|
|
48
|
+
*
|
|
49
|
+
* @param items - Returned expressions.
|
|
50
|
+
* @param oldAlias - Alias of the pre-statement row (`WITH (OLD AS ...)`).
|
|
51
|
+
* @returns Chunks, or nothing.
|
|
52
|
+
*/
|
|
53
|
+
returning(items: readonly ExprNode[] | undefined, oldAlias?: string): Chunks;
|
|
54
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ExprNode, OrderNode, QueryNode } from './ast.ts';
|
|
2
|
+
import { ChunkBuilder, Chunks } from './sql-chunks.ts';
|
|
3
|
+
/** Compiles SELECT statements nested in expressions (subqueries). */
|
|
4
|
+
export type SubqueryCompiler = Readonly<{
|
|
5
|
+
query(node: QueryNode): Chunks;
|
|
6
|
+
}>;
|
|
7
|
+
/** Compiles expression nodes, ORDER BY items and WHERE clauses into chunks. */
|
|
8
|
+
export declare class ExpressionCompiler extends ChunkBuilder {
|
|
9
|
+
#private;
|
|
10
|
+
/**
|
|
11
|
+
* @param queries - Compiler of subqueries.
|
|
12
|
+
*/
|
|
13
|
+
constructor(queries: SubqueryCompiler);
|
|
14
|
+
/**
|
|
15
|
+
* Compiles an expression.
|
|
16
|
+
*
|
|
17
|
+
* @param node - Expression node.
|
|
18
|
+
* @returns Chunks.
|
|
19
|
+
*/
|
|
20
|
+
expression(node: ExprNode): Chunks;
|
|
21
|
+
/**
|
|
22
|
+
* Comma-separated expressions.
|
|
23
|
+
*
|
|
24
|
+
* @param items - Expressions.
|
|
25
|
+
* @returns `a, b`.
|
|
26
|
+
*/
|
|
27
|
+
exprList(items: readonly ExprNode[]): Chunks;
|
|
28
|
+
/**
|
|
29
|
+
* Comma-separated parenthesized rows.
|
|
30
|
+
*
|
|
31
|
+
* @param rows - Rows of expressions.
|
|
32
|
+
* @returns `(a, b), (c, d)`.
|
|
33
|
+
*/
|
|
34
|
+
rows(rows: readonly (readonly ExprNode[])[]): Chunks;
|
|
35
|
+
/**
|
|
36
|
+
* Comma-separated ORDER BY items.
|
|
37
|
+
*
|
|
38
|
+
* @param items - Order items.
|
|
39
|
+
* @returns `a ASC, b DESC NULLS LAST`.
|
|
40
|
+
*/
|
|
41
|
+
orderList(items: readonly OrderNode[]): Chunks;
|
|
42
|
+
/**
|
|
43
|
+
* One ORDER BY item.
|
|
44
|
+
*
|
|
45
|
+
* @param node - Order item.
|
|
46
|
+
* @returns `expr ASC NULLS FIRST`.
|
|
47
|
+
*/
|
|
48
|
+
order(node: OrderNode): Chunks;
|
|
49
|
+
/**
|
|
50
|
+
* Optional WHERE clause.
|
|
51
|
+
*
|
|
52
|
+
* @param node - Condition.
|
|
53
|
+
* @returns ` WHERE cond`, or nothing.
|
|
54
|
+
*/
|
|
55
|
+
where(node: ExprNode | undefined): Chunks;
|
|
56
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { FunctionSource, JsonTableSource, TableRef, ValuesSource } from './ast.ts';
|
|
2
|
+
import { ExpressionCompiler } from './expression-compiler.ts';
|
|
3
|
+
import { ChunkBuilder, Chunks } from './sql-chunks.ts';
|
|
4
|
+
/** Compiles the FROM sources other than tables and subqueries: VALUES, functions, JSON_TABLE, TABLESAMPLE. */
|
|
5
|
+
export declare class FromCompiler extends ChunkBuilder {
|
|
6
|
+
#private;
|
|
7
|
+
/**
|
|
8
|
+
* @param expr - Expression compiler of the arguments.
|
|
9
|
+
*/
|
|
10
|
+
constructor(expr: ExpressionCompiler);
|
|
11
|
+
/**
|
|
12
|
+
* A table with its optional sampling clause.
|
|
13
|
+
*
|
|
14
|
+
* @param table - Table reference.
|
|
15
|
+
* @returns Chunks.
|
|
16
|
+
*/
|
|
17
|
+
table(table: TableRef): Chunks;
|
|
18
|
+
/**
|
|
19
|
+
* `(VALUES ...) AS alias(columns)`.
|
|
20
|
+
*
|
|
21
|
+
* @param source - VALUES source.
|
|
22
|
+
* @returns Chunks.
|
|
23
|
+
*/
|
|
24
|
+
values(source: ValuesSource): Chunks;
|
|
25
|
+
/**
|
|
26
|
+
* Set-returning function call.
|
|
27
|
+
*
|
|
28
|
+
* @param source - Function source.
|
|
29
|
+
* @returns Chunks.
|
|
30
|
+
*/
|
|
31
|
+
function(source: FunctionSource): Chunks;
|
|
32
|
+
/**
|
|
33
|
+
* `JSON_TABLE(...)`.
|
|
34
|
+
*
|
|
35
|
+
* @param source - JSON_TABLE source.
|
|
36
|
+
* @returns Chunks.
|
|
37
|
+
*/
|
|
38
|
+
jsonTable(source: JsonTableSource): Chunks;
|
|
39
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quotes SQL identifiers (`"name"`, embedded quotes doubled). The quoted form of a name never
|
|
3
|
+
* changes and the same few table and column names are quoted for every statement, so results are
|
|
4
|
+
* remembered; the memo stops growing at a fixed size, so arbitrary user aliases cannot exhaust memory.
|
|
5
|
+
*/
|
|
6
|
+
export declare class IdentifierQuoter {
|
|
7
|
+
#private;
|
|
8
|
+
/**
|
|
9
|
+
* Quotes an identifier.
|
|
10
|
+
*
|
|
11
|
+
* @param name - Identifier.
|
|
12
|
+
* @returns `"name"` with embedded quotes doubled.
|
|
13
|
+
*/
|
|
14
|
+
quote(name: string): string;
|
|
15
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { MergeNode } from './ast.ts';
|
|
2
|
+
import { DmlCompiler } from './dml-compiler.ts';
|
|
3
|
+
import { QueryCompiler } from './query-compiler.ts';
|
|
4
|
+
import { ChunkBuilder, Chunks } from './sql-chunks.ts';
|
|
5
|
+
/** Compiles MERGE statements. */
|
|
6
|
+
export declare class MergeCompiler extends ChunkBuilder {
|
|
7
|
+
#private;
|
|
8
|
+
/**
|
|
9
|
+
* @param query - SELECT compiler; its expression compiler is shared.
|
|
10
|
+
* @param dml - SET and RETURNING clauses.
|
|
11
|
+
*/
|
|
12
|
+
constructor(query: QueryCompiler, dml: DmlCompiler);
|
|
13
|
+
/**
|
|
14
|
+
* Compiles a MERGE statement.
|
|
15
|
+
*
|
|
16
|
+
* @param node - MERGE node.
|
|
17
|
+
* @returns Chunks.
|
|
18
|
+
*/
|
|
19
|
+
merge(node: MergeNode): Chunks;
|
|
20
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { OrderNode } from './ast.ts';
|
|
2
|
+
type Direction = NonNullable<OrderNode['direction']>;
|
|
3
|
+
type Nulls = NonNullable<OrderNode['nulls']>;
|
|
4
|
+
/** Order direction (`ASC`, `DESC NULLS LAST`, ...) from an allowlist; spreads into an order node. */
|
|
5
|
+
export declare class OrderDirection {
|
|
6
|
+
#private;
|
|
7
|
+
/** `ASC` / `DESC`; absent when only the nulls order is given. */
|
|
8
|
+
readonly direction?: Direction;
|
|
9
|
+
/** `NULLS FIRST` / `NULLS LAST`; absent when not given. */
|
|
10
|
+
readonly nulls?: Nulls;
|
|
11
|
+
private constructor();
|
|
12
|
+
/** Parses an order direction from the allowlist; throws for anything else. */
|
|
13
|
+
static parse(value: unknown): OrderDirection;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { FromItem, QueryNode, SelectNode } from './ast.ts';
|
|
2
|
+
import { CteBodyCompiler } from './with-compiler.ts';
|
|
3
|
+
import { ExpressionCompiler } from './expression-compiler.ts';
|
|
4
|
+
import { ChunkBuilder, Chunks } from './sql-chunks.ts';
|
|
5
|
+
/** Compiles SELECT statements with their FROM, JOIN, WITH and locking clauses. */
|
|
6
|
+
export declare class QueryCompiler extends ChunkBuilder {
|
|
7
|
+
#private;
|
|
8
|
+
/** Expression compiler that compiles subqueries through this compiler. */
|
|
9
|
+
readonly expr: ExpressionCompiler;
|
|
10
|
+
constructor();
|
|
11
|
+
/**
|
|
12
|
+
* Compiles a SELECT statement.
|
|
13
|
+
*
|
|
14
|
+
* @param node - SELECT node.
|
|
15
|
+
* @returns Chunks.
|
|
16
|
+
*/
|
|
17
|
+
select(node: SelectNode): Chunks;
|
|
18
|
+
/**
|
|
19
|
+
* Compiles a query expression: a SELECT or a set operation.
|
|
20
|
+
*
|
|
21
|
+
* @param node - Query node.
|
|
22
|
+
* @returns Chunks.
|
|
23
|
+
*/
|
|
24
|
+
query(node: QueryNode): Chunks;
|
|
25
|
+
/**
|
|
26
|
+
* Sets the compiler of data-modifying CTE bodies (which live in the DML compiler).
|
|
27
|
+
*
|
|
28
|
+
* @param compile - Compiler of INSERT / UPDATE / DELETE statements.
|
|
29
|
+
*/
|
|
30
|
+
useModifying(compile: CteBodyCompiler): void;
|
|
31
|
+
/**
|
|
32
|
+
* One FROM source: a table or an aliased subquery.
|
|
33
|
+
*
|
|
34
|
+
* @param from - FROM source.
|
|
35
|
+
* @returns Chunks.
|
|
36
|
+
*/
|
|
37
|
+
from(from: FromItem): Chunks;
|
|
38
|
+
/**
|
|
39
|
+
* Comma-separated FROM sources.
|
|
40
|
+
*
|
|
41
|
+
* @param items - FROM sources.
|
|
42
|
+
* @returns Chunks.
|
|
43
|
+
*/
|
|
44
|
+
fromList(items: readonly FromItem[]): Chunks;
|
|
45
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { TableRef } from './ast.ts';
|
|
2
|
+
/** Bound value inside a chunk list; the same chunk object maps to the same `$n`. */
|
|
3
|
+
export type ParamChunk = Readonly<{
|
|
4
|
+
param: unknown;
|
|
5
|
+
}>;
|
|
6
|
+
/** SQL text or a bound value. */
|
|
7
|
+
export type Chunk = string | ParamChunk;
|
|
8
|
+
/** Chunk list rendered by `SqlCompiler.finalize`. */
|
|
9
|
+
export type Chunks = readonly Chunk[];
|
|
10
|
+
/** Shared chunk helpers of the SQL compilers: quoting, wrapping, joining and table references. */
|
|
11
|
+
export declare class ChunkBuilder {
|
|
12
|
+
/** Quotes an identifier: `"name"`, doubling embedded quotes. */
|
|
13
|
+
protected readonly quote: (name: string) => string;
|
|
14
|
+
/**
|
|
15
|
+
* Joins chunk lists with a separator.
|
|
16
|
+
*
|
|
17
|
+
* @param parts - Chunk lists.
|
|
18
|
+
* @param separator - SQL text between the lists.
|
|
19
|
+
* @returns Joined chunks.
|
|
20
|
+
*/
|
|
21
|
+
protected joinAll(parts: readonly Chunks[], separator: string): Chunks;
|
|
22
|
+
/**
|
|
23
|
+
* Wraps chunks in parentheses.
|
|
24
|
+
*
|
|
25
|
+
* @param chunks - Chunks.
|
|
26
|
+
* @returns `(chunks)`.
|
|
27
|
+
*/
|
|
28
|
+
protected wrap(chunks: Chunks): Chunks;
|
|
29
|
+
/**
|
|
30
|
+
* Parenthesized quoted column list.
|
|
31
|
+
*
|
|
32
|
+
* @param columns - Column names.
|
|
33
|
+
* @returns `("a", "b")`.
|
|
34
|
+
*/
|
|
35
|
+
protected columnList(columns: readonly string[]): Chunks;
|
|
36
|
+
/**
|
|
37
|
+
* Quoted table reference with an optional alias.
|
|
38
|
+
*
|
|
39
|
+
* @param table - Table reference.
|
|
40
|
+
* @returns `"schema"."name" AS "alias"`.
|
|
41
|
+
*/
|
|
42
|
+
protected tableRef(table: TableRef): Chunks;
|
|
43
|
+
/**
|
|
44
|
+
* Exhaustiveness guard of node switches.
|
|
45
|
+
*
|
|
46
|
+
* @param value - Unhandled node.
|
|
47
|
+
* @throws Error always.
|
|
48
|
+
*/
|
|
49
|
+
protected unexpected(value: never): never;
|
|
50
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ModifyingNode, QueryNode, WithClause } from './ast.ts';
|
|
2
|
+
import { ChunkBuilder, Chunks } from './sql-chunks.ts';
|
|
3
|
+
/** Compiles a CTE body: a query, or a data-modifying statement. */
|
|
4
|
+
export type CteBodyCompiler = (node: QueryNode | ModifyingNode) => Chunks;
|
|
5
|
+
/** Compiles `WITH [RECURSIVE]` clauses with `MATERIALIZED`, `SEARCH` and `CYCLE`. */
|
|
6
|
+
export declare class WithCompiler extends ChunkBuilder {
|
|
7
|
+
#private;
|
|
8
|
+
/**
|
|
9
|
+
* @param body - Compiler of CTE bodies.
|
|
10
|
+
*/
|
|
11
|
+
constructor(body: CteBodyCompiler);
|
|
12
|
+
/**
|
|
13
|
+
* Compiles a WITH clause.
|
|
14
|
+
*
|
|
15
|
+
* @param clause - WITH clause.
|
|
16
|
+
* @returns `WITH ... ` including the trailing space.
|
|
17
|
+
*/
|
|
18
|
+
with(clause: WithClause): Chunks;
|
|
19
|
+
}
|