@quereus/quereus 0.2.0 → 0.4.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/README.md +12 -1
- package/dist/src/common/errors.js.map +1 -1
- package/dist/src/common/json-types.d.ts +11 -0
- package/dist/src/common/json-types.d.ts.map +1 -0
- package/dist/src/common/json-types.js +3 -0
- package/dist/src/common/json-types.js.map +1 -0
- package/dist/src/common/types.d.ts +2 -0
- package/dist/src/common/types.d.ts.map +1 -1
- package/dist/src/core/database-options.d.ts +2 -2
- package/dist/src/core/database-options.d.ts.map +1 -1
- package/dist/src/core/database-options.js.map +1 -1
- package/dist/src/core/database.d.ts +61 -14
- package/dist/src/core/database.d.ts.map +1 -1
- package/dist/src/core/database.js +481 -54
- package/dist/src/core/database.js.map +1 -1
- package/dist/src/core/statement.d.ts.map +1 -1
- package/dist/src/core/statement.js +3 -1
- package/dist/src/core/statement.js.map +1 -1
- package/dist/src/func/builtins/builtin-window-functions.d.ts.map +1 -1
- package/dist/src/func/builtins/builtin-window-functions.js.map +1 -1
- package/dist/src/func/builtins/datetime.d.ts +2 -0
- package/dist/src/func/builtins/datetime.d.ts.map +1 -1
- package/dist/src/func/builtins/datetime.js +39 -0
- package/dist/src/func/builtins/datetime.js.map +1 -1
- package/dist/src/func/builtins/explain.d.ts +1 -0
- package/dist/src/func/builtins/explain.d.ts.map +1 -1
- package/dist/src/func/builtins/explain.js +159 -36
- package/dist/src/func/builtins/explain.js.map +1 -1
- package/dist/src/func/builtins/index.d.ts.map +1 -1
- package/dist/src/func/builtins/index.js +5 -2
- package/dist/src/func/builtins/index.js.map +1 -1
- package/dist/src/func/builtins/json-helpers.d.ts +8 -8
- package/dist/src/func/builtins/json-helpers.d.ts.map +1 -1
- package/dist/src/func/builtins/json-helpers.js +3 -3
- package/dist/src/func/builtins/json-helpers.js.map +1 -1
- package/dist/src/func/builtins/json-tvf.d.ts.map +1 -1
- package/dist/src/func/builtins/json-tvf.js +1 -1
- package/dist/src/func/builtins/json-tvf.js.map +1 -1
- package/dist/src/func/builtins/json.d.ts.map +1 -1
- package/dist/src/func/builtins/json.js +3 -2
- package/dist/src/func/builtins/json.js.map +1 -1
- package/dist/src/func/builtins/schema.d.ts.map +1 -1
- package/dist/src/func/builtins/schema.js +22 -1
- package/dist/src/func/builtins/schema.js.map +1 -1
- package/dist/src/func/context.d.ts.map +1 -1
- package/dist/src/func/context.js +5 -0
- package/dist/src/func/context.js.map +1 -1
- package/dist/src/func/registration.d.ts +2 -1
- package/dist/src/func/registration.d.ts.map +1 -1
- package/dist/src/func/registration.js.map +1 -1
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/parser/ast.d.ts +84 -6
- package/dist/src/parser/ast.d.ts.map +1 -1
- package/dist/src/parser/lexer.d.ts +11 -0
- package/dist/src/parser/lexer.d.ts.map +1 -1
- package/dist/src/parser/lexer.js +29 -21
- package/dist/src/parser/lexer.js.map +1 -1
- package/dist/src/parser/parser.d.ts +16 -0
- package/dist/src/parser/parser.d.ts.map +1 -1
- package/dist/src/parser/parser.js +542 -26
- package/dist/src/parser/parser.js.map +1 -1
- package/dist/src/parser/visitor.d.ts.map +1 -1
- package/dist/src/parser/visitor.js +1 -0
- package/dist/src/parser/visitor.js.map +1 -1
- package/dist/src/planner/analysis/binding-collector.d.ts +5 -0
- package/dist/src/planner/analysis/binding-collector.d.ts.map +1 -0
- package/dist/src/planner/analysis/binding-collector.js +73 -0
- package/dist/src/planner/analysis/binding-collector.js.map +1 -0
- package/dist/src/planner/analysis/const-evaluator.js +1 -1
- package/dist/src/planner/analysis/const-evaluator.js.map +1 -1
- package/dist/src/planner/analysis/const-pass.d.ts.map +1 -1
- package/dist/src/planner/analysis/const-pass.js +1 -1
- package/dist/src/planner/analysis/const-pass.js.map +1 -1
- package/dist/src/planner/analysis/constraint-extractor.d.ts +67 -31
- package/dist/src/planner/analysis/constraint-extractor.d.ts.map +1 -1
- package/dist/src/planner/analysis/constraint-extractor.js +513 -84
- package/dist/src/planner/analysis/constraint-extractor.js.map +1 -1
- package/dist/src/planner/analysis/predicate-normalizer.d.ts +17 -0
- package/dist/src/planner/analysis/predicate-normalizer.d.ts.map +1 -0
- package/dist/src/planner/analysis/predicate-normalizer.js +222 -0
- package/dist/src/planner/analysis/predicate-normalizer.js.map +1 -0
- package/dist/src/planner/building/alter-table.d.ts.map +1 -1
- package/dist/src/planner/building/alter-table.js +5 -2
- package/dist/src/planner/building/alter-table.js.map +1 -1
- package/dist/src/planner/building/block.d.ts.map +1 -1
- package/dist/src/planner/building/block.js +16 -0
- package/dist/src/planner/building/block.js.map +1 -1
- package/dist/src/planner/building/constraint-builder.d.ts +2 -2
- package/dist/src/planner/building/constraint-builder.d.ts.map +1 -1
- package/dist/src/planner/building/constraint-builder.js +52 -3
- package/dist/src/planner/building/constraint-builder.js.map +1 -1
- package/dist/src/planner/building/create-assertion.d.ts +5 -0
- package/dist/src/planner/building/create-assertion.d.ts.map +1 -0
- package/dist/src/planner/building/create-assertion.js +5 -0
- package/dist/src/planner/building/create-assertion.js.map +1 -0
- package/dist/src/planner/building/declare-schema.d.ts +8 -0
- package/dist/src/planner/building/declare-schema.d.ts.map +1 -0
- package/dist/src/planner/building/declare-schema.js +14 -0
- package/dist/src/planner/building/declare-schema.js.map +1 -0
- package/dist/src/planner/building/delete.d.ts.map +1 -1
- package/dist/src/planner/building/delete.js +38 -6
- package/dist/src/planner/building/delete.js.map +1 -1
- package/dist/src/planner/building/drop-assertion.d.ts +5 -0
- package/dist/src/planner/building/drop-assertion.d.ts.map +1 -0
- package/dist/src/planner/building/drop-assertion.js +8 -0
- package/dist/src/planner/building/drop-assertion.js.map +1 -0
- package/dist/src/planner/building/expression.d.ts.map +1 -1
- package/dist/src/planner/building/expression.js +1 -0
- package/dist/src/planner/building/expression.js.map +1 -1
- package/dist/src/planner/building/function-call.d.ts.map +1 -1
- package/dist/src/planner/building/function-call.js +2 -1
- package/dist/src/planner/building/function-call.js.map +1 -1
- package/dist/src/planner/building/insert.d.ts.map +1 -1
- package/dist/src/planner/building/insert.js +68 -11
- package/dist/src/planner/building/insert.js.map +1 -1
- package/dist/src/planner/building/pragma.d.ts.map +1 -1
- package/dist/src/planner/building/pragma.js +1 -0
- package/dist/src/planner/building/pragma.js.map +1 -1
- package/dist/src/planner/building/schema-resolution.d.ts +2 -2
- package/dist/src/planner/building/schema-resolution.d.ts.map +1 -1
- package/dist/src/planner/building/select-aggregates.d.ts.map +1 -1
- package/dist/src/planner/building/select-aggregates.js +3 -2
- package/dist/src/planner/building/select-aggregates.js.map +1 -1
- package/dist/src/planner/building/select-compound.d.ts +2 -2
- package/dist/src/planner/building/select-compound.d.ts.map +1 -1
- package/dist/src/planner/building/select-compound.js +10 -1
- package/dist/src/planner/building/select-compound.js.map +1 -1
- package/dist/src/planner/building/select-context.d.ts +3 -3
- package/dist/src/planner/building/select-context.d.ts.map +1 -1
- package/dist/src/planner/building/select-context.js.map +1 -1
- package/dist/src/planner/building/select-modifiers.d.ts +6 -5
- package/dist/src/planner/building/select-modifiers.d.ts.map +1 -1
- package/dist/src/planner/building/select-modifiers.js +5 -4
- package/dist/src/planner/building/select-modifiers.js.map +1 -1
- package/dist/src/planner/building/select-projections.d.ts.map +1 -1
- package/dist/src/planner/building/select-projections.js +4 -5
- package/dist/src/planner/building/select-projections.js.map +1 -1
- package/dist/src/planner/building/select-window.d.ts.map +1 -1
- package/dist/src/planner/building/select-window.js +6 -3
- package/dist/src/planner/building/select-window.js.map +1 -1
- package/dist/src/planner/building/select.d.ts +3 -3
- package/dist/src/planner/building/select.d.ts.map +1 -1
- package/dist/src/planner/building/select.js +18 -8
- package/dist/src/planner/building/select.js.map +1 -1
- package/dist/src/planner/building/table-function.d.ts.map +1 -1
- package/dist/src/planner/building/table-function.js +1 -1
- package/dist/src/planner/building/table-function.js.map +1 -1
- package/dist/src/planner/building/table.d.ts +5 -3
- package/dist/src/planner/building/table.d.ts.map +1 -1
- package/dist/src/planner/building/table.js +7 -2
- package/dist/src/planner/building/table.js.map +1 -1
- package/dist/src/planner/building/update.d.ts.map +1 -1
- package/dist/src/planner/building/update.js +39 -7
- package/dist/src/planner/building/update.js.map +1 -1
- package/dist/src/planner/building/with.d.ts +3 -3
- package/dist/src/planner/building/with.d.ts.map +1 -1
- package/dist/src/planner/building/with.js.map +1 -1
- package/dist/src/planner/debug.d.ts.map +1 -1
- package/dist/src/planner/debug.js.map +1 -1
- package/dist/src/planner/framework/characteristics.d.ts +235 -0
- package/dist/src/planner/framework/characteristics.d.ts.map +1 -0
- package/dist/src/planner/framework/characteristics.js +299 -0
- package/dist/src/planner/framework/characteristics.js.map +1 -0
- package/dist/src/planner/framework/context.d.ts +16 -5
- package/dist/src/planner/framework/context.d.ts.map +1 -1
- package/dist/src/planner/framework/context.js +2 -0
- package/dist/src/planner/framework/context.js.map +1 -1
- package/dist/src/planner/framework/pass.d.ts +116 -0
- package/dist/src/planner/framework/pass.d.ts.map +1 -0
- package/dist/src/planner/framework/pass.js +236 -0
- package/dist/src/planner/framework/pass.js.map +1 -0
- package/dist/src/planner/nodes/aggregate-node.d.ts +16 -6
- package/dist/src/planner/nodes/aggregate-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/aggregate-node.js +40 -4
- package/dist/src/planner/nodes/aggregate-node.js.map +1 -1
- package/dist/src/planner/nodes/array-index-node.js.map +1 -1
- package/dist/src/planner/nodes/cache-node.d.ts +5 -2
- package/dist/src/planner/nodes/cache-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/cache-node.js +6 -0
- package/dist/src/planner/nodes/cache-node.js.map +1 -1
- package/dist/src/planner/nodes/constraint-check-node.d.ts +12 -4
- package/dist/src/planner/nodes/constraint-check-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/constraint-check-node.js +12 -4
- package/dist/src/planner/nodes/constraint-check-node.js.map +1 -1
- package/dist/src/planner/nodes/create-assertion-node.d.ts +22 -0
- package/dist/src/planner/nodes/create-assertion-node.d.ts.map +1 -0
- package/dist/src/planner/nodes/create-assertion-node.js +41 -0
- package/dist/src/planner/nodes/create-assertion-node.js.map +1 -0
- package/dist/src/planner/nodes/create-index-node.js +2 -2
- package/dist/src/planner/nodes/create-index-node.js.map +1 -1
- package/dist/src/planner/nodes/create-table-node.js +2 -2
- package/dist/src/planner/nodes/create-table-node.js.map +1 -1
- package/dist/src/planner/nodes/cte-node.d.ts +17 -2
- package/dist/src/planner/nodes/cte-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/cte-node.js +9 -1
- package/dist/src/planner/nodes/cte-node.js.map +1 -1
- package/dist/src/planner/nodes/cte-reference-node.js +1 -1
- package/dist/src/planner/nodes/cte-reference-node.js.map +1 -1
- package/dist/src/planner/nodes/declarative-schema.d.ts +62 -0
- package/dist/src/planner/nodes/declarative-schema.d.ts.map +1 -0
- package/dist/src/planner/nodes/declarative-schema.js +181 -0
- package/dist/src/planner/nodes/declarative-schema.js.map +1 -0
- package/dist/src/planner/nodes/delete-node.d.ts +8 -3
- package/dist/src/planner/nodes/delete-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/delete-node.js +10 -2
- package/dist/src/planner/nodes/delete-node.js.map +1 -1
- package/dist/src/planner/nodes/distinct-node.d.ts +3 -2
- package/dist/src/planner/nodes/distinct-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/distinct-node.js +17 -4
- package/dist/src/planner/nodes/distinct-node.js.map +1 -1
- package/dist/src/planner/nodes/dml-executor-node.d.ts +2 -2
- package/dist/src/planner/nodes/dml-executor-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/drop-assertion-node.d.ts +21 -0
- package/dist/src/planner/nodes/drop-assertion-node.d.ts.map +1 -0
- package/dist/src/planner/nodes/drop-assertion-node.js +41 -0
- package/dist/src/planner/nodes/drop-assertion-node.js.map +1 -0
- package/dist/src/planner/nodes/drop-table-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/drop-table-node.js +1 -0
- package/dist/src/planner/nodes/drop-table-node.js.map +1 -1
- package/dist/src/planner/nodes/filter.d.ts +8 -3
- package/dist/src/planner/nodes/filter.d.ts.map +1 -1
- package/dist/src/planner/nodes/filter.js +44 -0
- package/dist/src/planner/nodes/filter.js.map +1 -1
- package/dist/src/planner/nodes/insert-node.d.ts +9 -3
- package/dist/src/planner/nodes/insert-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/insert-node.js +11 -2
- package/dist/src/planner/nodes/insert-node.js.map +1 -1
- package/dist/src/planner/nodes/internal-recursive-cte-ref-node.d.ts +3 -4
- package/dist/src/planner/nodes/internal-recursive-cte-ref-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/internal-recursive-cte-ref-node.js +1 -16
- package/dist/src/planner/nodes/internal-recursive-cte-ref-node.js.map +1 -1
- package/dist/src/planner/nodes/join-node.d.ts +12 -3
- package/dist/src/planner/nodes/join-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/join-node.js +111 -2
- package/dist/src/planner/nodes/join-node.js.map +1 -1
- package/dist/src/planner/nodes/limit-offset.d.ts +7 -3
- package/dist/src/planner/nodes/limit-offset.d.ts.map +1 -1
- package/dist/src/planner/nodes/limit-offset.js +15 -0
- package/dist/src/planner/nodes/limit-offset.js.map +1 -1
- package/dist/src/planner/nodes/plan-node-type.d.ts +8 -0
- package/dist/src/planner/nodes/plan-node-type.d.ts.map +1 -1
- package/dist/src/planner/nodes/plan-node-type.js +8 -0
- package/dist/src/planner/nodes/plan-node-type.js.map +1 -1
- package/dist/src/planner/nodes/plan-node.d.ts +9 -9
- package/dist/src/planner/nodes/plan-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/plan-node.js +3 -3
- package/dist/src/planner/nodes/plan-node.js.map +1 -1
- package/dist/src/planner/nodes/pragma.d.ts +2 -1
- package/dist/src/planner/nodes/pragma.d.ts.map +1 -1
- package/dist/src/planner/nodes/pragma.js +3 -1
- package/dist/src/planner/nodes/pragma.js.map +1 -1
- package/dist/src/planner/nodes/project-node.d.ts +16 -3
- package/dist/src/planner/nodes/project-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/project-node.js +82 -2
- package/dist/src/planner/nodes/project-node.js.map +1 -1
- package/dist/src/planner/nodes/recursive-cte-node.d.ts +2 -2
- package/dist/src/planner/nodes/recursive-cte-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/recursive-cte-node.js +1 -1
- package/dist/src/planner/nodes/recursive-cte-node.js.map +1 -1
- package/dist/src/planner/nodes/reference.d.ts +13 -4
- package/dist/src/planner/nodes/reference.d.ts.map +1 -1
- package/dist/src/planner/nodes/reference.js +16 -0
- package/dist/src/planner/nodes/reference.js.map +1 -1
- package/dist/src/planner/nodes/remote-query-node.d.ts +37 -0
- package/dist/src/planner/nodes/remote-query-node.d.ts.map +1 -0
- package/dist/src/planner/nodes/remote-query-node.js +63 -0
- package/dist/src/planner/nodes/remote-query-node.js.map +1 -0
- package/dist/src/planner/nodes/retrieve-node.d.ts +46 -0
- package/dist/src/planner/nodes/retrieve-node.d.ts.map +1 -0
- package/dist/src/planner/nodes/retrieve-node.js +77 -0
- package/dist/src/planner/nodes/retrieve-node.js.map +1 -0
- package/dist/src/planner/nodes/returning-node.d.ts +4 -3
- package/dist/src/planner/nodes/returning-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/returning-node.js +44 -3
- package/dist/src/planner/nodes/returning-node.js.map +1 -1
- package/dist/src/planner/nodes/sequencing-node.d.ts +1 -1
- package/dist/src/planner/nodes/sequencing-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/sequencing-node.js.map +1 -1
- package/dist/src/planner/nodes/set-operation-node.d.ts +1 -1
- package/dist/src/planner/nodes/set-operation-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/set-operation-node.js.map +1 -1
- package/dist/src/planner/nodes/sort.d.ts +11 -2
- package/dist/src/planner/nodes/sort.d.ts.map +1 -1
- package/dist/src/planner/nodes/sort.js +23 -2
- package/dist/src/planner/nodes/sort.js.map +1 -1
- package/dist/src/planner/nodes/stream-aggregate.d.ts.map +1 -1
- package/dist/src/planner/nodes/stream-aggregate.js +4 -1
- package/dist/src/planner/nodes/stream-aggregate.js.map +1 -1
- package/dist/src/planner/nodes/table-access-nodes.d.ts +7 -1
- package/dist/src/planner/nodes/table-access-nodes.d.ts.map +1 -1
- package/dist/src/planner/nodes/table-access-nodes.js +22 -4
- package/dist/src/planner/nodes/table-access-nodes.js.map +1 -1
- package/dist/src/planner/nodes/table-function-call.d.ts +2 -1
- package/dist/src/planner/nodes/table-function-call.d.ts.map +1 -1
- package/dist/src/planner/nodes/table-function-call.js +12 -5
- package/dist/src/planner/nodes/table-function-call.js.map +1 -1
- package/dist/src/planner/nodes/transaction-node.js +2 -2
- package/dist/src/planner/nodes/transaction-node.js.map +1 -1
- package/dist/src/planner/nodes/update-node.d.ts +7 -1
- package/dist/src/planner/nodes/update-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/update-node.js +11 -2
- package/dist/src/planner/nodes/update-node.js.map +1 -1
- package/dist/src/planner/nodes/view-reference-node.js.map +1 -1
- package/dist/src/planner/nodes/window-function.js.map +1 -1
- package/dist/src/planner/nodes/window-node.js.map +1 -1
- package/dist/src/planner/optimizer-tuning.d.ts +11 -0
- package/dist/src/planner/optimizer-tuning.d.ts.map +1 -1
- package/dist/src/planner/optimizer-tuning.js +6 -0
- package/dist/src/planner/optimizer-tuning.js.map +1 -1
- package/dist/src/planner/optimizer.d.ts +17 -3
- package/dist/src/planner/optimizer.d.ts.map +1 -1
- package/dist/src/planner/optimizer.js +159 -67
- package/dist/src/planner/optimizer.js.map +1 -1
- package/dist/src/planner/planning-context.d.ts +5 -3
- package/dist/src/planner/planning-context.d.ts.map +1 -1
- package/dist/src/planner/planning-context.js +2 -0
- package/dist/src/planner/planning-context.js.map +1 -1
- package/dist/src/planner/resolve.d.ts +3 -2
- package/dist/src/planner/resolve.d.ts.map +1 -1
- package/dist/src/planner/resolve.js +6 -5
- package/dist/src/planner/resolve.js.map +1 -1
- package/dist/src/planner/rules/access/rule-select-access-path.d.ts +8 -3
- package/dist/src/planner/rules/access/rule-select-access-path.d.ts.map +1 -1
- package/dist/src/planner/rules/access/rule-select-access-path.js +206 -47
- package/dist/src/planner/rules/access/rule-select-access-path.js.map +1 -1
- package/dist/src/planner/rules/aggregate/rule-aggregate-streaming.d.ts +10 -3
- package/dist/src/planner/rules/aggregate/rule-aggregate-streaming.d.ts.map +1 -1
- package/dist/src/planner/rules/aggregate/rule-aggregate-streaming.js +95 -87
- package/dist/src/planner/rules/aggregate/rule-aggregate-streaming.js.map +1 -1
- package/dist/src/planner/rules/cache/rule-cte-optimization.d.ts +8 -2
- package/dist/src/planner/rules/cache/rule-cte-optimization.d.ts.map +1 -1
- package/dist/src/planner/rules/cache/rule-cte-optimization.js +24 -13
- package/dist/src/planner/rules/cache/rule-cte-optimization.js.map +1 -1
- package/dist/src/planner/rules/cache/rule-materialization-advisory.d.ts +9 -2
- package/dist/src/planner/rules/cache/rule-materialization-advisory.d.ts.map +1 -1
- package/dist/src/planner/rules/cache/rule-materialization-advisory.js +14 -7
- package/dist/src/planner/rules/cache/rule-materialization-advisory.js.map +1 -1
- package/dist/src/planner/rules/cache/rule-mutating-subquery-cache.d.ts +9 -3
- package/dist/src/planner/rules/cache/rule-mutating-subquery-cache.d.ts.map +1 -1
- package/dist/src/planner/rules/cache/rule-mutating-subquery-cache.js +34 -37
- package/dist/src/planner/rules/cache/rule-mutating-subquery-cache.js.map +1 -1
- package/dist/src/planner/rules/join/rule-join-greedy-commute.d.ts +14 -0
- package/dist/src/planner/rules/join/rule-join-greedy-commute.d.ts.map +1 -0
- package/dist/src/planner/rules/join/rule-join-greedy-commute.js +33 -0
- package/dist/src/planner/rules/join/rule-join-greedy-commute.js.map +1 -0
- package/dist/src/planner/rules/join/rule-join-key-inference.d.ts +11 -0
- package/dist/src/planner/rules/join/rule-join-key-inference.d.ts.map +1 -0
- package/dist/src/planner/rules/join/rule-join-key-inference.js +32 -0
- package/dist/src/planner/rules/join/rule-join-key-inference.js.map +1 -0
- package/dist/src/planner/rules/join/rule-quickpick-enumeration.d.ts +4 -0
- package/dist/src/planner/rules/join/rule-quickpick-enumeration.d.ts.map +1 -0
- package/dist/src/planner/rules/join/rule-quickpick-enumeration.js +233 -0
- package/dist/src/planner/rules/join/rule-quickpick-enumeration.js.map +1 -0
- package/dist/src/planner/rules/predicate/rule-predicate-pushdown.d.ts +21 -0
- package/dist/src/planner/rules/predicate/rule-predicate-pushdown.d.ts.map +1 -0
- package/dist/src/planner/rules/predicate/rule-predicate-pushdown.js +125 -0
- package/dist/src/planner/rules/predicate/rule-predicate-pushdown.js.map +1 -0
- package/dist/src/planner/rules/retrieve/rule-grow-retrieve.d.ts +21 -0
- package/dist/src/planner/rules/retrieve/rule-grow-retrieve.d.ts.map +1 -0
- package/dist/src/planner/rules/retrieve/rule-grow-retrieve.js +261 -0
- package/dist/src/planner/rules/retrieve/rule-grow-retrieve.js.map +1 -0
- package/dist/src/planner/scopes/registered.d.ts +1 -0
- package/dist/src/planner/scopes/registered.d.ts.map +1 -1
- package/dist/src/planner/scopes/registered.js +7 -0
- package/dist/src/planner/scopes/registered.js.map +1 -1
- package/dist/src/planner/stats/index.d.ts +0 -17
- package/dist/src/planner/stats/index.d.ts.map +1 -1
- package/dist/src/planner/stats/index.js +0 -58
- package/dist/src/planner/stats/index.js.map +1 -1
- package/dist/src/planner/util/deferred-constraint.d.ts +14 -0
- package/dist/src/planner/util/deferred-constraint.d.ts.map +1 -0
- package/dist/src/planner/util/deferred-constraint.js +85 -0
- package/dist/src/planner/util/deferred-constraint.js.map +1 -0
- package/dist/src/planner/util/key-utils.d.ts +15 -0
- package/dist/src/planner/util/key-utils.d.ts.map +1 -0
- package/dist/src/planner/util/key-utils.js +43 -0
- package/dist/src/planner/util/key-utils.js.map +1 -0
- package/dist/src/planner/validation/plan-validator.d.ts.map +1 -1
- package/dist/src/planner/validation/plan-validator.js +1 -0
- package/dist/src/planner/validation/plan-validator.js.map +1 -1
- package/dist/src/runtime/deferred-constraint-queue.d.ts +33 -0
- package/dist/src/runtime/deferred-constraint-queue.d.ts.map +1 -0
- package/dist/src/runtime/deferred-constraint-queue.js +172 -0
- package/dist/src/runtime/deferred-constraint-queue.js.map +1 -0
- package/dist/src/runtime/emission-context.d.ts +9 -3
- package/dist/src/runtime/emission-context.d.ts.map +1 -1
- package/dist/src/runtime/emission-context.js +5 -1
- package/dist/src/runtime/emission-context.js.map +1 -1
- package/dist/src/runtime/emit/add-constraint.d.ts.map +1 -1
- package/dist/src/runtime/emit/add-constraint.js +22 -4
- package/dist/src/runtime/emit/add-constraint.js.map +1 -1
- package/dist/src/runtime/emit/aggregate.d.ts.map +1 -1
- package/dist/src/runtime/emit/aggregate.js +3 -2
- package/dist/src/runtime/emit/aggregate.js.map +1 -1
- package/dist/src/runtime/emit/array-index.js.map +1 -1
- package/dist/src/runtime/emit/binary.d.ts.map +1 -1
- package/dist/src/runtime/emit/binary.js +9 -2
- package/dist/src/runtime/emit/binary.js.map +1 -1
- package/dist/src/runtime/emit/cache.d.ts.map +1 -1
- package/dist/src/runtime/emit/cache.js +1 -1
- package/dist/src/runtime/emit/cache.js.map +1 -1
- package/dist/src/runtime/emit/cast.d.ts.map +1 -1
- package/dist/src/runtime/emit/cast.js.map +1 -1
- package/dist/src/runtime/emit/constraint-check.d.ts.map +1 -1
- package/dist/src/runtime/emit/constraint-check.js +112 -25
- package/dist/src/runtime/emit/constraint-check.js.map +1 -1
- package/dist/src/runtime/emit/create-assertion.d.ts +5 -0
- package/dist/src/runtime/emit/create-assertion.d.ts.map +1 -0
- package/dist/src/runtime/emit/create-assertion.js +70 -0
- package/dist/src/runtime/emit/create-assertion.js.map +1 -0
- package/dist/src/runtime/emit/cte-reference.d.ts.map +1 -1
- package/dist/src/runtime/emit/cte-reference.js.map +1 -1
- package/dist/src/runtime/emit/cte.d.ts.map +1 -1
- package/dist/src/runtime/emit/cte.js.map +1 -1
- package/dist/src/runtime/emit/distinct.d.ts.map +1 -1
- package/dist/src/runtime/emit/distinct.js.map +1 -1
- package/dist/src/runtime/emit/dml-executor.d.ts.map +1 -1
- package/dist/src/runtime/emit/dml-executor.js +17 -9
- package/dist/src/runtime/emit/dml-executor.js.map +1 -1
- package/dist/src/runtime/emit/drop-assertion.d.ts +5 -0
- package/dist/src/runtime/emit/drop-assertion.d.ts.map +1 -0
- package/dist/src/runtime/emit/drop-assertion.js +30 -0
- package/dist/src/runtime/emit/drop-assertion.js.map +1 -0
- package/dist/src/runtime/emit/filter.d.ts.map +1 -1
- package/dist/src/runtime/emit/filter.js.map +1 -1
- package/dist/src/runtime/emit/join.d.ts.map +1 -1
- package/dist/src/runtime/emit/join.js.map +1 -1
- package/dist/src/runtime/emit/limit-offset.d.ts.map +1 -1
- package/dist/src/runtime/emit/limit-offset.js.map +1 -1
- package/dist/src/runtime/emit/pragma.js.map +1 -1
- package/dist/src/runtime/emit/project.d.ts.map +1 -1
- package/dist/src/runtime/emit/project.js.map +1 -1
- package/dist/src/runtime/emit/recursive-cte.d.ts.map +1 -1
- package/dist/src/runtime/emit/recursive-cte.js +1 -1
- package/dist/src/runtime/emit/recursive-cte.js.map +1 -1
- package/dist/src/runtime/emit/remote-query.d.ts +9 -0
- package/dist/src/runtime/emit/remote-query.d.ts.map +1 -0
- package/dist/src/runtime/emit/remote-query.js +30 -0
- package/dist/src/runtime/emit/remote-query.js.map +1 -0
- package/dist/src/runtime/emit/retrieve.d.ts +5 -0
- package/dist/src/runtime/emit/retrieve.d.ts.map +1 -0
- package/dist/src/runtime/emit/retrieve.js +9 -0
- package/dist/src/runtime/emit/retrieve.js.map +1 -0
- package/dist/src/runtime/emit/returning.d.ts.map +1 -1
- package/dist/src/runtime/emit/returning.js +1 -1
- package/dist/src/runtime/emit/returning.js.map +1 -1
- package/dist/src/runtime/emit/scalar-function.d.ts.map +1 -1
- package/dist/src/runtime/emit/scalar-function.js.map +1 -1
- package/dist/src/runtime/emit/scan.d.ts.map +1 -1
- package/dist/src/runtime/emit/scan.js +20 -5
- package/dist/src/runtime/emit/scan.js.map +1 -1
- package/dist/src/runtime/emit/schema-declarative.d.ts +8 -0
- package/dist/src/runtime/emit/schema-declarative.d.ts.map +1 -0
- package/dist/src/runtime/emit/schema-declarative.js +163 -0
- package/dist/src/runtime/emit/schema-declarative.js.map +1 -0
- package/dist/src/runtime/emit/sequencing.d.ts.map +1 -1
- package/dist/src/runtime/emit/sequencing.js.map +1 -1
- package/dist/src/runtime/emit/set-operation.d.ts.map +1 -1
- package/dist/src/runtime/emit/set-operation.js +6 -6
- package/dist/src/runtime/emit/set-operation.js.map +1 -1
- package/dist/src/runtime/emit/sort.d.ts.map +1 -1
- package/dist/src/runtime/emit/sort.js.map +1 -1
- package/dist/src/runtime/emit/subquery.d.ts +1 -1
- package/dist/src/runtime/emit/subquery.d.ts.map +1 -1
- package/dist/src/runtime/emit/subquery.js +6 -6
- package/dist/src/runtime/emit/subquery.js.map +1 -1
- package/dist/src/runtime/emit/transaction.d.ts.map +1 -1
- package/dist/src/runtime/emit/transaction.js +48 -8
- package/dist/src/runtime/emit/transaction.js.map +1 -1
- package/dist/src/runtime/emit/values.d.ts.map +1 -1
- package/dist/src/runtime/emit/values.js.map +1 -1
- package/dist/src/runtime/emit/window.d.ts.map +1 -1
- package/dist/src/runtime/emit/window.js.map +1 -1
- package/dist/src/runtime/emitters.d.ts.map +1 -1
- package/dist/src/runtime/emitters.js +1 -0
- package/dist/src/runtime/emitters.js.map +1 -1
- package/dist/src/runtime/register.d.ts.map +1 -1
- package/dist/src/runtime/register.js +16 -2
- package/dist/src/runtime/register.js.map +1 -1
- package/dist/src/runtime/scheduler.js.map +1 -1
- package/dist/src/runtime/types.d.ts +2 -2
- package/dist/src/runtime/types.d.ts.map +1 -1
- package/dist/src/runtime/types.js +4 -1
- package/dist/src/runtime/types.js.map +1 -1
- package/dist/src/runtime/utils.d.ts +2 -2
- package/dist/src/runtime/utils.d.ts.map +1 -1
- package/dist/src/runtime/utils.js +1 -0
- package/dist/src/runtime/utils.js.map +1 -1
- package/dist/src/schema/assertion.d.ts +19 -0
- package/dist/src/schema/assertion.d.ts.map +1 -0
- package/dist/src/schema/assertion.js +2 -0
- package/dist/src/schema/assertion.js.map +1 -0
- package/dist/src/schema/catalog.d.ts +44 -0
- package/dist/src/schema/catalog.d.ts.map +1 -0
- package/dist/src/schema/catalog.js +148 -0
- package/dist/src/schema/catalog.js.map +1 -0
- package/dist/src/schema/change-events.d.ts +2 -2
- package/dist/src/schema/change-events.d.ts.map +1 -1
- package/dist/src/schema/column.d.ts +2 -0
- package/dist/src/schema/column.d.ts.map +1 -1
- package/dist/src/schema/column.js.map +1 -1
- package/dist/src/schema/declared-schema-manager.d.ts +42 -0
- package/dist/src/schema/declared-schema-manager.d.ts.map +1 -0
- package/dist/src/schema/declared-schema-manager.js +71 -0
- package/dist/src/schema/declared-schema-manager.js.map +1 -0
- package/dist/src/schema/function.d.ts +3 -2
- package/dist/src/schema/function.d.ts.map +1 -1
- package/dist/src/schema/function.js.map +1 -1
- package/dist/src/schema/manager.d.ts +8 -3
- package/dist/src/schema/manager.d.ts.map +1 -1
- package/dist/src/schema/manager.js +32 -3
- package/dist/src/schema/manager.js.map +1 -1
- package/dist/src/schema/schema-differ.d.ts +34 -0
- package/dist/src/schema/schema-differ.d.ts.map +1 -0
- package/dist/src/schema/schema-differ.js +157 -0
- package/dist/src/schema/schema-differ.js.map +1 -0
- package/dist/src/schema/schema-hasher.d.ts +10 -0
- package/dist/src/schema/schema-hasher.d.ts.map +1 -0
- package/dist/src/schema/schema-hasher.js +39 -0
- package/dist/src/schema/schema-hasher.js.map +1 -0
- package/dist/src/schema/schema.d.ts +7 -0
- package/dist/src/schema/schema.d.ts.map +1 -1
- package/dist/src/schema/schema.js +19 -0
- package/dist/src/schema/schema.js.map +1 -1
- package/dist/src/schema/table.d.ts +31 -6
- package/dist/src/schema/table.d.ts.map +1 -1
- package/dist/src/schema/table.js +27 -12
- package/dist/src/schema/table.js.map +1 -1
- package/dist/src/schema/window-function.d.ts.map +1 -1
- package/dist/src/schema/window-function.js.map +1 -1
- package/dist/src/util/ast-stringify.d.ts.map +1 -1
- package/dist/src/util/ast-stringify.js +116 -3
- package/dist/src/util/ast-stringify.js.map +1 -1
- package/dist/src/util/environment.js.map +1 -1
- package/dist/src/util/plugin-loader.d.ts +25 -0
- package/dist/src/util/plugin-loader.d.ts.map +1 -1
- package/dist/src/util/plugin-loader.js +137 -0
- package/dist/src/util/plugin-loader.js.map +1 -1
- package/dist/src/util/row-descriptor.d.ts +1 -1
- package/dist/src/util/row-descriptor.d.ts.map +1 -1
- package/dist/src/util/row-descriptor.js.map +1 -1
- package/dist/src/util/serialization.d.ts +3 -0
- package/dist/src/util/serialization.d.ts.map +1 -1
- package/dist/src/util/serialization.js +1 -0
- package/dist/src/util/serialization.js.map +1 -1
- package/dist/src/vtab/best-access-plan.d.ts +1 -1
- package/dist/src/vtab/best-access-plan.d.ts.map +1 -1
- package/dist/src/vtab/best-access-plan.js +1 -0
- package/dist/src/vtab/best-access-plan.js.map +1 -1
- package/dist/src/vtab/manifest.d.ts.map +1 -1
- package/dist/src/vtab/memory/layer/base.d.ts.map +1 -1
- package/dist/src/vtab/memory/layer/base.js +2 -0
- package/dist/src/vtab/memory/layer/base.js.map +1 -1
- package/dist/src/vtab/memory/layer/manager.d.ts +2 -1
- package/dist/src/vtab/memory/layer/manager.d.ts.map +1 -1
- package/dist/src/vtab/memory/layer/manager.js +24 -6
- package/dist/src/vtab/memory/layer/manager.js.map +1 -1
- package/dist/src/vtab/memory/layer/safe-iterate.d.ts.map +1 -1
- package/dist/src/vtab/memory/layer/safe-iterate.js.map +1 -1
- package/dist/src/vtab/memory/module.d.ts.map +1 -1
- package/dist/src/vtab/memory/module.js +5 -0
- package/dist/src/vtab/memory/module.js.map +1 -1
- package/dist/src/vtab/memory/table.d.ts +2 -1
- package/dist/src/vtab/memory/table.d.ts.map +1 -1
- package/dist/src/vtab/memory/table.js +3 -2
- package/dist/src/vtab/memory/table.js.map +1 -1
- package/dist/src/vtab/memory/utils/logging.d.ts +2 -2
- package/dist/src/vtab/memory/utils/logging.d.ts.map +1 -1
- package/dist/src/vtab/memory/utils/logging.js +6 -3
- package/dist/src/vtab/memory/utils/logging.js.map +1 -1
- package/dist/src/vtab/module.d.ts +25 -0
- package/dist/src/vtab/module.d.ts.map +1 -1
- package/dist/src/vtab/table.d.ts +18 -5
- package/dist/src/vtab/table.d.ts.map +1 -1
- package/dist/src/vtab/table.js.map +1 -1
- package/package.json +5 -3
- package/src/common/errors.ts +1 -1
- package/src/common/json-types.ts +16 -0
- package/src/common/types.ts +3 -0
- package/src/core/database-options.ts +8 -8
- package/src/core/database.ts +537 -71
- package/src/core/statement.ts +3 -1
- package/src/func/builtins/builtin-window-functions.ts +11 -10
- package/src/func/builtins/datetime.ts +42 -0
- package/src/func/builtins/explain.ts +186 -44
- package/src/func/builtins/index.ts +5 -2
- package/src/func/builtins/json-helpers.ts +21 -21
- package/src/func/builtins/json-tvf.ts +8 -9
- package/src/func/builtins/json.ts +10 -9
- package/src/func/builtins/schema.ts +24 -4
- package/src/func/context.ts +7 -0
- package/src/func/registration.ts +5 -1
- package/src/index.ts +3 -3
- package/src/parser/ast.ts +582 -484
- package/src/parser/lexer.ts +27 -21
- package/src/parser/parser.ts +3336 -2776
- package/src/parser/visitor.ts +1 -0
- package/src/planner/analysis/binding-collector.ts +83 -0
- package/src/planner/analysis/const-evaluator.ts +1 -1
- package/src/planner/analysis/const-pass.ts +3 -2
- package/src/planner/analysis/constraint-extractor.ts +610 -123
- package/src/planner/analysis/predicate-normalizer.ts +237 -0
- package/src/planner/building/alter-table.ts +3 -1
- package/src/planner/building/block.ts +93 -78
- package/src/planner/building/constraint-builder.ts +173 -114
- package/src/planner/building/create-assertion.ts +7 -0
- package/src/planner/building/declare-schema.ts +22 -0
- package/src/planner/building/delete.ts +214 -171
- package/src/planner/building/drop-assertion.ts +11 -0
- package/src/planner/building/expression.ts +1 -0
- package/src/planner/building/function-call.ts +6 -5
- package/src/planner/building/insert.ts +428 -349
- package/src/planner/building/pragma.ts +1 -0
- package/src/planner/building/schema-resolution.ts +176 -176
- package/src/planner/building/select-aggregates.ts +5 -3
- package/src/planner/building/select-compound.ts +22 -13
- package/src/planner/building/select-context.ts +6 -6
- package/src/planner/building/select-modifiers.ts +8 -7
- package/src/planner/building/select-projections.ts +177 -176
- package/src/planner/building/select-window.ts +259 -253
- package/src/planner/building/select.ts +531 -520
- package/src/planner/building/table-function.ts +49 -48
- package/src/planner/building/table.ts +9 -3
- package/src/planner/building/update.ts +319 -270
- package/src/planner/building/with.ts +7 -7
- package/src/planner/debug.ts +1 -0
- package/src/planner/framework/characteristics.ts +503 -0
- package/src/planner/framework/context.ts +23 -6
- package/src/planner/framework/pass.ts +354 -0
- package/src/planner/nodes/aggregate-node.ts +52 -7
- package/src/planner/nodes/array-index-node.ts +1 -1
- package/src/planner/nodes/cache-node.ts +11 -2
- package/src/planner/nodes/constraint-check-node.ts +16 -7
- package/src/planner/nodes/create-assertion-node.ts +51 -0
- package/src/planner/nodes/create-index-node.ts +2 -2
- package/src/planner/nodes/create-table-node.ts +2 -2
- package/src/planner/nodes/cte-node.ts +30 -4
- package/src/planner/nodes/cte-reference-node.ts +2 -2
- package/src/planner/nodes/declarative-schema.ts +221 -0
- package/src/planner/nodes/delete-node.ts +102 -96
- package/src/planner/nodes/distinct-node.ts +20 -6
- package/src/planner/nodes/dml-executor-node.ts +2 -2
- package/src/planner/nodes/drop-assertion-node.ts +50 -0
- package/src/planner/nodes/drop-table-node.ts +1 -0
- package/src/planner/nodes/filter.ts +56 -3
- package/src/planner/nodes/insert-node.ts +126 -120
- package/src/planner/nodes/internal-recursive-cte-ref-node.ts +5 -20
- package/src/planner/nodes/join-node.ts +122 -4
- package/src/planner/nodes/limit-offset.ts +132 -113
- package/src/planner/nodes/plan-node-type.ts +95 -87
- package/src/planner/nodes/plan-node.ts +8 -8
- package/src/planner/nodes/pragma.ts +6 -3
- package/src/planner/nodes/project-node.ts +101 -7
- package/src/planner/nodes/recursive-cte-node.ts +6 -6
- package/src/planner/nodes/reference.ts +334 -312
- package/src/planner/nodes/remote-query-node.ts +73 -0
- package/src/planner/nodes/retrieve-node.ts +86 -0
- package/src/planner/nodes/returning-node.ts +52 -10
- package/src/planner/nodes/sequencing-node.ts +2 -2
- package/src/planner/nodes/set-operation-node.ts +3 -3
- package/src/planner/nodes/sort.ts +33 -4
- package/src/planner/nodes/stream-aggregate.ts +5 -1
- package/src/planner/nodes/table-access-nodes.ts +31 -6
- package/src/planner/nodes/table-function-call.ts +134 -127
- package/src/planner/nodes/transaction-node.ts +2 -2
- package/src/planner/nodes/update-node.ts +138 -132
- package/src/planner/nodes/view-reference-node.ts +1 -1
- package/src/planner/nodes/window-function.ts +2 -2
- package/src/planner/nodes/window-node.ts +1 -1
- package/src/planner/optimizer-tuning.ts +18 -0
- package/src/planner/optimizer.ts +171 -96
- package/src/planner/planning-context.ts +10 -3
- package/src/planner/resolve.ts +10 -9
- package/src/planner/rules/README.md +96 -96
- package/src/planner/rules/access/rule-select-access-path.ts +384 -184
- package/src/planner/rules/aggregate/rule-aggregate-streaming.ts +118 -104
- package/src/planner/rules/cache/rule-cte-optimization.ts +29 -16
- package/src/planner/rules/cache/rule-materialization-advisory.ts +14 -7
- package/src/planner/rules/cache/rule-mutating-subquery-cache.ts +38 -44
- package/src/planner/rules/join/rule-join-greedy-commute.ts +48 -0
- package/src/planner/rules/join/rule-join-key-inference.ts +35 -0
- package/src/planner/rules/join/rule-quickpick-enumeration.ts +267 -0
- package/src/planner/rules/predicate/rule-predicate-pushdown.ts +144 -0
- package/src/planner/rules/retrieve/rule-grow-retrieve.ts +337 -0
- package/src/planner/scopes/registered.ts +8 -0
- package/src/planner/stats/index.ts +0 -65
- package/src/planner/util/key-utils.ts +46 -0
- package/src/planner/validation/plan-validator.ts +5 -3
- package/src/runtime/deferred-constraint-queue.ts +196 -0
- package/src/runtime/emission-context.ts +11 -5
- package/src/runtime/emit/add-constraint.ts +26 -5
- package/src/runtime/emit/aggregate.ts +9 -7
- package/src/runtime/emit/array-index.ts +2 -2
- package/src/runtime/emit/binary.ts +26 -8
- package/src/runtime/emit/cache.ts +2 -2
- package/src/runtime/emit/cast.ts +2 -2
- package/src/runtime/emit/constraint-check.ts +150 -28
- package/src/runtime/emit/create-assertion.ts +82 -0
- package/src/runtime/emit/cte-reference.ts +2 -2
- package/src/runtime/emit/cte.ts +2 -2
- package/src/runtime/emit/distinct.ts +2 -2
- package/src/runtime/emit/dml-executor.ts +20 -12
- package/src/runtime/emit/drop-assertion.ts +45 -0
- package/src/runtime/emit/filter.ts +4 -4
- package/src/runtime/emit/join.ts +8 -7
- package/src/runtime/emit/limit-offset.ts +2 -2
- package/src/runtime/emit/pragma.ts +2 -2
- package/src/runtime/emit/project.ts +2 -2
- package/src/runtime/emit/recursive-cte.ts +2 -2
- package/src/runtime/emit/remote-query.ts +47 -0
- package/src/runtime/emit/retrieve.ts +15 -0
- package/src/runtime/emit/returning.ts +4 -4
- package/src/runtime/emit/scalar-function.ts +2 -2
- package/src/runtime/emit/scan.ts +29 -13
- package/src/runtime/emit/schema-declarative.ts +205 -0
- package/src/runtime/emit/sequencing.ts +3 -3
- package/src/runtime/emit/set-operation.ts +7 -7
- package/src/runtime/emit/sort.ts +2 -2
- package/src/runtime/emit/subquery.ts +10 -10
- package/src/runtime/emit/transaction.ts +46 -8
- package/src/runtime/emit/values.ts +2 -2
- package/src/runtime/emit/window.ts +3 -3
- package/src/runtime/emitters.ts +1 -0
- package/src/runtime/register.ts +150 -135
- package/src/runtime/scheduler.ts +2 -2
- package/src/runtime/types.ts +10 -7
- package/src/runtime/utils.ts +3 -2
- package/src/schema/assertion.ts +21 -0
- package/src/schema/catalog.ts +208 -0
- package/src/schema/change-events.ts +2 -2
- package/src/schema/column.ts +2 -0
- package/src/schema/declared-schema-manager.ts +82 -0
- package/src/schema/function.ts +5 -2
- package/src/schema/manager.ts +742 -709
- package/src/schema/schema-differ.ts +214 -0
- package/src/schema/schema-hasher.ts +44 -0
- package/src/schema/schema.ts +23 -0
- package/src/schema/table.ts +398 -364
- package/src/schema/window-function.ts +2 -0
- package/src/util/ast-stringify.ts +869 -764
- package/src/util/environment.ts +2 -2
- package/src/util/plugin-loader.ts +184 -0
- package/src/util/row-descriptor.ts +1 -1
- package/src/util/serialization.ts +2 -0
- package/src/vtab/best-access-plan.ts +2 -1
- package/src/vtab/manifest.ts +1 -0
- package/src/vtab/memory/index.ts +178 -178
- package/src/vtab/memory/layer/base.ts +275 -273
- package/src/vtab/memory/layer/interface.ts +47 -47
- package/src/vtab/memory/layer/manager.ts +33 -11
- package/src/vtab/memory/layer/safe-iterate.ts +3 -3
- package/src/vtab/memory/layer/transaction.ts +229 -229
- package/src/vtab/memory/module.ts +24 -18
- package/src/vtab/memory/table.ts +256 -253
- package/src/vtab/memory/utils/logging.ts +6 -3
- package/src/vtab/module.ts +170 -140
- package/src/vtab/table.ts +162 -143
|
@@ -34,6 +34,8 @@ export class Parser {
|
|
|
34
34
|
current = 0;
|
|
35
35
|
// Counter for positional parameters
|
|
36
36
|
parameterPosition = 1;
|
|
37
|
+
// Track opening parentheses for accurate error locations
|
|
38
|
+
parenStack = [];
|
|
37
39
|
/**
|
|
38
40
|
* Initialize the parser with tokens from a SQL string
|
|
39
41
|
* @param sql SQL string to parse
|
|
@@ -44,6 +46,7 @@ export class Parser {
|
|
|
44
46
|
this.tokens = lexer.scanTokens();
|
|
45
47
|
this.current = 0;
|
|
46
48
|
this.parameterPosition = 1; // Reset parameter counter
|
|
49
|
+
this.parenStack = [];
|
|
47
50
|
// Check for errors from lexer
|
|
48
51
|
const errorToken = this.tokens.find(t => t.type === TokenType.ERROR);
|
|
49
52
|
if (errorToken) {
|
|
@@ -85,6 +88,16 @@ export class Parser {
|
|
|
85
88
|
quereusError(`Parser error: ${e instanceof Error ? e.message : e}`, StatusCode.ERROR, e instanceof Error ? e : undefined);
|
|
86
89
|
}
|
|
87
90
|
}
|
|
91
|
+
// Report any unterminated parenthesis at EOF with pointer to opening location
|
|
92
|
+
if (this.parenStack.length > 0) {
|
|
93
|
+
const openToken = this.parenStack[this.parenStack.length - 1];
|
|
94
|
+
quereusError(`Unterminated '(' opened at line ${openToken.startLine}, column ${openToken.startColumn}. Expected ')' before end of input.`, StatusCode.ERROR, undefined, {
|
|
95
|
+
loc: {
|
|
96
|
+
start: { line: openToken.startLine, column: openToken.startColumn },
|
|
97
|
+
end: { line: this.peek().endLine, column: this.peek().endColumn },
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
}
|
|
88
101
|
// If we consumed all tokens and didn't parse any statements (e.g., empty input or only comments/whitespace),
|
|
89
102
|
// return an empty array instead of throwing an error.
|
|
90
103
|
return statements;
|
|
@@ -162,7 +175,7 @@ export class Parser {
|
|
|
162
175
|
if (!this.check(TokenType.RPAREN)) {
|
|
163
176
|
do {
|
|
164
177
|
columns.push(this.consumeIdentifier(['key', 'action', 'set', 'default', 'check', 'unique', 'like'], "Expected column name in CTE definition."));
|
|
165
|
-
} while (this.match(TokenType.COMMA));
|
|
178
|
+
} while (this.match(TokenType.COMMA) && !this.check(TokenType.RPAREN));
|
|
166
179
|
}
|
|
167
180
|
endToken = this.consume(TokenType.RPAREN, "Expected ')' after CTE column list.");
|
|
168
181
|
}
|
|
@@ -273,6 +286,22 @@ export class Parser {
|
|
|
273
286
|
this.advance();
|
|
274
287
|
stmt = this.pragmaStatement(startToken, withClause);
|
|
275
288
|
break;
|
|
289
|
+
case 'DECLARE':
|
|
290
|
+
this.advance();
|
|
291
|
+
stmt = this.declareSchemaStatement(startToken);
|
|
292
|
+
break;
|
|
293
|
+
case 'DIFF':
|
|
294
|
+
this.advance();
|
|
295
|
+
stmt = this.diffSchemaStatement(startToken);
|
|
296
|
+
break;
|
|
297
|
+
case 'APPLY':
|
|
298
|
+
this.advance();
|
|
299
|
+
stmt = this.applySchemaStatement(startToken);
|
|
300
|
+
break;
|
|
301
|
+
case 'EXPLAIN':
|
|
302
|
+
this.advance();
|
|
303
|
+
stmt = this.explainSchemaStatement(startToken);
|
|
304
|
+
break;
|
|
276
305
|
// --- Add default case ---
|
|
277
306
|
default:
|
|
278
307
|
// If it wasn't a recognized keyword starting the statement
|
|
@@ -280,6 +309,7 @@ export class Parser {
|
|
|
280
309
|
}
|
|
281
310
|
// Attach WITH clause if present and supported
|
|
282
311
|
if (withClause && this.statementSupportsWithClause(stmt)) {
|
|
312
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
283
313
|
stmt.withClause = withClause;
|
|
284
314
|
if (withClause.loc && stmt.loc) {
|
|
285
315
|
stmt.loc.start = withClause.loc.start;
|
|
@@ -312,6 +342,17 @@ export class Parser {
|
|
|
312
342
|
} while (this.match(TokenType.COMMA));
|
|
313
343
|
this.consume(TokenType.RPAREN, "Expected ')' after column list.");
|
|
314
344
|
}
|
|
345
|
+
// Parse mutation context assignments if present (after column list, before VALUES/SELECT)
|
|
346
|
+
let contextValues;
|
|
347
|
+
if (this.matchKeyword('WITH')) {
|
|
348
|
+
if (this.matchKeyword('CONTEXT')) {
|
|
349
|
+
contextValues = this.parseContextAssignments();
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
// Not a WITH CONTEXT clause, backtrack
|
|
353
|
+
this.current--;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
315
356
|
// Parse VALUES clause
|
|
316
357
|
let values;
|
|
317
358
|
let select;
|
|
@@ -356,6 +397,7 @@ export class Parser {
|
|
|
356
397
|
values,
|
|
357
398
|
select,
|
|
358
399
|
returning,
|
|
400
|
+
contextValues,
|
|
359
401
|
loc: _createLoc(startToken, lastConsumedToken),
|
|
360
402
|
};
|
|
361
403
|
}
|
|
@@ -409,7 +451,7 @@ export class Parser {
|
|
|
409
451
|
}
|
|
410
452
|
// Check for compound set operations (UNION / INTERSECT / EXCEPT) BEFORE ORDER BY/LIMIT
|
|
411
453
|
let compound;
|
|
412
|
-
if (this.match(TokenType.UNION, TokenType.INTERSECT, TokenType.EXCEPT)) {
|
|
454
|
+
if (this.match(TokenType.UNION, TokenType.INTERSECT, TokenType.EXCEPT, TokenType.DIFF)) {
|
|
413
455
|
const tok = this.previous();
|
|
414
456
|
let op;
|
|
415
457
|
if (tok.type === TokenType.UNION) {
|
|
@@ -423,9 +465,12 @@ export class Parser {
|
|
|
423
465
|
else if (tok.type === TokenType.INTERSECT) {
|
|
424
466
|
op = 'intersect';
|
|
425
467
|
}
|
|
426
|
-
else {
|
|
468
|
+
else if (tok.type === TokenType.EXCEPT) {
|
|
427
469
|
op = 'except';
|
|
428
470
|
}
|
|
471
|
+
else {
|
|
472
|
+
op = 'diff';
|
|
473
|
+
}
|
|
429
474
|
let rightSelect;
|
|
430
475
|
// Handle parenthesized subquery after set operation
|
|
431
476
|
if (this.match(TokenType.LPAREN)) {
|
|
@@ -574,7 +619,7 @@ export class Parser {
|
|
|
574
619
|
let schema;
|
|
575
620
|
let name;
|
|
576
621
|
let endToken = startToken;
|
|
577
|
-
const contextualKeywords = ['key', 'action', 'set', 'default', 'check', 'unique', 'references', 'on', 'cascade', 'restrict', 'like'];
|
|
622
|
+
const contextualKeywords = ['key', 'action', 'set', 'default', 'check', 'unique', 'references', 'on', 'cascade', 'restrict', 'like', 'temp', 'temporary'];
|
|
578
623
|
// Check for schema.table pattern
|
|
579
624
|
if (this.checkIdentifierLike(contextualKeywords) && this.checkNext(1, TokenType.DOT)) {
|
|
580
625
|
schema = this.consumeIdentifier(contextualKeywords, "Expected schema name.");
|
|
@@ -688,7 +733,7 @@ export class Parser {
|
|
|
688
733
|
if (!this.check(TokenType.RPAREN)) {
|
|
689
734
|
do {
|
|
690
735
|
columns.push(this.consumeIdentifier(contextualKeywords, "Expected column name in alias column list."));
|
|
691
|
-
} while (this.match(TokenType.COMMA));
|
|
736
|
+
} while (this.match(TokenType.COMMA) && !this.check(TokenType.RPAREN));
|
|
692
737
|
}
|
|
693
738
|
this.consume(TokenType.RPAREN, "Expected ')' after alias column list.");
|
|
694
739
|
}
|
|
@@ -754,7 +799,7 @@ export class Parser {
|
|
|
754
799
|
if (!this.check(TokenType.RPAREN)) {
|
|
755
800
|
do {
|
|
756
801
|
columns.push(this.consumeIdentifier(contextualKeywords, "Expected column name in alias column list."));
|
|
757
|
-
} while (this.match(TokenType.COMMA));
|
|
802
|
+
} while (this.match(TokenType.COMMA) && !this.check(TokenType.RPAREN));
|
|
758
803
|
}
|
|
759
804
|
this.consume(TokenType.RPAREN, "Expected ')' after alias column list.");
|
|
760
805
|
}
|
|
@@ -830,6 +875,7 @@ export class Parser {
|
|
|
830
875
|
endToken = this.consume(TokenType.RPAREN, "Expected ')' after table function arguments.");
|
|
831
876
|
// Parse optional alias (same logic as for standard tables)
|
|
832
877
|
let alias;
|
|
878
|
+
let columns;
|
|
833
879
|
if (this.match(TokenType.AS)) {
|
|
834
880
|
if (!this.checkIdentifierLike(contextualKeywords)) {
|
|
835
881
|
throw this.error(this.peek(), "Expected alias after 'AS'.");
|
|
@@ -847,11 +893,23 @@ export class Parser {
|
|
|
847
893
|
alias = aliasToken.lexeme;
|
|
848
894
|
endToken = aliasToken;
|
|
849
895
|
}
|
|
896
|
+
// Optional column list after alias: alias(col1, col2, ...)
|
|
897
|
+
if (alias && this.match(TokenType.LPAREN)) {
|
|
898
|
+
columns = [];
|
|
899
|
+
const colKeywords = ['key', 'action', 'set', 'default', 'check', 'unique', 'references', 'on', 'cascade', 'restrict', 'like'];
|
|
900
|
+
if (!this.check(TokenType.RPAREN)) {
|
|
901
|
+
do {
|
|
902
|
+
columns.push(this.consumeIdentifier(colKeywords, "Expected column name in alias column list."));
|
|
903
|
+
} while (this.match(TokenType.COMMA) && !this.check(TokenType.RPAREN));
|
|
904
|
+
}
|
|
905
|
+
endToken = this.consume(TokenType.RPAREN, "Expected ')' after alias column list.");
|
|
906
|
+
}
|
|
850
907
|
return {
|
|
851
908
|
type: 'functionSource',
|
|
852
909
|
name,
|
|
853
910
|
args,
|
|
854
911
|
alias,
|
|
912
|
+
columns,
|
|
855
913
|
loc: _createLoc(startToken, endToken),
|
|
856
914
|
};
|
|
857
915
|
}
|
|
@@ -882,6 +940,8 @@ export class Parser {
|
|
|
882
940
|
}
|
|
883
941
|
// Consume JOIN token
|
|
884
942
|
this.consume(TokenType.JOIN, "Expected 'JOIN'.");
|
|
943
|
+
// Optional LATERAL before right side
|
|
944
|
+
const _isLateral = this.match(TokenType.LATERAL);
|
|
885
945
|
// Parse right side of join
|
|
886
946
|
const right = this.tableSource(withClause);
|
|
887
947
|
// Parse join condition
|
|
@@ -1331,6 +1391,7 @@ export class Parser {
|
|
|
1331
1391
|
// Literals
|
|
1332
1392
|
if (this.match(TokenType.INTEGER, TokenType.FLOAT, TokenType.STRING, TokenType.NULL, TokenType.TRUE, TokenType.FALSE, TokenType.BLOB)) {
|
|
1333
1393
|
const token = this.previous();
|
|
1394
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1334
1395
|
let value;
|
|
1335
1396
|
let lexeme = undefined;
|
|
1336
1397
|
if (token.type === TokenType.NULL) {
|
|
@@ -1607,7 +1668,19 @@ export class Parser {
|
|
|
1607
1668
|
if (this.check(type)) {
|
|
1608
1669
|
return this.advance();
|
|
1609
1670
|
}
|
|
1610
|
-
|
|
1671
|
+
// If a ')' was expected, point back to the matching '('
|
|
1672
|
+
if (type === TokenType.RPAREN && this.parenStack.length > 0) {
|
|
1673
|
+
const openToken = this.parenStack[this.parenStack.length - 1];
|
|
1674
|
+
const got = this.peek();
|
|
1675
|
+
quereusError(`${message} Unterminated '(' opened at line ${openToken.startLine}, column ${openToken.startColumn}. Got '${got.lexeme}'.`, StatusCode.ERROR, undefined, {
|
|
1676
|
+
loc: {
|
|
1677
|
+
start: { line: openToken.startLine, column: openToken.startColumn },
|
|
1678
|
+
end: { line: this.peek().endLine, column: this.peek().endColumn },
|
|
1679
|
+
},
|
|
1680
|
+
});
|
|
1681
|
+
}
|
|
1682
|
+
const got = this.peek();
|
|
1683
|
+
this.error(got, `${message} Got '${got.lexeme}'.`);
|
|
1611
1684
|
}
|
|
1612
1685
|
check(type) {
|
|
1613
1686
|
if (this.isAtEnd())
|
|
@@ -1622,7 +1695,20 @@ export class Parser {
|
|
|
1622
1695
|
advance() {
|
|
1623
1696
|
if (!this.isAtEnd())
|
|
1624
1697
|
this.current++;
|
|
1625
|
-
|
|
1698
|
+
const tok = this.previous();
|
|
1699
|
+
// Maintain parenthesis balance for precise diagnostics
|
|
1700
|
+
if (tok.type === TokenType.LPAREN) {
|
|
1701
|
+
this.parenStack.push(tok);
|
|
1702
|
+
}
|
|
1703
|
+
else if (tok.type === TokenType.RPAREN) {
|
|
1704
|
+
if (this.parenStack.length === 0) {
|
|
1705
|
+
quereusError(`Unmatched ')' at line ${tok.startLine}, column ${tok.startColumn}.`, StatusCode.ERROR, undefined, { loc: { start: { line: tok.startLine, column: tok.startColumn }, end: { line: tok.endLine, column: tok.endColumn } } });
|
|
1706
|
+
}
|
|
1707
|
+
else {
|
|
1708
|
+
this.parenStack.pop();
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
return tok;
|
|
1626
1712
|
}
|
|
1627
1713
|
isAtEnd() {
|
|
1628
1714
|
return this.peek().type === TokenType.EOF;
|
|
@@ -1634,7 +1720,18 @@ export class Parser {
|
|
|
1634
1720
|
return this.tokens[this.current - 1];
|
|
1635
1721
|
}
|
|
1636
1722
|
error(token, message) {
|
|
1637
|
-
|
|
1723
|
+
// If we see common starter tokens for a different clause where a separator/comma or keyword was expected,
|
|
1724
|
+
// enhance the message to hint at likely fixes instead of generic parenthesis errors.
|
|
1725
|
+
const nextLex = token.lexeme?.toUpperCase?.() || token.lexeme;
|
|
1726
|
+
const hintParts = [];
|
|
1727
|
+
if (this.peekKeyword('CONSTRAINT') || this.peekKeyword('PRIMARY') || this.peekKeyword('UNIQUE') || this.peekKeyword('CHECK') || this.peekKeyword('FOREIGN')) {
|
|
1728
|
+
hintParts.push("If you're in CREATE TABLE, you might be missing a comma between elements.");
|
|
1729
|
+
}
|
|
1730
|
+
if (nextLex === 'ON' && !this.peekKeyword('JOIN')) {
|
|
1731
|
+
hintParts.push("'ON' must follow a JOIN. Use WHERE for filters in subqueries.");
|
|
1732
|
+
}
|
|
1733
|
+
const fullMessage = hintParts.length > 0 ? `${message} ${hintParts.join(' ')}` : message;
|
|
1734
|
+
quereusError(fullMessage, StatusCode.ERROR, undefined, {
|
|
1638
1735
|
loc: {
|
|
1639
1736
|
start: {
|
|
1640
1737
|
line: token.startLine,
|
|
@@ -1663,7 +1760,7 @@ export class Parser {
|
|
|
1663
1760
|
token === TokenType.HAVING ||
|
|
1664
1761
|
token === TokenType.ORDER ||
|
|
1665
1762
|
token === TokenType.LIMIT ||
|
|
1666
|
-
token === TokenType.UNION ||
|
|
1763
|
+
token === TokenType.UNION || token === TokenType.DIFF || token === TokenType.INTERSECT || token === TokenType.EXCEPT ||
|
|
1667
1764
|
token === TokenType.SEMICOLON ||
|
|
1668
1765
|
token === TokenType.EOF;
|
|
1669
1766
|
}
|
|
@@ -1671,6 +1768,17 @@ export class Parser {
|
|
|
1671
1768
|
/** @internal */
|
|
1672
1769
|
updateStatement(startToken, _withClause) {
|
|
1673
1770
|
const table = this.tableIdentifier();
|
|
1771
|
+
// Parse mutation context assignments if present
|
|
1772
|
+
let contextValues;
|
|
1773
|
+
if (this.matchKeyword('WITH')) {
|
|
1774
|
+
if (this.matchKeyword('CONTEXT')) {
|
|
1775
|
+
contextValues = this.parseContextAssignments();
|
|
1776
|
+
}
|
|
1777
|
+
else {
|
|
1778
|
+
// Not a WITH CONTEXT clause, backtrack
|
|
1779
|
+
this.current--;
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1674
1782
|
this.consume(TokenType.SET, "Expected 'SET' after table name in UPDATE.");
|
|
1675
1783
|
const assignments = [];
|
|
1676
1784
|
do {
|
|
@@ -1689,12 +1797,23 @@ export class Parser {
|
|
|
1689
1797
|
returning = this.columnList();
|
|
1690
1798
|
}
|
|
1691
1799
|
const endToken = this.previous();
|
|
1692
|
-
return { type: 'update', table, assignments, where, returning, loc: _createLoc(startToken, endToken) };
|
|
1800
|
+
return { type: 'update', table, assignments, where, returning, contextValues, loc: _createLoc(startToken, endToken) };
|
|
1693
1801
|
}
|
|
1694
1802
|
/** @internal */
|
|
1695
1803
|
deleteStatement(startToken, _withClause) {
|
|
1696
1804
|
this.matchKeyword('FROM');
|
|
1697
1805
|
const table = this.tableIdentifier();
|
|
1806
|
+
// Parse mutation context assignments if present
|
|
1807
|
+
let contextValues;
|
|
1808
|
+
if (this.matchKeyword('WITH')) {
|
|
1809
|
+
if (this.matchKeyword('CONTEXT')) {
|
|
1810
|
+
contextValues = this.parseContextAssignments();
|
|
1811
|
+
}
|
|
1812
|
+
else {
|
|
1813
|
+
// Not a WITH CONTEXT clause, backtrack
|
|
1814
|
+
this.current--;
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1698
1817
|
let where;
|
|
1699
1818
|
if (this.match(TokenType.WHERE)) {
|
|
1700
1819
|
where = this.expression();
|
|
@@ -1705,7 +1824,7 @@ export class Parser {
|
|
|
1705
1824
|
returning = this.columnList();
|
|
1706
1825
|
}
|
|
1707
1826
|
const endToken = this.previous();
|
|
1708
|
-
return { type: 'delete', table, where, returning, loc: _createLoc(startToken, endToken) };
|
|
1827
|
+
return { type: 'delete', table, where, returning, contextValues, loc: _createLoc(startToken, endToken) };
|
|
1709
1828
|
}
|
|
1710
1829
|
/** @internal */
|
|
1711
1830
|
valuesStatement(startToken) {
|
|
@@ -1738,12 +1857,16 @@ export class Parser {
|
|
|
1738
1857
|
this.consumeKeyword('VIEW', "Expected 'VIEW' after CREATE.");
|
|
1739
1858
|
return this.createViewStatement(startToken, withClause);
|
|
1740
1859
|
}
|
|
1860
|
+
else if (this.peekKeyword('ASSERTION')) {
|
|
1861
|
+
this.consumeKeyword('ASSERTION', "Expected 'ASSERTION' after CREATE.");
|
|
1862
|
+
return this.createAssertionStatement(startToken, withClause);
|
|
1863
|
+
}
|
|
1741
1864
|
else if (this.peekKeyword('UNIQUE')) {
|
|
1742
1865
|
this.consumeKeyword('UNIQUE', "Expected 'UNIQUE' after CREATE.");
|
|
1743
1866
|
this.consumeKeyword('INDEX', "Expected 'INDEX' after CREATE UNIQUE.");
|
|
1744
1867
|
return this.createIndexStatement(startToken, true, withClause);
|
|
1745
1868
|
}
|
|
1746
|
-
throw this.error(this.peek(), "Expected TABLE, [UNIQUE] INDEX, VIEW, or VIRTUAL after CREATE.");
|
|
1869
|
+
throw this.error(this.peek(), "Expected TABLE, [UNIQUE] INDEX, VIEW, ASSERTION, or VIRTUAL after CREATE.");
|
|
1747
1870
|
}
|
|
1748
1871
|
/**
|
|
1749
1872
|
* Parse CREATE TABLE statement
|
|
@@ -1773,7 +1896,18 @@ export class Parser {
|
|
|
1773
1896
|
else {
|
|
1774
1897
|
columns.push(this.columnDefinition());
|
|
1775
1898
|
}
|
|
1776
|
-
|
|
1899
|
+
// Allow trailing comma before ')'
|
|
1900
|
+
} while (this.match(TokenType.COMMA) && !this.check(TokenType.RPAREN));
|
|
1901
|
+
// If we didn't see a comma and the next token looks like the start of another
|
|
1902
|
+
// column or table constraint, provide a clearer error about a missing comma.
|
|
1903
|
+
if (!this.check(TokenType.RPAREN)) {
|
|
1904
|
+
const contextualKeywords = ['key', 'action', 'set', 'default', 'check', 'unique', 'references', 'on', 'cascade', 'restrict', 'like'];
|
|
1905
|
+
const nextLooksLikeAnotherItem = this.peekKeyword('PRIMARY') || this.peekKeyword('UNIQUE') || this.peekKeyword('CHECK') || this.peekKeyword('FOREIGN') || this.peekKeyword('CONSTRAINT') || this.checkIdentifierLike(contextualKeywords);
|
|
1906
|
+
if (nextLooksLikeAnotherItem) {
|
|
1907
|
+
const next = this.peek();
|
|
1908
|
+
throw this.error(next, `Expected ',' between table elements. Did you forget a comma before '${next.lexeme}'?`);
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1777
1911
|
this.consume(TokenType.RPAREN, "Expected ')' after table definition.");
|
|
1778
1912
|
}
|
|
1779
1913
|
else if (this.matchKeyword('AS')) {
|
|
@@ -1787,15 +1921,27 @@ export class Parser {
|
|
|
1787
1921
|
const moduleArgs = {};
|
|
1788
1922
|
if (this.matchKeyword('USING')) {
|
|
1789
1923
|
moduleName = this.consumeIdentifier("Expected module name after 'USING'.");
|
|
1790
|
-
if (this.
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
}
|
|
1924
|
+
if (this.match(TokenType.LPAREN)) {
|
|
1925
|
+
if (!this.check(TokenType.RPAREN)) {
|
|
1926
|
+
do {
|
|
1927
|
+
const nameValue = this.nameValueItem('module argument');
|
|
1928
|
+
moduleArgs[nameValue.name] = nameValue.value && nameValue.value.type === 'literal'
|
|
1929
|
+
? getSyncLiteral(nameValue.value)
|
|
1930
|
+
: (nameValue.value && nameValue.value.type === 'identifier' ? nameValue.value.name : nameValue.name);
|
|
1931
|
+
} while (this.match(TokenType.COMMA));
|
|
1798
1932
|
}
|
|
1933
|
+
this.consume(TokenType.RPAREN, "Expected ')' after module arguments.");
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
// Parse mutation context definitions if present
|
|
1937
|
+
let contextDefinitions;
|
|
1938
|
+
if (this.matchKeyword('WITH')) {
|
|
1939
|
+
if (this.matchKeyword('CONTEXT')) {
|
|
1940
|
+
contextDefinitions = this.parseMutationContextDefinitions();
|
|
1941
|
+
}
|
|
1942
|
+
else {
|
|
1943
|
+
// Not a WITH CONTEXT clause, backtrack
|
|
1944
|
+
this.current--;
|
|
1799
1945
|
}
|
|
1800
1946
|
}
|
|
1801
1947
|
return {
|
|
@@ -1807,6 +1953,7 @@ export class Parser {
|
|
|
1807
1953
|
isTemporary,
|
|
1808
1954
|
moduleName,
|
|
1809
1955
|
moduleArgs,
|
|
1956
|
+
contextDefinitions,
|
|
1810
1957
|
loc: _createLoc(startToken, this.previous()),
|
|
1811
1958
|
};
|
|
1812
1959
|
}
|
|
@@ -1872,7 +2019,7 @@ export class Parser {
|
|
|
1872
2019
|
if (!this.check(TokenType.RPAREN)) {
|
|
1873
2020
|
do {
|
|
1874
2021
|
columns.push(this.consumeIdentifier(contextualKeywords, "Expected column name in view column list."));
|
|
1875
|
-
} while (this.match(TokenType.COMMA));
|
|
2022
|
+
} while (this.match(TokenType.COMMA) && !this.check(TokenType.RPAREN));
|
|
1876
2023
|
}
|
|
1877
2024
|
this.consume(TokenType.RPAREN, "Expected ')' after view column list.");
|
|
1878
2025
|
}
|
|
@@ -1889,6 +2036,23 @@ export class Parser {
|
|
|
1889
2036
|
loc: _createLoc(startToken, this.previous()),
|
|
1890
2037
|
};
|
|
1891
2038
|
}
|
|
2039
|
+
/**
|
|
2040
|
+
* Parse CREATE ASSERTION statement
|
|
2041
|
+
* @returns AST for CREATE ASSERTION
|
|
2042
|
+
*/
|
|
2043
|
+
createAssertionStatement(startToken, _withClause) {
|
|
2044
|
+
const name = this.consumeIdentifier("Expected assertion name.");
|
|
2045
|
+
this.consumeKeyword('CHECK', "Expected 'CHECK' after assertion name.");
|
|
2046
|
+
this.consume(TokenType.LPAREN, "Expected '(' after CHECK.");
|
|
2047
|
+
const check = this.expression();
|
|
2048
|
+
this.consume(TokenType.RPAREN, "Expected ')' after CHECK expression.");
|
|
2049
|
+
return {
|
|
2050
|
+
type: 'createAssertion',
|
|
2051
|
+
name,
|
|
2052
|
+
check,
|
|
2053
|
+
loc: _createLoc(startToken, this.previous()),
|
|
2054
|
+
};
|
|
2055
|
+
}
|
|
1892
2056
|
/**
|
|
1893
2057
|
* Parse DROP statement
|
|
1894
2058
|
* @returns AST for DROP statement
|
|
@@ -1907,8 +2071,12 @@ export class Parser {
|
|
|
1907
2071
|
this.consumeKeyword('INDEX', "Expected INDEX after DROP.");
|
|
1908
2072
|
objectType = 'index';
|
|
1909
2073
|
}
|
|
2074
|
+
else if (this.peekKeyword('ASSERTION')) {
|
|
2075
|
+
this.consumeKeyword('ASSERTION', "Expected ASSERTION after DROP.");
|
|
2076
|
+
objectType = 'assertion';
|
|
2077
|
+
}
|
|
1910
2078
|
else {
|
|
1911
|
-
throw this.error(this.peek(), "Expected TABLE, VIEW, or
|
|
2079
|
+
throw this.error(this.peek(), "Expected TABLE, VIEW, INDEX, or ASSERTION after DROP.");
|
|
1912
2080
|
}
|
|
1913
2081
|
let ifExists = false;
|
|
1914
2082
|
if (this.matchKeyword('IF')) {
|
|
@@ -2046,6 +2214,296 @@ export class Parser {
|
|
|
2046
2214
|
const nameValue = this.nameValueItem("pragma");
|
|
2047
2215
|
return { type: 'pragma', ...nameValue, loc: _createLoc(startToken, this.previous()) };
|
|
2048
2216
|
}
|
|
2217
|
+
// === Declarative schema parsing ===
|
|
2218
|
+
declareSchemaStatement(startToken) {
|
|
2219
|
+
this.consumeKeyword('SCHEMA', "Expected 'SCHEMA' after DECLARE.");
|
|
2220
|
+
const schemaName = this.consumeIdentifier(['temp', 'temporary'], "Expected schema name after DECLARE.");
|
|
2221
|
+
let version;
|
|
2222
|
+
let using;
|
|
2223
|
+
// Optional: version 'semver'
|
|
2224
|
+
// no-op
|
|
2225
|
+
if (this.matchKeyword('VERSION')) {
|
|
2226
|
+
const tok = this.consume(TokenType.STRING, "Expected version string after VERSION.");
|
|
2227
|
+
version = String(tok.literal);
|
|
2228
|
+
}
|
|
2229
|
+
// Optional: using ( default_vtab_module = 'memory', default_vtab_args = '[]' )
|
|
2230
|
+
if (this.match(TokenType.USING)) {
|
|
2231
|
+
this.consume(TokenType.LPAREN, "Expected '(' after USING.");
|
|
2232
|
+
using = {};
|
|
2233
|
+
if (!this.check(TokenType.RPAREN)) {
|
|
2234
|
+
do {
|
|
2235
|
+
const optName = this.consumeIdentifier("Expected option name inside USING().").toLowerCase();
|
|
2236
|
+
this.consume(TokenType.EQUAL, "Expected '=' after option name in USING().");
|
|
2237
|
+
if (optName === 'default_vtab_module') {
|
|
2238
|
+
const t = this.consume(TokenType.STRING, "Expected string for default_vtab_module.");
|
|
2239
|
+
using.defaultVtabModule = String(t.literal);
|
|
2240
|
+
}
|
|
2241
|
+
else if (optName === 'default_vtab_args') {
|
|
2242
|
+
const t = this.consume(TokenType.STRING, "Expected JSON string for default_vtab_args.");
|
|
2243
|
+
using.defaultVtabArgs = String(t.literal);
|
|
2244
|
+
}
|
|
2245
|
+
else {
|
|
2246
|
+
// Consume simple literal/identifier for forward compatibility
|
|
2247
|
+
if (this.check(TokenType.STRING) || this.check(TokenType.INTEGER) || this.check(TokenType.FLOAT) || this.check(TokenType.IDENTIFIER)) {
|
|
2248
|
+
this.advance();
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2251
|
+
} while (this.match(TokenType.COMMA));
|
|
2252
|
+
}
|
|
2253
|
+
this.consume(TokenType.RPAREN, "Expected ')' after USING options.");
|
|
2254
|
+
}
|
|
2255
|
+
// Block
|
|
2256
|
+
// Parse declaration block delimited by '{' '}'
|
|
2257
|
+
this.consume(TokenType.LBRACE, "Expected '{' to start schema declaration block.");
|
|
2258
|
+
const items = [];
|
|
2259
|
+
while (!this.check(TokenType.RBRACE)) {
|
|
2260
|
+
if (this.isAtEnd())
|
|
2261
|
+
break;
|
|
2262
|
+
// table ...
|
|
2263
|
+
if (this.peekKeyword('TABLE')) {
|
|
2264
|
+
this.advance();
|
|
2265
|
+
items.push(this.declareTableItem());
|
|
2266
|
+
}
|
|
2267
|
+
else if (this.peekKeyword('INDEX')) {
|
|
2268
|
+
this.advance();
|
|
2269
|
+
items.push(this.declareIndexItem());
|
|
2270
|
+
}
|
|
2271
|
+
else if (this.peekKeyword('VIEW')) {
|
|
2272
|
+
this.advance();
|
|
2273
|
+
items.push(this.declareViewItem());
|
|
2274
|
+
}
|
|
2275
|
+
else if (this.peekKeyword('SEED')) {
|
|
2276
|
+
this.advance();
|
|
2277
|
+
items.push(this.declareSeedItem());
|
|
2278
|
+
}
|
|
2279
|
+
else {
|
|
2280
|
+
// Fallback: ignore unrecognized item (domain, collation, import)
|
|
2281
|
+
const start = this.peek();
|
|
2282
|
+
// consume until semicolon
|
|
2283
|
+
while (!this.isAtEnd() && !this.check(TokenType.SEMICOLON) && !(this.check(TokenType.IDENTIFIER) && this.peek().lexeme === '}')) {
|
|
2284
|
+
this.advance();
|
|
2285
|
+
}
|
|
2286
|
+
const endTok = this.previous();
|
|
2287
|
+
items.push({ type: 'declareIgnored', kind: 'domain', text: this.sourceSlice(start.startOffset, endTok.endOffset) });
|
|
2288
|
+
}
|
|
2289
|
+
this.match(TokenType.SEMICOLON);
|
|
2290
|
+
}
|
|
2291
|
+
this.consume(TokenType.RBRACE, "Expected '}' to close schema declaration block.");
|
|
2292
|
+
const endTok = this.previous();
|
|
2293
|
+
return { type: 'declareSchema', schemaName, version, using, items, loc: _createLoc(startToken, endTok) };
|
|
2294
|
+
}
|
|
2295
|
+
declareTableItem() {
|
|
2296
|
+
const tableName = this.consumeIdentifier(['key', 'action', 'set', 'default', 'check', 'unique', 'references', 'on', 'cascade', 'restrict', 'like'], 'Expected table name in declaration.');
|
|
2297
|
+
let moduleName;
|
|
2298
|
+
let moduleArgs;
|
|
2299
|
+
const columns = [];
|
|
2300
|
+
const constraints = [];
|
|
2301
|
+
// Optional USING module
|
|
2302
|
+
if (this.match(TokenType.USING)) {
|
|
2303
|
+
if (this.check(TokenType.IDENTIFIER)) {
|
|
2304
|
+
moduleName = this.advance().lexeme;
|
|
2305
|
+
}
|
|
2306
|
+
if (this.match(TokenType.LPAREN)) {
|
|
2307
|
+
moduleArgs = {};
|
|
2308
|
+
if (!this.check(TokenType.RPAREN)) {
|
|
2309
|
+
do {
|
|
2310
|
+
const nv = this.nameValueItem('module argument');
|
|
2311
|
+
moduleArgs[nv.name] = nv.value && nv.value.type === 'literal' ? getSyncLiteral(nv.value) : (nv.value && nv.value.type === 'identifier' ? nv.value.name : null);
|
|
2312
|
+
} while (this.match(TokenType.COMMA));
|
|
2313
|
+
}
|
|
2314
|
+
this.consume(TokenType.RPAREN, "Expected ')' after module arguments.");
|
|
2315
|
+
}
|
|
2316
|
+
}
|
|
2317
|
+
// Column list can be in parens (...) or braces {...}
|
|
2318
|
+
const useBraces = this.check(TokenType.LBRACE);
|
|
2319
|
+
if (useBraces) {
|
|
2320
|
+
this.consume(TokenType.LBRACE, "Expected '{' before column definitions.");
|
|
2321
|
+
}
|
|
2322
|
+
else {
|
|
2323
|
+
this.consume(TokenType.LPAREN, "Expected '(' or '{' before column definitions.");
|
|
2324
|
+
}
|
|
2325
|
+
if (!this.check(useBraces ? TokenType.RBRACE : TokenType.RPAREN)) {
|
|
2326
|
+
do {
|
|
2327
|
+
// Distinguish table constraint vs column definition by lookahead for '(' or constraint keywords
|
|
2328
|
+
if (this.peekKeyword('CONSTRAINT') || this.peekKeyword('PRIMARY') || this.peekKeyword('UNIQUE') || this.peekKeyword('CHECK') || this.peekKeyword('FOREIGN')) {
|
|
2329
|
+
constraints.push(this.tableConstraint());
|
|
2330
|
+
}
|
|
2331
|
+
else {
|
|
2332
|
+
columns.push(this.columnDefinition());
|
|
2333
|
+
}
|
|
2334
|
+
} while (this.match(TokenType.COMMA) && !this.check(useBraces ? TokenType.RBRACE : TokenType.RPAREN));
|
|
2335
|
+
}
|
|
2336
|
+
if (useBraces) {
|
|
2337
|
+
this.consume(TokenType.RBRACE, "Expected '}' after table definition.");
|
|
2338
|
+
}
|
|
2339
|
+
else {
|
|
2340
|
+
this.consume(TokenType.RPAREN, "Expected ')' after table definition.");
|
|
2341
|
+
}
|
|
2342
|
+
// Build the CREATE TABLE AST node for this declared table
|
|
2343
|
+
const tableStmt = {
|
|
2344
|
+
type: 'createTable',
|
|
2345
|
+
table: { type: 'identifier', name: tableName },
|
|
2346
|
+
ifNotExists: false,
|
|
2347
|
+
columns,
|
|
2348
|
+
constraints,
|
|
2349
|
+
isTemporary: false,
|
|
2350
|
+
moduleName,
|
|
2351
|
+
moduleArgs
|
|
2352
|
+
};
|
|
2353
|
+
return { type: 'declaredTable', tableStmt };
|
|
2354
|
+
}
|
|
2355
|
+
declareIndexItem() {
|
|
2356
|
+
const indexName = this.consumeIdentifier('Expected index name.');
|
|
2357
|
+
this.consumeKeyword('ON', "Expected 'ON' after index name.");
|
|
2358
|
+
const tableName = this.consumeIdentifier('Expected table name after ON.');
|
|
2359
|
+
this.consume(TokenType.LPAREN, "Expected '(' before index columns.");
|
|
2360
|
+
const columns = this.indexedColumnList();
|
|
2361
|
+
this.consume(TokenType.RPAREN, "Expected ')' after index columns.");
|
|
2362
|
+
const indexStmt = {
|
|
2363
|
+
type: 'createIndex',
|
|
2364
|
+
index: { type: 'identifier', name: indexName },
|
|
2365
|
+
table: { type: 'identifier', name: tableName },
|
|
2366
|
+
ifNotExists: false,
|
|
2367
|
+
columns,
|
|
2368
|
+
isUnique: false
|
|
2369
|
+
};
|
|
2370
|
+
return { type: 'declaredIndex', indexStmt };
|
|
2371
|
+
}
|
|
2372
|
+
declareViewItem() {
|
|
2373
|
+
const viewName = this.consumeIdentifier('Expected view name.');
|
|
2374
|
+
let columns;
|
|
2375
|
+
if (this.match(TokenType.LPAREN)) {
|
|
2376
|
+
columns = this.identifierList();
|
|
2377
|
+
this.consume(TokenType.RPAREN, "Expected ')' after view columns.");
|
|
2378
|
+
}
|
|
2379
|
+
this.consumeKeyword('AS', "Expected AS before SELECT in view declaration.");
|
|
2380
|
+
const selTok = this.consume(TokenType.SELECT, "Expected SELECT after AS in view declaration.");
|
|
2381
|
+
const select = this.selectStatement(selTok);
|
|
2382
|
+
const viewStmt = {
|
|
2383
|
+
type: 'createView',
|
|
2384
|
+
view: { type: 'identifier', name: viewName },
|
|
2385
|
+
ifNotExists: false,
|
|
2386
|
+
columns,
|
|
2387
|
+
select,
|
|
2388
|
+
isTemporary: false
|
|
2389
|
+
};
|
|
2390
|
+
return { type: 'declaredView', viewStmt };
|
|
2391
|
+
}
|
|
2392
|
+
declareSeedItem() {
|
|
2393
|
+
// seed <table> ( (...), (...) ) or seed <table> values (col, ...) values (...), (...)
|
|
2394
|
+
const tableName = this.consumeIdentifier('Expected table name after SEED.');
|
|
2395
|
+
let columns;
|
|
2396
|
+
const rows = [];
|
|
2397
|
+
// Check for column list syntax: seed table (cols...) values (...)
|
|
2398
|
+
if (this.matchKeyword('VALUES')) {
|
|
2399
|
+
this.consume(TokenType.LPAREN, "Expected '(' before seed column list.");
|
|
2400
|
+
columns = this.identifierList();
|
|
2401
|
+
this.consume(TokenType.RPAREN, "Expected ')' after seed column list.");
|
|
2402
|
+
this.consumeKeyword('VALUES', "Expected VALUES to introduce seed rows.");
|
|
2403
|
+
}
|
|
2404
|
+
// Parse seed rows: ( (...), (...) )
|
|
2405
|
+
this.consume(TokenType.LPAREN, "Expected '(' before seed rows.");
|
|
2406
|
+
do {
|
|
2407
|
+
this.consume(TokenType.LPAREN, "Expected '(' before seed row values.");
|
|
2408
|
+
const rowValues = [];
|
|
2409
|
+
if (!this.check(TokenType.RPAREN)) {
|
|
2410
|
+
do {
|
|
2411
|
+
const expr = this.expression();
|
|
2412
|
+
// Evaluate literal expressions to SqlValue
|
|
2413
|
+
if (expr.type === 'literal') {
|
|
2414
|
+
rowValues.push(getSyncLiteral(expr));
|
|
2415
|
+
}
|
|
2416
|
+
else {
|
|
2417
|
+
throw this.error(this.peek(), "Seed data must contain only literal values.");
|
|
2418
|
+
}
|
|
2419
|
+
} while (this.match(TokenType.COMMA));
|
|
2420
|
+
}
|
|
2421
|
+
this.consume(TokenType.RPAREN, "Expected ')' after seed row values.");
|
|
2422
|
+
rows.push(rowValues);
|
|
2423
|
+
} while (this.match(TokenType.COMMA));
|
|
2424
|
+
this.consume(TokenType.RPAREN, "Expected ')' after seed rows.");
|
|
2425
|
+
return { type: 'declaredSeed', tableName, columns, seedData: rows };
|
|
2426
|
+
}
|
|
2427
|
+
diffSchemaStatement(startToken) {
|
|
2428
|
+
this.consumeKeyword('SCHEMA', "Expected SCHEMA after DIFF.");
|
|
2429
|
+
const schemaName = this.consumeIdentifier(['temp', 'temporary'], 'Expected schema name after DIFF SCHEMA.');
|
|
2430
|
+
return { type: 'diffSchema', schemaName, loc: _createLoc(startToken, this.previous()) };
|
|
2431
|
+
}
|
|
2432
|
+
applySchemaStatement(startToken) {
|
|
2433
|
+
this.consumeKeyword('SCHEMA', "Expected SCHEMA after APPLY.");
|
|
2434
|
+
const schemaName = this.consumeIdentifier(['temp', 'temporary'], 'Expected schema name after APPLY SCHEMA.');
|
|
2435
|
+
let toVersion;
|
|
2436
|
+
let withSeed = false;
|
|
2437
|
+
let options;
|
|
2438
|
+
if (this.matchKeyword('TO')) {
|
|
2439
|
+
this.consumeKeyword('VERSION', "Expected VERSION after TO.");
|
|
2440
|
+
const tok = this.consume(TokenType.STRING, "Expected version string after TO VERSION.");
|
|
2441
|
+
toVersion = String(tok.literal);
|
|
2442
|
+
}
|
|
2443
|
+
// Check for WITH SEED
|
|
2444
|
+
if (this.matchKeyword('WITH')) {
|
|
2445
|
+
this.consumeKeyword('SEED', "Expected SEED after WITH.");
|
|
2446
|
+
withSeed = true;
|
|
2447
|
+
}
|
|
2448
|
+
if (this.matchKeyword('OPTIONS')) {
|
|
2449
|
+
this.consume(TokenType.LPAREN, "Expected '(' after OPTIONS.");
|
|
2450
|
+
options = {};
|
|
2451
|
+
if (!this.check(TokenType.RPAREN)) {
|
|
2452
|
+
do {
|
|
2453
|
+
const key = this.consumeIdentifier('Expected option key.').toLowerCase();
|
|
2454
|
+
this.consume(TokenType.EQUAL, "Expected '=' after option key.");
|
|
2455
|
+
if (key === 'dry_run')
|
|
2456
|
+
options.dryRun = this.consumeBooleanLiteral();
|
|
2457
|
+
else if (key === 'validate_only')
|
|
2458
|
+
options.validateOnly = this.consumeBooleanLiteral();
|
|
2459
|
+
else if (key === 'allow_destructive')
|
|
2460
|
+
options.allowDestructive = this.consumeBooleanLiteral();
|
|
2461
|
+
else if (key === 'rename_policy') {
|
|
2462
|
+
const vtok = this.consume(TokenType.STRING, "Expected string for rename_policy.");
|
|
2463
|
+
options.renamePolicy = String(vtok.literal);
|
|
2464
|
+
}
|
|
2465
|
+
else {
|
|
2466
|
+
// consume literal
|
|
2467
|
+
if (this.check(TokenType.STRING) || this.check(TokenType.INTEGER) || this.check(TokenType.FLOAT) || this.check(TokenType.IDENTIFIER))
|
|
2468
|
+
this.advance();
|
|
2469
|
+
}
|
|
2470
|
+
} while (this.match(TokenType.COMMA));
|
|
2471
|
+
}
|
|
2472
|
+
this.consume(TokenType.RPAREN, "Expected ')' after OPTIONS.");
|
|
2473
|
+
}
|
|
2474
|
+
return { type: 'applySchema', schemaName, toVersion, withSeed, options, loc: _createLoc(startToken, this.previous()) };
|
|
2475
|
+
}
|
|
2476
|
+
explainSchemaStatement(startToken) {
|
|
2477
|
+
this.consumeKeyword('SCHEMA', "Expected SCHEMA after EXPLAIN.");
|
|
2478
|
+
const schemaName = this.consumeIdentifier(['temp', 'temporary'], 'Expected schema name after EXPLAIN SCHEMA.');
|
|
2479
|
+
let version;
|
|
2480
|
+
if (this.matchKeyword('VERSION')) {
|
|
2481
|
+
const tok = this.consume(TokenType.STRING, "Expected version string after VERSION.");
|
|
2482
|
+
version = String(tok.literal);
|
|
2483
|
+
}
|
|
2484
|
+
return { type: 'explainSchema', schemaName, version, loc: _createLoc(startToken, this.previous()) };
|
|
2485
|
+
}
|
|
2486
|
+
consumeBooleanLiteral() {
|
|
2487
|
+
if (this.match(TokenType.TRUE))
|
|
2488
|
+
return true;
|
|
2489
|
+
if (this.match(TokenType.FALSE))
|
|
2490
|
+
return false;
|
|
2491
|
+
if (this.check(TokenType.STRING)) {
|
|
2492
|
+
const t = this.advance();
|
|
2493
|
+
const v = String(t.literal).toLowerCase();
|
|
2494
|
+
return v === 'true' || v === '1';
|
|
2495
|
+
}
|
|
2496
|
+
if (this.check(TokenType.INTEGER)) {
|
|
2497
|
+
const t = this.advance();
|
|
2498
|
+
return Number(t.literal) !== 0;
|
|
2499
|
+
}
|
|
2500
|
+
return false;
|
|
2501
|
+
}
|
|
2502
|
+
sourceSlice(_start, _end) {
|
|
2503
|
+
// Lexer tokens include offsets; this.tokens array belongs to this parser, but we don't have direct source here.
|
|
2504
|
+
// Return an empty string as placeholder; canonicalization is future work.
|
|
2505
|
+
return '';
|
|
2506
|
+
}
|
|
2049
2507
|
nameValueItem(context) {
|
|
2050
2508
|
const name = this.consumeIdentifier(`Expected ${context} name.`);
|
|
2051
2509
|
let value;
|
|
@@ -2218,6 +2676,50 @@ export class Parser {
|
|
|
2218
2676
|
const constraints = this.columnConstraintList();
|
|
2219
2677
|
return { name, dataType, constraints };
|
|
2220
2678
|
}
|
|
2679
|
+
/** @internal Parses mutation context variable definitions: WITH CONTEXT (var type [NULL], ...) */
|
|
2680
|
+
parseMutationContextDefinitions() {
|
|
2681
|
+
this.consume(TokenType.LPAREN, "Expected '(' after WITH CONTEXT.");
|
|
2682
|
+
const contextVars = [];
|
|
2683
|
+
do {
|
|
2684
|
+
const name = this.consumeIdentifier("Expected context variable name.");
|
|
2685
|
+
let dataType;
|
|
2686
|
+
if (this.check(TokenType.IDENTIFIER)) {
|
|
2687
|
+
dataType = this.advance().lexeme;
|
|
2688
|
+
if (this.match(TokenType.LPAREN)) {
|
|
2689
|
+
dataType += '(';
|
|
2690
|
+
let parenLevel = 1;
|
|
2691
|
+
while (parenLevel > 0 && !this.isAtEnd()) {
|
|
2692
|
+
const token = this.peek();
|
|
2693
|
+
if (token.type === TokenType.LPAREN)
|
|
2694
|
+
parenLevel++;
|
|
2695
|
+
if (token.type === TokenType.RPAREN)
|
|
2696
|
+
parenLevel--;
|
|
2697
|
+
if (parenLevel > 0) {
|
|
2698
|
+
dataType += this.advance().lexeme;
|
|
2699
|
+
}
|
|
2700
|
+
}
|
|
2701
|
+
dataType += ')';
|
|
2702
|
+
this.consume(TokenType.RPAREN, "Expected ')' after type parameters.");
|
|
2703
|
+
}
|
|
2704
|
+
}
|
|
2705
|
+
// Check for NULL keyword (explicit nullable marker)
|
|
2706
|
+
const notNull = !this.match(TokenType.NULL);
|
|
2707
|
+
contextVars.push({ name, dataType, notNull });
|
|
2708
|
+
} while (this.match(TokenType.COMMA));
|
|
2709
|
+
this.consume(TokenType.RPAREN, "Expected ')' after mutation context definitions.");
|
|
2710
|
+
return contextVars;
|
|
2711
|
+
}
|
|
2712
|
+
/** @internal Parses mutation context assignments: WITH CONTEXT var = expr, ... */
|
|
2713
|
+
parseContextAssignments() {
|
|
2714
|
+
const assignments = [];
|
|
2715
|
+
do {
|
|
2716
|
+
const name = this.consumeIdentifier("Expected context variable name.");
|
|
2717
|
+
this.consume(TokenType.EQUAL, `Expected '=' after context variable '${name}'.`);
|
|
2718
|
+
const value = this.expression();
|
|
2719
|
+
assignments.push({ name, value });
|
|
2720
|
+
} while (this.match(TokenType.COMMA));
|
|
2721
|
+
return assignments;
|
|
2722
|
+
}
|
|
2221
2723
|
/** @internal Parses column constraints */
|
|
2222
2724
|
columnConstraintList() {
|
|
2223
2725
|
const constraints = [];
|
|
@@ -2293,7 +2795,14 @@ export class Parser {
|
|
|
2293
2795
|
this.consume(TokenType.LPAREN, "Expected '(' after CHECK.");
|
|
2294
2796
|
const expr = this.expression();
|
|
2295
2797
|
endToken = this.consume(TokenType.RPAREN, "Expected ')' after CHECK expression.");
|
|
2296
|
-
|
|
2798
|
+
// No DEFERRABLE syntax supported; deferral is auto-detected by the planner
|
|
2799
|
+
return {
|
|
2800
|
+
type: 'check',
|
|
2801
|
+
name,
|
|
2802
|
+
expr,
|
|
2803
|
+
operations,
|
|
2804
|
+
loc: _createLoc(startToken, endToken)
|
|
2805
|
+
};
|
|
2297
2806
|
}
|
|
2298
2807
|
else if (this.match(TokenType.DEFAULT)) {
|
|
2299
2808
|
const expr = this.expression();
|
|
@@ -2375,7 +2884,14 @@ export class Parser {
|
|
|
2375
2884
|
this.consume(TokenType.LPAREN, "Expected '(' after CHECK.");
|
|
2376
2885
|
const expr = this.expression();
|
|
2377
2886
|
endToken = this.consume(TokenType.RPAREN, "Expected ')' after CHECK expression.");
|
|
2378
|
-
|
|
2887
|
+
// No DEFERRABLE syntax supported; deferral is auto-detected by the planner
|
|
2888
|
+
return {
|
|
2889
|
+
type: 'check',
|
|
2890
|
+
name,
|
|
2891
|
+
expr,
|
|
2892
|
+
operations,
|
|
2893
|
+
loc: _createLoc(startToken, endToken)
|
|
2894
|
+
};
|
|
2379
2895
|
}
|
|
2380
2896
|
else if (this.match(TokenType.FOREIGN)) {
|
|
2381
2897
|
this.consume(TokenType.KEY, "Expected KEY after FOREIGN.");
|