@quereus/quereus 0.7.3 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/schema/manager.d.ts.map +1 -1
- package/dist/src/schema/manager.js +19 -18
- package/package.json +3 -3
- package/dist/src/common/constants.js.map +0 -1
- package/dist/src/common/datatype.js.map +0 -1
- package/dist/src/common/errors.js.map +0 -1
- package/dist/src/common/json-types.js.map +0 -1
- package/dist/src/common/logger.js.map +0 -1
- package/dist/src/common/type-inference.js.map +0 -1
- package/dist/src/common/types.js.map +0 -1
- package/dist/src/core/database-options.js.map +0 -1
- package/dist/src/core/database.js.map +0 -1
- package/dist/src/core/param.js.map +0 -1
- package/dist/src/core/statement.js.map +0 -1
- package/dist/src/func/builtins/aggregate.js.map +0 -1
- package/dist/src/func/builtins/builtin-window-functions.js.map +0 -1
- package/dist/src/func/builtins/conversion.js.map +0 -1
- package/dist/src/func/builtins/datetime.js.map +0 -1
- package/dist/src/func/builtins/explain.js.map +0 -1
- package/dist/src/func/builtins/generation.js.map +0 -1
- package/dist/src/func/builtins/index.js.map +0 -1
- package/dist/src/func/builtins/json-helpers.js.map +0 -1
- package/dist/src/func/builtins/json-tvf.js.map +0 -1
- package/dist/src/func/builtins/json.js.map +0 -1
- package/dist/src/func/builtins/scalar.js.map +0 -1
- package/dist/src/func/builtins/schema.js.map +0 -1
- package/dist/src/func/builtins/string.js.map +0 -1
- package/dist/src/func/builtins/timespan.js.map +0 -1
- package/dist/src/func/context.js.map +0 -1
- package/dist/src/func/registration.js.map +0 -1
- package/dist/src/index.js.map +0 -1
- package/dist/src/parser/ast.js.map +0 -1
- package/dist/src/parser/index.js.map +0 -1
- package/dist/src/parser/lexer.js.map +0 -1
- package/dist/src/parser/parser.js.map +0 -1
- package/dist/src/parser/utils.js.map +0 -1
- package/dist/src/parser/visitor.js.map +0 -1
- package/dist/src/planner/analysis/binding-collector.js.map +0 -1
- package/dist/src/planner/analysis/const-evaluator.js.map +0 -1
- package/dist/src/planner/analysis/const-pass.js.map +0 -1
- package/dist/src/planner/analysis/constraint-extractor.js.map +0 -1
- package/dist/src/planner/analysis/predicate-normalizer.js.map +0 -1
- package/dist/src/planner/building/alter-table.js.map +0 -1
- package/dist/src/planner/building/block.js.map +0 -1
- package/dist/src/planner/building/constraint-builder.js.map +0 -1
- package/dist/src/planner/building/create-assertion.js.map +0 -1
- package/dist/src/planner/building/create-view.js.map +0 -1
- package/dist/src/planner/building/ddl.js.map +0 -1
- package/dist/src/planner/building/declare-schema.js.map +0 -1
- package/dist/src/planner/building/delete.js.map +0 -1
- package/dist/src/planner/building/drop-assertion.js.map +0 -1
- package/dist/src/planner/building/drop-table.js.map +0 -1
- package/dist/src/planner/building/drop-view.js.map +0 -1
- package/dist/src/planner/building/expression.js.map +0 -1
- package/dist/src/planner/building/function-call.js.map +0 -1
- package/dist/src/planner/building/insert.js.map +0 -1
- package/dist/src/planner/building/pragma.js.map +0 -1
- package/dist/src/planner/building/schema-resolution.js.map +0 -1
- package/dist/src/planner/building/select-aggregates.js.map +0 -1
- package/dist/src/planner/building/select-compound.js.map +0 -1
- package/dist/src/planner/building/select-context.js.map +0 -1
- package/dist/src/planner/building/select-modifiers.js.map +0 -1
- package/dist/src/planner/building/select-projections.js.map +0 -1
- package/dist/src/planner/building/select-window.js.map +0 -1
- package/dist/src/planner/building/select.js.map +0 -1
- package/dist/src/planner/building/table-function.js.map +0 -1
- package/dist/src/planner/building/table.js.map +0 -1
- package/dist/src/planner/building/transaction.js.map +0 -1
- package/dist/src/planner/building/update.js.map +0 -1
- package/dist/src/planner/building/with.js.map +0 -1
- package/dist/src/planner/cache/correlation-detector.js.map +0 -1
- package/dist/src/planner/cache/materialization-advisory.js.map +0 -1
- package/dist/src/planner/cache/reference-graph.js.map +0 -1
- package/dist/src/planner/cost/index.js.map +0 -1
- package/dist/src/planner/debug/logger-utils.js.map +0 -1
- package/dist/src/planner/debug.js.map +0 -1
- package/dist/src/planner/framework/characteristics.js.map +0 -1
- package/dist/src/planner/framework/context.js.map +0 -1
- package/dist/src/planner/framework/pass.js.map +0 -1
- package/dist/src/planner/framework/physical-utils.js.map +0 -1
- package/dist/src/planner/framework/registry.js.map +0 -1
- package/dist/src/planner/framework/trace.js.map +0 -1
- package/dist/src/planner/nodes/add-constraint-node.js.map +0 -1
- package/dist/src/planner/nodes/aggregate-function.js.map +0 -1
- package/dist/src/planner/nodes/aggregate-node.js.map +0 -1
- package/dist/src/planner/nodes/array-index-node.js.map +0 -1
- package/dist/src/planner/nodes/block.js.map +0 -1
- package/dist/src/planner/nodes/cache-node.js.map +0 -1
- package/dist/src/planner/nodes/constraint-check-node.js.map +0 -1
- package/dist/src/planner/nodes/create-assertion-node.js.map +0 -1
- package/dist/src/planner/nodes/create-index-node.js.map +0 -1
- package/dist/src/planner/nodes/create-table-node.js.map +0 -1
- package/dist/src/planner/nodes/create-view-node.js.map +0 -1
- package/dist/src/planner/nodes/cte-node.js.map +0 -1
- package/dist/src/planner/nodes/cte-reference-node.js.map +0 -1
- package/dist/src/planner/nodes/declarative-schema.js.map +0 -1
- package/dist/src/planner/nodes/delete-node.js.map +0 -1
- package/dist/src/planner/nodes/distinct-node.js.map +0 -1
- package/dist/src/planner/nodes/dml-executor-node.js.map +0 -1
- package/dist/src/planner/nodes/drop-assertion-node.js.map +0 -1
- package/dist/src/planner/nodes/drop-table-node.js.map +0 -1
- package/dist/src/planner/nodes/drop-view-node.js.map +0 -1
- package/dist/src/planner/nodes/filter.js.map +0 -1
- package/dist/src/planner/nodes/function.js.map +0 -1
- package/dist/src/planner/nodes/insert-node.js.map +0 -1
- package/dist/src/planner/nodes/internal-recursive-cte-ref-node.js.map +0 -1
- package/dist/src/planner/nodes/join-node.js.map +0 -1
- package/dist/src/planner/nodes/limit-offset.js.map +0 -1
- package/dist/src/planner/nodes/plan-node-type.js.map +0 -1
- package/dist/src/planner/nodes/plan-node.js.map +0 -1
- package/dist/src/planner/nodes/pragma.js.map +0 -1
- package/dist/src/planner/nodes/project-node.js.map +0 -1
- package/dist/src/planner/nodes/recursive-cte-node.js.map +0 -1
- package/dist/src/planner/nodes/reference.js.map +0 -1
- package/dist/src/planner/nodes/remote-query-node.js.map +0 -1
- package/dist/src/planner/nodes/retrieve-node.js.map +0 -1
- package/dist/src/planner/nodes/returning-node.js.map +0 -1
- package/dist/src/planner/nodes/scalar.js.map +0 -1
- package/dist/src/planner/nodes/sequencing-node.js.map +0 -1
- package/dist/src/planner/nodes/set-operation-node.js.map +0 -1
- package/dist/src/planner/nodes/single-row.js.map +0 -1
- package/dist/src/planner/nodes/sink-node.js.map +0 -1
- package/dist/src/planner/nodes/sort.js.map +0 -1
- package/dist/src/planner/nodes/stream-aggregate.js.map +0 -1
- package/dist/src/planner/nodes/subquery.js.map +0 -1
- package/dist/src/planner/nodes/table-access-nodes.js.map +0 -1
- package/dist/src/planner/nodes/table-function-call.js.map +0 -1
- package/dist/src/planner/nodes/transaction-node.js.map +0 -1
- package/dist/src/planner/nodes/update-node.js.map +0 -1
- package/dist/src/planner/nodes/values-node.js.map +0 -1
- package/dist/src/planner/nodes/view-reference-node.js.map +0 -1
- package/dist/src/planner/nodes/window-function.js.map +0 -1
- package/dist/src/planner/nodes/window-node.js.map +0 -1
- package/dist/src/planner/optimizer-tuning.js.map +0 -1
- package/dist/src/planner/optimizer.js.map +0 -1
- package/dist/src/planner/planning-context.js.map +0 -1
- package/dist/src/planner/resolve.js.map +0 -1
- package/dist/src/planner/rules/access/rule-select-access-path.js.map +0 -1
- package/dist/src/planner/rules/aggregate/rule-aggregate-streaming.js.map +0 -1
- package/dist/src/planner/rules/cache/rule-cte-optimization.js.map +0 -1
- package/dist/src/planner/rules/cache/rule-materialization-advisory.js.map +0 -1
- package/dist/src/planner/rules/cache/rule-mutating-subquery-cache.js.map +0 -1
- package/dist/src/planner/rules/join/rule-join-greedy-commute.js.map +0 -1
- package/dist/src/planner/rules/join/rule-join-key-inference.js.map +0 -1
- package/dist/src/planner/rules/join/rule-quickpick-enumeration.js.map +0 -1
- package/dist/src/planner/rules/predicate/rule-predicate-pushdown.js.map +0 -1
- package/dist/src/planner/rules/retrieve/rule-grow-retrieve.js.map +0 -1
- package/dist/src/planner/scopes/aliased.js.map +0 -1
- package/dist/src/planner/scopes/base.js.map +0 -1
- package/dist/src/planner/scopes/empty.js.map +0 -1
- package/dist/src/planner/scopes/global.js.map +0 -1
- package/dist/src/planner/scopes/multi.js.map +0 -1
- package/dist/src/planner/scopes/param.js.map +0 -1
- package/dist/src/planner/scopes/registered.js.map +0 -1
- package/dist/src/planner/scopes/scope.js.map +0 -1
- package/dist/src/planner/stats/basic-estimates.js.map +0 -1
- package/dist/src/planner/stats/index.js.map +0 -1
- package/dist/src/planner/type-utils.js.map +0 -1
- package/dist/src/planner/util/key-utils.js.map +0 -1
- package/dist/src/planner/validation/determinism-validator.js.map +0 -1
- package/dist/src/planner/validation/plan-validator.js.map +0 -1
- package/dist/src/runtime/async-util.js.map +0 -1
- package/dist/src/runtime/cache/shared-cache.js.map +0 -1
- package/dist/src/runtime/context-helpers.js.map +0 -1
- package/dist/src/runtime/deferred-constraint-queue.js.map +0 -1
- package/dist/src/runtime/emission-context.js.map +0 -1
- package/dist/src/runtime/emit/add-constraint.js.map +0 -1
- package/dist/src/runtime/emit/aggregate.js.map +0 -1
- package/dist/src/runtime/emit/array-index.js.map +0 -1
- package/dist/src/runtime/emit/between.js.map +0 -1
- package/dist/src/runtime/emit/binary.js.map +0 -1
- package/dist/src/runtime/emit/block.js.map +0 -1
- package/dist/src/runtime/emit/cache.js.map +0 -1
- package/dist/src/runtime/emit/case.js.map +0 -1
- package/dist/src/runtime/emit/cast.js.map +0 -1
- package/dist/src/runtime/emit/collate.js.map +0 -1
- package/dist/src/runtime/emit/column-reference.js.map +0 -1
- package/dist/src/runtime/emit/constraint-check.js.map +0 -1
- package/dist/src/runtime/emit/create-assertion.js.map +0 -1
- package/dist/src/runtime/emit/create-index.js.map +0 -1
- package/dist/src/runtime/emit/create-table.js.map +0 -1
- package/dist/src/runtime/emit/create-view.js.map +0 -1
- package/dist/src/runtime/emit/cte-reference.js.map +0 -1
- package/dist/src/runtime/emit/cte.js.map +0 -1
- package/dist/src/runtime/emit/delete.js.map +0 -1
- package/dist/src/runtime/emit/distinct.js.map +0 -1
- package/dist/src/runtime/emit/dml-executor.js.map +0 -1
- package/dist/src/runtime/emit/drop-assertion.js.map +0 -1
- package/dist/src/runtime/emit/drop-table.js.map +0 -1
- package/dist/src/runtime/emit/drop-view.js.map +0 -1
- package/dist/src/runtime/emit/filter.js.map +0 -1
- package/dist/src/runtime/emit/insert.js.map +0 -1
- package/dist/src/runtime/emit/internal-recursive-cte-ref.js.map +0 -1
- package/dist/src/runtime/emit/join.js.map +0 -1
- package/dist/src/runtime/emit/limit-offset.js.map +0 -1
- package/dist/src/runtime/emit/literal.js.map +0 -1
- package/dist/src/runtime/emit/parameter.js.map +0 -1
- package/dist/src/runtime/emit/pragma.js.map +0 -1
- package/dist/src/runtime/emit/project.js.map +0 -1
- package/dist/src/runtime/emit/recursive-cte.js.map +0 -1
- package/dist/src/runtime/emit/remote-query.js.map +0 -1
- package/dist/src/runtime/emit/retrieve.js.map +0 -1
- package/dist/src/runtime/emit/returning.js.map +0 -1
- package/dist/src/runtime/emit/scalar-function.js.map +0 -1
- package/dist/src/runtime/emit/scan.js.map +0 -1
- package/dist/src/runtime/emit/schema-declarative.js.map +0 -1
- package/dist/src/runtime/emit/sequencing.js.map +0 -1
- package/dist/src/runtime/emit/set-operation.js.map +0 -1
- package/dist/src/runtime/emit/sink.js.map +0 -1
- package/dist/src/runtime/emit/sort.js.map +0 -1
- package/dist/src/runtime/emit/subquery.js.map +0 -1
- package/dist/src/runtime/emit/table-valued-function.js.map +0 -1
- package/dist/src/runtime/emit/temporal-arithmetic.js.map +0 -1
- package/dist/src/runtime/emit/transaction.js.map +0 -1
- package/dist/src/runtime/emit/unary.js.map +0 -1
- package/dist/src/runtime/emit/update.js.map +0 -1
- package/dist/src/runtime/emit/values.js.map +0 -1
- package/dist/src/runtime/emit/window-function.js.map +0 -1
- package/dist/src/runtime/emit/window.js.map +0 -1
- package/dist/src/runtime/emitters.js.map +0 -1
- package/dist/src/runtime/register.js.map +0 -1
- package/dist/src/runtime/scheduler.js.map +0 -1
- package/dist/src/runtime/types.js.map +0 -1
- package/dist/src/runtime/utils.js.map +0 -1
- package/dist/src/schema/assertion.js.map +0 -1
- package/dist/src/schema/catalog.js.map +0 -1
- package/dist/src/schema/change-events.js.map +0 -1
- package/dist/src/schema/column.js.map +0 -1
- package/dist/src/schema/declared-schema-manager.js.map +0 -1
- package/dist/src/schema/function.js.map +0 -1
- package/dist/src/schema/manager.js.map +0 -1
- package/dist/src/schema/schema-differ.js.map +0 -1
- package/dist/src/schema/schema-hasher.js.map +0 -1
- package/dist/src/schema/schema.js.map +0 -1
- package/dist/src/schema/table.js.map +0 -1
- package/dist/src/schema/view.js.map +0 -1
- package/dist/src/schema/window-function.js.map +0 -1
- package/dist/src/types/builtin-types.js.map +0 -1
- package/dist/src/types/index.js.map +0 -1
- package/dist/src/types/json-type.js.map +0 -1
- package/dist/src/types/logical-type.js.map +0 -1
- package/dist/src/types/plugin-interface.js.map +0 -1
- package/dist/src/types/registry.js.map +0 -1
- package/dist/src/types/temporal-types.js.map +0 -1
- package/dist/src/types/validation.js.map +0 -1
- package/dist/src/util/affinity.js.map +0 -1
- package/dist/src/util/ast-stringify.js.map +0 -1
- package/dist/src/util/cached.js.map +0 -1
- package/dist/src/util/coercion.js.map +0 -1
- package/dist/src/util/comparison.js.map +0 -1
- package/dist/src/util/environment.js.map +0 -1
- package/dist/src/util/hash.js.map +0 -1
- package/dist/src/util/latches.js.map +0 -1
- package/dist/src/util/mutation-statement.js.map +0 -1
- package/dist/src/util/patterns.js.map +0 -1
- package/dist/src/util/plan-formatter.js.map +0 -1
- package/dist/src/util/plugin-helper.js.map +0 -1
- package/dist/src/util/row-descriptor.js.map +0 -1
- package/dist/src/util/serialization.js.map +0 -1
- package/dist/src/util/sql-literal.js.map +0 -1
- package/dist/src/util/working-table-iterable.js.map +0 -1
- package/dist/src/vtab/best-access-plan.js.map +0 -1
- package/dist/src/vtab/connection.js.map +0 -1
- package/dist/src/vtab/filter-info.js.map +0 -1
- package/dist/src/vtab/index-info.js.map +0 -1
- package/dist/src/vtab/manifest.js.map +0 -1
- package/dist/src/vtab/memory/connection.js.map +0 -1
- package/dist/src/vtab/memory/index.js.map +0 -1
- package/dist/src/vtab/memory/layer/base-cursor.js.map +0 -1
- package/dist/src/vtab/memory/layer/base.js.map +0 -1
- package/dist/src/vtab/memory/layer/connection.js.map +0 -1
- package/dist/src/vtab/memory/layer/interface.js.map +0 -1
- package/dist/src/vtab/memory/layer/manager.js.map +0 -1
- package/dist/src/vtab/memory/layer/safe-iterate.js.map +0 -1
- package/dist/src/vtab/memory/layer/scan-plan.js.map +0 -1
- package/dist/src/vtab/memory/layer/transaction-cursor.js.map +0 -1
- package/dist/src/vtab/memory/layer/transaction.js.map +0 -1
- package/dist/src/vtab/memory/module.js.map +0 -1
- package/dist/src/vtab/memory/table.js.map +0 -1
- package/dist/src/vtab/memory/types.js.map +0 -1
- package/dist/src/vtab/memory/utils/logging.js.map +0 -1
- package/dist/src/vtab/memory/utils/primary-key.js.map +0 -1
- package/dist/src/vtab/module.js.map +0 -1
- package/dist/src/vtab/table.js.map +0 -1
- package/src/common/constants.ts +0 -60
- package/src/common/datatype.ts +0 -85
- package/src/common/errors.ts +0 -189
- package/src/common/json-types.ts +0 -16
- package/src/common/logger.ts +0 -97
- package/src/common/type-inference.ts +0 -39
- package/src/common/types.ts +0 -151
- package/src/core/database-options.ts +0 -258
- package/src/core/database.ts +0 -1461
- package/src/core/param.ts +0 -56
- package/src/core/statement.ts +0 -528
- package/src/func/builtins/aggregate.ts +0 -269
- package/src/func/builtins/builtin-window-functions.ts +0 -166
- package/src/func/builtins/conversion.ts +0 -226
- package/src/func/builtins/datetime.ts +0 -500
- package/src/func/builtins/explain.ts +0 -779
- package/src/func/builtins/generation.ts +0 -43
- package/src/func/builtins/index.ts +0 -167
- package/src/func/builtins/json-helpers.ts +0 -237
- package/src/func/builtins/json-tvf.ts +0 -224
- package/src/func/builtins/json.ts +0 -588
- package/src/func/builtins/scalar.ts +0 -423
- package/src/func/builtins/schema.ts +0 -213
- package/src/func/builtins/string.ts +0 -306
- package/src/func/builtins/timespan.ts +0 -179
- package/src/func/context.ts +0 -258
- package/src/func/registration.ts +0 -201
- package/src/index.ts +0 -172
- package/src/parser/ast.ts +0 -581
- package/src/parser/index.ts +0 -65
- package/src/parser/lexer.ts +0 -806
- package/src/parser/parser.ts +0 -3352
- package/src/parser/utils.ts +0 -10
- package/src/parser/visitor.ts +0 -188
- package/src/planner/analysis/README.md +0 -93
- package/src/planner/analysis/binding-collector.ts +0 -83
- package/src/planner/analysis/const-evaluator.ts +0 -63
- package/src/planner/analysis/const-pass.ts +0 -282
- package/src/planner/analysis/constraint-extractor.ts +0 -764
- package/src/planner/analysis/predicate-normalizer.ts +0 -237
- package/src/planner/building/alter-table.ts +0 -49
- package/src/planner/building/block.ts +0 -93
- package/src/planner/building/constraint-builder.ts +0 -178
- package/src/planner/building/create-assertion.ts +0 -7
- package/src/planner/building/create-view.ts +0 -29
- package/src/planner/building/ddl.ts +0 -24
- package/src/planner/building/declare-schema.ts +0 -22
- package/src/planner/building/delete.ts +0 -218
- package/src/planner/building/drop-assertion.ts +0 -11
- package/src/planner/building/drop-table.ts +0 -13
- package/src/planner/building/drop-view.ts +0 -19
- package/src/planner/building/expression.ts +0 -205
- package/src/planner/building/function-call.ts +0 -129
- package/src/planner/building/insert.ts +0 -435
- package/src/planner/building/pragma.ts +0 -34
- package/src/planner/building/schema-resolution.ts +0 -176
- package/src/planner/building/select-aggregates.ts +0 -318
- package/src/planner/building/select-compound.ts +0 -119
- package/src/planner/building/select-context.ts +0 -85
- package/src/planner/building/select-modifiers.ts +0 -236
- package/src/planner/building/select-projections.ts +0 -177
- package/src/planner/building/select-window.ts +0 -259
- package/src/planner/building/select.ts +0 -567
- package/src/planner/building/table-function.ts +0 -49
- package/src/planner/building/table.ts +0 -40
- package/src/planner/building/transaction.ts +0 -23
- package/src/planner/building/update.ts +0 -331
- package/src/planner/building/with.ts +0 -180
- package/src/planner/cache/correlation-detector.ts +0 -83
- package/src/planner/cache/materialization-advisory.ts +0 -265
- package/src/planner/cache/reference-graph.ts +0 -196
- package/src/planner/cost/index.ts +0 -169
- package/src/planner/debug/logger-utils.ts +0 -68
- package/src/planner/debug.ts +0 -480
- package/src/planner/framework/README.md +0 -132
- package/src/planner/framework/characteristics.ts +0 -503
- package/src/planner/framework/context.ts +0 -239
- package/src/planner/framework/pass.ts +0 -354
- package/src/planner/framework/physical-utils.ts +0 -210
- package/src/planner/framework/registry.ts +0 -261
- package/src/planner/framework/trace.ts +0 -259
- package/src/planner/nodes/add-constraint-node.ts +0 -62
- package/src/planner/nodes/aggregate-function.ts +0 -155
- package/src/planner/nodes/aggregate-node.ts +0 -267
- package/src/planner/nodes/array-index-node.ts +0 -50
- package/src/planner/nodes/block.ts +0 -80
- package/src/planner/nodes/cache-node.ts +0 -103
- package/src/planner/nodes/constraint-check-node.ts +0 -138
- package/src/planner/nodes/create-assertion-node.ts +0 -51
- package/src/planner/nodes/create-index-node.ts +0 -41
- package/src/planner/nodes/create-table-node.ts +0 -35
- package/src/planner/nodes/create-view-node.ts +0 -44
- package/src/planner/nodes/cte-node.ts +0 -168
- package/src/planner/nodes/cte-reference-node.ts +0 -125
- package/src/planner/nodes/declarative-schema.ts +0 -221
- package/src/planner/nodes/delete-node.ts +0 -102
- package/src/planner/nodes/distinct-node.ts +0 -107
- package/src/planner/nodes/dml-executor-node.ts +0 -104
- package/src/planner/nodes/drop-assertion-node.ts +0 -50
- package/src/planner/nodes/drop-table-node.ts +0 -36
- package/src/planner/nodes/drop-view-node.ts +0 -37
- package/src/planner/nodes/filter.ts +0 -144
- package/src/planner/nodes/function.ts +0 -98
- package/src/planner/nodes/insert-node.ts +0 -126
- package/src/planner/nodes/internal-recursive-cte-ref-node.ts +0 -61
- package/src/planner/nodes/join-node.ts +0 -336
- package/src/planner/nodes/limit-offset.ts +0 -144
- package/src/planner/nodes/plan-node-type.ts +0 -95
- package/src/planner/nodes/plan-node.ts +0 -503
- package/src/planner/nodes/pragma.ts +0 -98
- package/src/planner/nodes/project-node.ts +0 -337
- package/src/planner/nodes/recursive-cte-node.ts +0 -158
- package/src/planner/nodes/reference.ts +0 -334
- package/src/planner/nodes/remote-query-node.ts +0 -73
- package/src/planner/nodes/retrieve-node.ts +0 -86
- package/src/planner/nodes/returning-node.ts +0 -269
- package/src/planner/nodes/scalar.ts +0 -772
- package/src/planner/nodes/sequencing-node.ts +0 -113
- package/src/planner/nodes/set-operation-node.ts +0 -87
- package/src/planner/nodes/single-row.ts +0 -85
- package/src/planner/nodes/sink-node.ts +0 -61
- package/src/planner/nodes/sort.ts +0 -166
- package/src/planner/nodes/stream-aggregate.ts +0 -293
- package/src/planner/nodes/subquery.ts +0 -268
- package/src/planner/nodes/table-access-nodes.ts +0 -323
- package/src/planner/nodes/table-function-call.ts +0 -134
- package/src/planner/nodes/transaction-node.ts +0 -55
- package/src/planner/nodes/update-node.ts +0 -138
- package/src/planner/nodes/values-node.ts +0 -244
- package/src/planner/nodes/view-reference-node.ts +0 -97
- package/src/planner/nodes/window-function.ts +0 -73
- package/src/planner/nodes/window-node.ts +0 -199
- package/src/planner/optimizer-tuning.ts +0 -105
- package/src/planner/optimizer.ts +0 -332
- package/src/planner/planning-context.ts +0 -190
- package/src/planner/resolve.ts +0 -101
- package/src/planner/rules/README.md +0 -96
- package/src/planner/rules/access/rule-select-access-path.ts +0 -399
- package/src/planner/rules/aggregate/rule-aggregate-streaming.ts +0 -162
- package/src/planner/rules/cache/rule-cte-optimization.ts +0 -79
- package/src/planner/rules/cache/rule-materialization-advisory.ts +0 -77
- package/src/planner/rules/cache/rule-mutating-subquery-cache.ts +0 -104
- package/src/planner/rules/join/rule-join-greedy-commute.ts +0 -48
- package/src/planner/rules/join/rule-join-key-inference.ts +0 -35
- package/src/planner/rules/join/rule-quickpick-enumeration.ts +0 -267
- package/src/planner/rules/predicate/rule-predicate-pushdown.ts +0 -144
- package/src/planner/rules/retrieve/rule-grow-retrieve.ts +0 -337
- package/src/planner/scopes/aliased.ts +0 -50
- package/src/planner/scopes/base.ts +0 -10
- package/src/planner/scopes/empty.ts +0 -12
- package/src/planner/scopes/global.ts +0 -73
- package/src/planner/scopes/multi.ts +0 -40
- package/src/planner/scopes/param.ts +0 -95
- package/src/planner/scopes/registered.ts +0 -67
- package/src/planner/scopes/scope.ts +0 -16
- package/src/planner/stats/basic-estimates.ts +0 -107
- package/src/planner/stats/index.ts +0 -158
- package/src/planner/type-utils.ts +0 -87
- package/src/planner/util/key-utils.ts +0 -46
- package/src/planner/validation/determinism-validator.ts +0 -104
- package/src/planner/validation/plan-validator.ts +0 -335
- package/src/runtime/async-util.ts +0 -283
- package/src/runtime/cache/shared-cache.ts +0 -169
- package/src/runtime/context-helpers.ts +0 -191
- package/src/runtime/deferred-constraint-queue.ts +0 -196
- package/src/runtime/emission-context.ts +0 -319
- package/src/runtime/emit/add-constraint.ts +0 -78
- package/src/runtime/emit/aggregate.ts +0 -581
- package/src/runtime/emit/array-index.ts +0 -25
- package/src/runtime/emit/between.ts +0 -51
- package/src/runtime/emit/binary.ts +0 -357
- package/src/runtime/emit/block.ts +0 -23
- package/src/runtime/emit/cache.ts +0 -64
- package/src/runtime/emit/case.ts +0 -87
- package/src/runtime/emit/cast.ts +0 -151
- package/src/runtime/emit/collate.ts +0 -9
- package/src/runtime/emit/column-reference.ts +0 -17
- package/src/runtime/emit/constraint-check.ts +0 -290
- package/src/runtime/emit/create-assertion.ts +0 -82
- package/src/runtime/emit/create-index.ts +0 -15
- package/src/runtime/emit/create-table.ts +0 -15
- package/src/runtime/emit/create-view.ts +0 -52
- package/src/runtime/emit/cte-reference.ts +0 -38
- package/src/runtime/emit/cte.ts +0 -39
- package/src/runtime/emit/delete.ts +0 -24
- package/src/runtime/emit/distinct.ts +0 -40
- package/src/runtime/emit/dml-executor.ts +0 -198
- package/src/runtime/emit/drop-assertion.ts +0 -45
- package/src/runtime/emit/drop-table.ts +0 -27
- package/src/runtime/emit/drop-view.ts +0 -49
- package/src/runtime/emit/filter.ts +0 -30
- package/src/runtime/emit/insert.ts +0 -42
- package/src/runtime/emit/internal-recursive-cte-ref.ts +0 -37
- package/src/runtime/emit/join.ts +0 -148
- package/src/runtime/emit/limit-offset.ts +0 -73
- package/src/runtime/emit/literal.ts +0 -17
- package/src/runtime/emit/parameter.ts +0 -59
- package/src/runtime/emit/pragma.ts +0 -56
- package/src/runtime/emit/project.ts +0 -46
- package/src/runtime/emit/recursive-cte.ts +0 -111
- package/src/runtime/emit/remote-query.ts +0 -47
- package/src/runtime/emit/retrieve.ts +0 -15
- package/src/runtime/emit/returning.ts +0 -41
- package/src/runtime/emit/scalar-function.ts +0 -69
- package/src/runtime/emit/scan.ts +0 -106
- package/src/runtime/emit/schema-declarative.ts +0 -215
- package/src/runtime/emit/sequencing.ts +0 -24
- package/src/runtime/emit/set-operation.ts +0 -141
- package/src/runtime/emit/sink.ts +0 -27
- package/src/runtime/emit/sort.ts +0 -75
- package/src/runtime/emit/subquery.ts +0 -203
- package/src/runtime/emit/table-valued-function.ts +0 -106
- package/src/runtime/emit/temporal-arithmetic.ts +0 -302
- package/src/runtime/emit/transaction.ts +0 -205
- package/src/runtime/emit/unary.ts +0 -101
- package/src/runtime/emit/update.ts +0 -66
- package/src/runtime/emit/values.ts +0 -66
- package/src/runtime/emit/window-function.ts +0 -42
- package/src/runtime/emit/window.ts +0 -458
- package/src/runtime/emitters.ts +0 -183
- package/src/runtime/register.ts +0 -150
- package/src/runtime/scheduler.ts +0 -488
- package/src/runtime/types.ts +0 -242
- package/src/runtime/utils.ts +0 -177
- package/src/schema/assertion.ts +0 -21
- package/src/schema/catalog.ts +0 -269
- package/src/schema/change-events.ts +0 -80
- package/src/schema/column.ts +0 -51
- package/src/schema/declared-schema-manager.ts +0 -82
- package/src/schema/function.ts +0 -188
- package/src/schema/manager.ts +0 -1034
- package/src/schema/schema-differ.ts +0 -214
- package/src/schema/schema-hasher.ts +0 -26
- package/src/schema/schema.ts +0 -222
- package/src/schema/table.ts +0 -409
- package/src/schema/view.ts +0 -19
- package/src/schema/window-function.ts +0 -56
- package/src/types/builtin-types.ts +0 -350
- package/src/types/index.ts +0 -17
- package/src/types/json-type.ts +0 -152
- package/src/types/logical-type.ts +0 -91
- package/src/types/plugin-interface.ts +0 -10
- package/src/types/registry.ts +0 -204
- package/src/types/temporal-types.ts +0 -290
- package/src/types/validation.ts +0 -120
- package/src/util/affinity.ts +0 -151
- package/src/util/ast-stringify.ts +0 -887
- package/src/util/cached.ts +0 -25
- package/src/util/coercion.ts +0 -113
- package/src/util/comparison.ts +0 -510
- package/src/util/environment.ts +0 -52
- package/src/util/hash.ts +0 -90
- package/src/util/latches.ts +0 -47
- package/src/util/mutation-statement.ts +0 -135
- package/src/util/patterns.ts +0 -56
- package/src/util/plan-formatter.ts +0 -48
- package/src/util/plugin-helper.ts +0 -110
- package/src/util/row-descriptor.ts +0 -105
- package/src/util/serialization.ts +0 -47
- package/src/util/sql-literal.ts +0 -22
- package/src/util/working-table-iterable.ts +0 -38
- package/src/vtab/best-access-plan.ts +0 -244
- package/src/vtab/connection.ts +0 -36
- package/src/vtab/filter-info.ts +0 -23
- package/src/vtab/index-info.ts +0 -84
- package/src/vtab/manifest.ts +0 -86
- package/src/vtab/memory/connection.ts +0 -73
- package/src/vtab/memory/index.ts +0 -191
- package/src/vtab/memory/layer/base-cursor.ts +0 -124
- package/src/vtab/memory/layer/base.ts +0 -275
- package/src/vtab/memory/layer/connection.ts +0 -203
- package/src/vtab/memory/layer/interface.ts +0 -47
- package/src/vtab/memory/layer/manager.ts +0 -909
- package/src/vtab/memory/layer/safe-iterate.ts +0 -49
- package/src/vtab/memory/layer/scan-plan.ts +0 -84
- package/src/vtab/memory/layer/transaction-cursor.ts +0 -162
- package/src/vtab/memory/layer/transaction.ts +0 -229
- package/src/vtab/memory/module.ts +0 -667
- package/src/vtab/memory/table.ts +0 -251
- package/src/vtab/memory/types.ts +0 -23
- package/src/vtab/memory/utils/logging.ts +0 -36
- package/src/vtab/memory/utils/primary-key.ts +0 -163
- package/src/vtab/module.ts +0 -162
- package/src/vtab/table.ts +0 -177
|
@@ -1,887 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Functions to convert DDL AST nodes back into SQL strings.
|
|
3
|
-
*
|
|
4
|
-
* Formatting Notes:
|
|
5
|
-
* - Emits lowercase SQL keywords.
|
|
6
|
-
* - Quotes identifiers (table/column names) using double quotes.
|
|
7
|
-
* - String literals are escaped.
|
|
8
|
-
* - Omits clauses that represent the default SQLite behavior:
|
|
9
|
-
* - `ON CONFLICT ABORT`
|
|
10
|
-
* - `ASC` direction for primary keys
|
|
11
|
-
* - `VIRTUAL` storage for generated columns
|
|
12
|
-
* - (TODO: `FOREIGN KEY` default actions and deferrability)
|
|
13
|
-
*/
|
|
14
|
-
import type * as AST from '../parser/ast.js';
|
|
15
|
-
import { ConflictResolution } from '../common/constants.js';
|
|
16
|
-
import { KEYWORDS } from '../parser/lexer.js';
|
|
17
|
-
|
|
18
|
-
// --- Identifier Quoting Logic ---
|
|
19
|
-
|
|
20
|
-
// Basic check for valid SQL identifiers (adjust regex as needed)
|
|
21
|
-
const isValidIdentifier = (name: string): boolean => {
|
|
22
|
-
return /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Quotes an identifier (table, column, etc.) with double quotes if necessary.
|
|
27
|
-
* Quoting is needed if the identifier:
|
|
28
|
-
* - Is a reserved keyword (case-insensitive).
|
|
29
|
-
* - Does not match the valid identifier pattern (starts with letter/_, contains letters/numbers/_).
|
|
30
|
-
*/
|
|
31
|
-
function quoteIdentifierIfNeeded(name: string): string {
|
|
32
|
-
if (Object.hasOwn(KEYWORDS, name.toLowerCase()) || !isValidIdentifier(name)) {
|
|
33
|
-
return `"${name.replace(/"/g, '""')}"`; // Escape internal quotes
|
|
34
|
-
}
|
|
35
|
-
return name;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Main function to convert any AST node to SQL string
|
|
39
|
-
export function astToString(node: AST.AstNode): string {
|
|
40
|
-
switch (node.type) {
|
|
41
|
-
// Expression types
|
|
42
|
-
case 'literal':
|
|
43
|
-
case 'identifier':
|
|
44
|
-
case 'column':
|
|
45
|
-
case 'binary':
|
|
46
|
-
case 'unary':
|
|
47
|
-
case 'function':
|
|
48
|
-
case 'cast':
|
|
49
|
-
case 'parameter':
|
|
50
|
-
case 'subquery':
|
|
51
|
-
case 'collate':
|
|
52
|
-
case 'case':
|
|
53
|
-
case 'windowFunction':
|
|
54
|
-
return expressionToString(node as AST.Expression);
|
|
55
|
-
|
|
56
|
-
// Statement types
|
|
57
|
-
case 'select':
|
|
58
|
-
return selectToString(node as AST.SelectStmt);
|
|
59
|
-
case 'insert':
|
|
60
|
-
return insertToString(node as AST.InsertStmt);
|
|
61
|
-
case 'update':
|
|
62
|
-
return updateToString(node as AST.UpdateStmt);
|
|
63
|
-
case 'delete':
|
|
64
|
-
return deleteToString(node as AST.DeleteStmt);
|
|
65
|
-
case 'values':
|
|
66
|
-
return valuesToString(node as AST.ValuesStmt);
|
|
67
|
-
case 'createTable':
|
|
68
|
-
return createTableToString(node as AST.CreateTableStmt);
|
|
69
|
-
case 'createIndex':
|
|
70
|
-
return createIndexToString(node as AST.CreateIndexStmt);
|
|
71
|
-
case 'createView':
|
|
72
|
-
return createViewToString(node as AST.CreateViewStmt);
|
|
73
|
-
case 'drop':
|
|
74
|
-
return dropToString(node as AST.DropStmt);
|
|
75
|
-
case 'begin':
|
|
76
|
-
return beginToString(node as AST.BeginStmt);
|
|
77
|
-
case 'commit':
|
|
78
|
-
return 'commit';
|
|
79
|
-
case 'rollback':
|
|
80
|
-
return rollbackToString(node as AST.RollbackStmt);
|
|
81
|
-
case 'savepoint':
|
|
82
|
-
return savepointToString(node as AST.SavepointStmt);
|
|
83
|
-
case 'release':
|
|
84
|
-
return releaseToString(node as AST.ReleaseStmt);
|
|
85
|
-
case 'pragma':
|
|
86
|
-
return pragmaToString(node as AST.PragmaStmt);
|
|
87
|
-
case 'declareSchema':
|
|
88
|
-
return declareSchemaToString(node as unknown as AST.DeclareSchemaStmt);
|
|
89
|
-
case 'diffSchema':
|
|
90
|
-
return `diff schema ${(node as unknown as AST.DiffSchemaStmt).schemaName || 'main'}`;
|
|
91
|
-
case 'applySchema': {
|
|
92
|
-
const n = node as unknown as AST.ApplySchemaStmt;
|
|
93
|
-
let s = `apply schema ${n.schemaName || 'main'}`;
|
|
94
|
-
if (n.toVersion) s += ` to version '${n.toVersion}'`;
|
|
95
|
-
if (n.withSeed) s += ' with seed';
|
|
96
|
-
if (n.options) {
|
|
97
|
-
s += ' options (';
|
|
98
|
-
const parts: string[] = [];
|
|
99
|
-
if (n.options.dryRun !== undefined) parts.push(`dry_run = ${n.options.dryRun ? 'true' : 'false'}`);
|
|
100
|
-
if (n.options.validateOnly !== undefined) parts.push(`validate_only = ${n.options.validateOnly ? 'true' : 'false'}`);
|
|
101
|
-
if (n.options.allowDestructive !== undefined) parts.push(`allow_destructive = ${n.options.allowDestructive ? 'true' : 'false'}`);
|
|
102
|
-
if (n.options.renamePolicy) parts.push(`rename_policy = '${n.options.renamePolicy}'`);
|
|
103
|
-
s += parts.join(', ') + ')';
|
|
104
|
-
}
|
|
105
|
-
return s;
|
|
106
|
-
}
|
|
107
|
-
case 'explainSchema':
|
|
108
|
-
return `explain schema ${(node as unknown as AST.ExplainSchemaStmt).schemaName || 'main'}`;
|
|
109
|
-
|
|
110
|
-
default:
|
|
111
|
-
return `[${node.type}]`; // Fallback for unknown node types
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Helper to stringify expressions (extended from original)
|
|
116
|
-
export function expressionToString(expr: AST.Expression): string {
|
|
117
|
-
switch (expr.type) {
|
|
118
|
-
case 'literal': {
|
|
119
|
-
// Prefer original lexeme for numbers if available and different
|
|
120
|
-
if ((typeof expr.value === 'number' || typeof expr.value === 'bigint') && expr.lexeme && expr.lexeme !== String(expr.value)) {
|
|
121
|
-
return expr.lexeme;
|
|
122
|
-
}
|
|
123
|
-
// Prefer original lexeme for NULL if available
|
|
124
|
-
if (expr.value === null) return expr.lexeme?.toLowerCase() || 'null';
|
|
125
|
-
if (typeof expr.value === 'string') return `'${expr.value.replace(/'/g, "''")}'`; // Escape single quotes
|
|
126
|
-
if (typeof expr.value === 'number') return expr.value.toString();
|
|
127
|
-
if (expr.value instanceof Uint8Array) {
|
|
128
|
-
const hex = Buffer.from(expr.value).toString('hex');
|
|
129
|
-
return `x'${hex}'`;
|
|
130
|
-
}
|
|
131
|
-
return String(expr.value);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
case 'identifier': {
|
|
135
|
-
let identStr = quoteIdentifierIfNeeded(expr.name);
|
|
136
|
-
if (expr.schema) {
|
|
137
|
-
identStr = `${quoteIdentifierIfNeeded(expr.schema)}.${identStr}`;
|
|
138
|
-
}
|
|
139
|
-
return identStr;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
case 'column': {
|
|
143
|
-
let colStr = quoteIdentifierIfNeeded(expr.name);
|
|
144
|
-
if (expr.table) {
|
|
145
|
-
colStr = `${quoteIdentifierIfNeeded(expr.table)}.${colStr}`;
|
|
146
|
-
if (expr.schema) {
|
|
147
|
-
colStr = `${quoteIdentifierIfNeeded(expr.schema)}.${colStr}`;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
return colStr;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
case 'binary': {
|
|
154
|
-
const leftStr = needsParens(expr.left, expr.operator, 'left')
|
|
155
|
-
? `(${expressionToString(expr.left)})`
|
|
156
|
-
: expressionToString(expr.left);
|
|
157
|
-
const rightStr = needsParens(expr.right, expr.operator, 'right')
|
|
158
|
-
? `(${expressionToString(expr.right)})`
|
|
159
|
-
: expressionToString(expr.right);
|
|
160
|
-
return `${leftStr} ${expr.operator.toLowerCase()} ${rightStr}`;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
case 'unary': {
|
|
164
|
-
const exprStr = expr.expr.type === 'binary'
|
|
165
|
-
? `(${expressionToString(expr.expr)})`
|
|
166
|
-
: expressionToString(expr.expr);
|
|
167
|
-
// Handle postfix operators like IS NULL, IS NOT NULL
|
|
168
|
-
if (expr.operator === 'IS NULL' || expr.operator === 'IS NOT NULL') {
|
|
169
|
-
return `${exprStr} ${expr.operator.toLowerCase()}`;
|
|
170
|
-
} else if (expr.operator.toUpperCase() === 'NOT') {
|
|
171
|
-
return `${expr.operator.toLowerCase()} ${exprStr}`;
|
|
172
|
-
}
|
|
173
|
-
return `${expr.operator.toLowerCase()}${exprStr}`;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
case 'function': {
|
|
177
|
-
if (expr.name.toLowerCase() === 'count' && expr.args.length === 0) {
|
|
178
|
-
return 'count(*)';
|
|
179
|
-
}
|
|
180
|
-
const argsStr = expr.args.map(arg => expressionToString(arg)).join(', ');
|
|
181
|
-
const distinctStr = expr.distinct ? 'distinct ' : '';
|
|
182
|
-
return `${expr.name.toLowerCase()}(${distinctStr}${argsStr})`;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
case 'cast':
|
|
186
|
-
return `cast(${expressionToString(expr.expr)} as ${expr.targetType.toLowerCase()})`;
|
|
187
|
-
|
|
188
|
-
case 'parameter': {
|
|
189
|
-
if (expr.index !== undefined) {
|
|
190
|
-
return '?';
|
|
191
|
-
} else if (expr.name) {
|
|
192
|
-
return expr.name.startsWith(':') || expr.name.startsWith('$')
|
|
193
|
-
? expr.name
|
|
194
|
-
: `:${expr.name}`;
|
|
195
|
-
}
|
|
196
|
-
return '?';
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
case 'subquery':
|
|
200
|
-
return `(${selectToString(expr.query)})`;
|
|
201
|
-
|
|
202
|
-
case 'exists':
|
|
203
|
-
return `exists (${selectToString((expr as AST.ExistsExpr).subquery)})`;
|
|
204
|
-
|
|
205
|
-
case 'in': {
|
|
206
|
-
const inExpr = expr as AST.InExpr;
|
|
207
|
-
let result = expressionToString(inExpr.expr) + ' in ';
|
|
208
|
-
if (inExpr.values) {
|
|
209
|
-
result += `(${inExpr.values.map(expressionToString).join(', ')})`;
|
|
210
|
-
} else if (inExpr.subquery) {
|
|
211
|
-
result += `(${selectToString(inExpr.subquery)})`;
|
|
212
|
-
}
|
|
213
|
-
return result;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
case 'between': {
|
|
217
|
-
const betweenExpr = expr as AST.BetweenExpr;
|
|
218
|
-
const exprStr = expressionToString(betweenExpr.expr);
|
|
219
|
-
const lowerStr = expressionToString(betweenExpr.lower);
|
|
220
|
-
const upperStr = expressionToString(betweenExpr.upper);
|
|
221
|
-
const notStr = betweenExpr.not ? 'not ' : '';
|
|
222
|
-
return `${exprStr} ${notStr}between ${lowerStr} and ${upperStr}`;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
case 'collate':
|
|
226
|
-
return `${expressionToString(expr.expr)} collate ${expr.collation.toLowerCase()}`;
|
|
227
|
-
|
|
228
|
-
case 'case': {
|
|
229
|
-
// TODO: preserve and emit with original case
|
|
230
|
-
let caseStr = 'case';
|
|
231
|
-
if (expr.baseExpr) {
|
|
232
|
-
caseStr += ` ${expressionToString(expr.baseExpr)}`;
|
|
233
|
-
}
|
|
234
|
-
for (const clause of expr.whenThenClauses) {
|
|
235
|
-
caseStr += ` when ${expressionToString(clause.when)} then ${expressionToString(clause.then)}`;
|
|
236
|
-
}
|
|
237
|
-
if (expr.elseExpr) {
|
|
238
|
-
caseStr += ` else ${expressionToString(expr.elseExpr)}`;
|
|
239
|
-
}
|
|
240
|
-
caseStr += ' end';
|
|
241
|
-
return caseStr;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
case 'windowFunction': {
|
|
245
|
-
let winStr = expressionToString(expr.function);
|
|
246
|
-
if (expr.window) {
|
|
247
|
-
winStr += ` over (${windowDefinitionToString(expr.window)})`;
|
|
248
|
-
}
|
|
249
|
-
return winStr;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
default:
|
|
253
|
-
return '[unknown_expr]';
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// Helper to determine if parentheses are needed for binary operations
|
|
258
|
-
function needsParens(expr: AST.Expression, parentOp: string, side: 'left' | 'right'): boolean {
|
|
259
|
-
if (expr.type !== 'binary') return false;
|
|
260
|
-
|
|
261
|
-
const precedence: Record<string, number> = {
|
|
262
|
-
'OR': 1, 'AND': 2, 'NOT': 3, '=': 4, '!=': 4, '<': 4, '<=': 4, '>': 4, '>=': 4,
|
|
263
|
-
'LIKE': 4, 'IN': 4, 'IS': 4, '+': 5, '-': 5, '*': 6, '/': 6, '%': 6
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
const parentPrec = precedence[parentOp.toUpperCase()] || 0;
|
|
267
|
-
const childPrec = precedence[expr.operator.toUpperCase()] || 0;
|
|
268
|
-
|
|
269
|
-
if (childPrec < parentPrec) return true;
|
|
270
|
-
if (childPrec === parentPrec && side === 'right' && !isAssociative(parentOp)) return true;
|
|
271
|
-
|
|
272
|
-
return false;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
function isAssociative(op: string): boolean {
|
|
276
|
-
const associativeOps = ['AND', 'OR', '+', '*'];
|
|
277
|
-
return associativeOps.includes(op.toUpperCase());
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// Helper for window definitions
|
|
281
|
-
function windowDefinitionToString(win: AST.WindowDefinition): string {
|
|
282
|
-
const parts: string[] = [];
|
|
283
|
-
|
|
284
|
-
if (win.partitionBy && win.partitionBy.length > 0) {
|
|
285
|
-
parts.push(`partition by ${win.partitionBy.map(expressionToString).join(', ')}`);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
if (win.orderBy && win.orderBy.length > 0) {
|
|
289
|
-
const orderParts = win.orderBy.map(clause => {
|
|
290
|
-
let orderStr = expressionToString(clause.expr);
|
|
291
|
-
if (clause.direction === 'desc') orderStr += ' desc';
|
|
292
|
-
if (clause.nulls) orderStr += ` nulls ${clause.nulls.toLowerCase()}`;
|
|
293
|
-
return orderStr;
|
|
294
|
-
});
|
|
295
|
-
parts.push(`order by ${orderParts.join(', ')}`);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
if (win.frame) {
|
|
299
|
-
parts.push(windowFrameToString(win.frame));
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
return parts.join(' ');
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
function windowFrameToString(frame: AST.WindowFrame): string {
|
|
306
|
-
let frameStr = frame.type.toLowerCase(); // 'rows' or 'range'
|
|
307
|
-
|
|
308
|
-
if (frame.end) {
|
|
309
|
-
frameStr += ` between ${windowFrameBoundToString(frame.start)} and ${windowFrameBoundToString(frame.end)}`;
|
|
310
|
-
} else {
|
|
311
|
-
frameStr += ` ${windowFrameBoundToString(frame.start)}`;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
if (frame.exclusion) {
|
|
315
|
-
frameStr += ` exclude ${frame.exclusion.toLowerCase()}`;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
return frameStr;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
function windowFrameBoundToString(bound: AST.WindowFrameBound): string {
|
|
322
|
-
switch (bound.type) {
|
|
323
|
-
case 'currentRow': return 'current row';
|
|
324
|
-
case 'unboundedPreceding': return 'unbounded preceding';
|
|
325
|
-
case 'unboundedFollowing': return 'unbounded following';
|
|
326
|
-
case 'preceding': return `${expressionToString(bound.value)} preceding`;
|
|
327
|
-
case 'following': return `${expressionToString(bound.value)} following`;
|
|
328
|
-
default: return '[unknown_bound]';
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// Statement stringify functions
|
|
333
|
-
export function selectToString(stmt: AST.SelectStmt): string {
|
|
334
|
-
const parts: string[] = [];
|
|
335
|
-
|
|
336
|
-
if (stmt.withClause) {
|
|
337
|
-
parts.push(withClauseToString(stmt.withClause));
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
parts.push('select');
|
|
341
|
-
|
|
342
|
-
if (stmt.distinct) parts.push('distinct');
|
|
343
|
-
if (stmt.all) parts.push('all');
|
|
344
|
-
|
|
345
|
-
const columns = stmt.columns.map(col => {
|
|
346
|
-
if (col.type === 'all') {
|
|
347
|
-
return col.table ? `${quoteIdentifierIfNeeded(col.table)}.*` : '*';
|
|
348
|
-
} else {
|
|
349
|
-
let colStr = expressionToString(col.expr);
|
|
350
|
-
if (col.alias) colStr += ` as ${quoteIdentifierIfNeeded(col.alias)}`;
|
|
351
|
-
return colStr;
|
|
352
|
-
}
|
|
353
|
-
});
|
|
354
|
-
parts.push(columns.join(', '));
|
|
355
|
-
|
|
356
|
-
if (stmt.from && stmt.from.length > 0) {
|
|
357
|
-
parts.push('from', stmt.from.map(fromClauseToString).join(', '));
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
if (stmt.where) {
|
|
361
|
-
parts.push('where', expressionToString(stmt.where));
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
if (stmt.groupBy && stmt.groupBy.length > 0) {
|
|
365
|
-
parts.push('group by', stmt.groupBy.map(expressionToString).join(', '));
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
if (stmt.having) {
|
|
369
|
-
parts.push('having', expressionToString(stmt.having));
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
if (stmt.orderBy && stmt.orderBy.length > 0) {
|
|
373
|
-
const orderParts = stmt.orderBy.map(clause => {
|
|
374
|
-
let orderStr = expressionToString(clause.expr);
|
|
375
|
-
if (clause.direction === 'desc') orderStr += ' desc';
|
|
376
|
-
if (clause.nulls) orderStr += ` nulls ${clause.nulls.toLowerCase()}`;
|
|
377
|
-
return orderStr;
|
|
378
|
-
});
|
|
379
|
-
parts.push('order by', orderParts.join(', '));
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
if (stmt.limit) {
|
|
383
|
-
parts.push('limit', expressionToString(stmt.limit));
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
if (stmt.offset) {
|
|
387
|
-
parts.push('offset', expressionToString(stmt.offset));
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
let result = parts.join(' ');
|
|
391
|
-
|
|
392
|
-
if (stmt.union) {
|
|
393
|
-
result += stmt.unionAll ? ' union all ' : ' union ';
|
|
394
|
-
result += selectToString(stmt.union);
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
return result;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
function withClauseToString(withClause: AST.WithClause): string {
|
|
401
|
-
let result = 'with';
|
|
402
|
-
if (withClause.recursive) result += ' recursive';
|
|
403
|
-
|
|
404
|
-
const ctes = withClause.ctes.map(cte => {
|
|
405
|
-
let cteStr = quoteIdentifierIfNeeded(cte.name);
|
|
406
|
-
if (cte.columns && cte.columns.length > 0) {
|
|
407
|
-
cteStr += ` (${cte.columns.map(quoteIdentifierIfNeeded).join(', ')})`;
|
|
408
|
-
}
|
|
409
|
-
cteStr += ` as (${astToString(cte.query)})`;
|
|
410
|
-
return cteStr;
|
|
411
|
-
});
|
|
412
|
-
|
|
413
|
-
result += ` ${ctes.join(', ')}`;
|
|
414
|
-
|
|
415
|
-
// Add OPTION clause if present
|
|
416
|
-
if (withClause.options?.maxRecursion !== undefined) {
|
|
417
|
-
result += ` option (maxrecursion ${withClause.options.maxRecursion})`;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
return result;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
function fromClauseToString(from: AST.FromClause): string {
|
|
424
|
-
switch (from.type) {
|
|
425
|
-
case 'table': {
|
|
426
|
-
let tableStr = quoteIdentifierIfNeeded(from.table.name);
|
|
427
|
-
if (from.table.schema) {
|
|
428
|
-
tableStr = `${quoteIdentifierIfNeeded(from.table.schema)}.${tableStr}`;
|
|
429
|
-
}
|
|
430
|
-
if (from.alias) tableStr += ` as ${quoteIdentifierIfNeeded(from.alias)}`;
|
|
431
|
-
return tableStr;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
case 'subquerySource': {
|
|
435
|
-
let subqueryStr: string;
|
|
436
|
-
if (from.subquery.type === 'select') {
|
|
437
|
-
subqueryStr = selectToString(from.subquery);
|
|
438
|
-
} else if (from.subquery.type === 'values') {
|
|
439
|
-
subqueryStr = valuesToString(from.subquery);
|
|
440
|
-
} else {
|
|
441
|
-
// Handle the case where subquery type is not recognized
|
|
442
|
-
const exhaustiveCheck: never = from.subquery;
|
|
443
|
-
subqueryStr = astToString(exhaustiveCheck);
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
let aliasStr = `as ${quoteIdentifierIfNeeded(from.alias)}`;
|
|
447
|
-
if (from.columns && from.columns.length > 0) {
|
|
448
|
-
aliasStr += ` (${from.columns.map(quoteIdentifierIfNeeded).join(', ')})`;
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
return `(${subqueryStr}) ${aliasStr}`;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
case 'functionSource': {
|
|
455
|
-
const args = from.args.map(expressionToString).join(', ');
|
|
456
|
-
// Check if from.name is a function expression or identifier expression
|
|
457
|
-
let funcName: string;
|
|
458
|
-
if (from.name.type === 'identifier') {
|
|
459
|
-
funcName = from.name.name.toLowerCase();
|
|
460
|
-
} else if (from.name.type === 'function') {
|
|
461
|
-
funcName = expressionToString(from.name);
|
|
462
|
-
} else {
|
|
463
|
-
funcName = expressionToString(from.name);
|
|
464
|
-
}
|
|
465
|
-
let funcStr = `${funcName}(${args})`;
|
|
466
|
-
if (from.alias) funcStr += ` as ${quoteIdentifierIfNeeded(from.alias)}`;
|
|
467
|
-
return funcStr;
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
case 'join': {
|
|
471
|
-
const leftStr = fromClauseToString(from.left);
|
|
472
|
-
const rightStr = fromClauseToString(from.right);
|
|
473
|
-
let joinStr = `${leftStr} ${from.joinType.toLowerCase()} join ${rightStr}`;
|
|
474
|
-
if (from.condition) {
|
|
475
|
-
joinStr += ` on ${expressionToString(from.condition)}`;
|
|
476
|
-
} else if (from.columns) {
|
|
477
|
-
joinStr += ` using (${from.columns.map(quoteIdentifierIfNeeded).join(', ')})`;
|
|
478
|
-
}
|
|
479
|
-
return joinStr;
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
default:
|
|
483
|
-
return '[unknown_from]';
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
export function insertToString(stmt: AST.InsertStmt): string {
|
|
488
|
-
const parts: string[] = [];
|
|
489
|
-
|
|
490
|
-
if (stmt.withClause) {
|
|
491
|
-
parts.push(withClauseToString(stmt.withClause));
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
parts.push('insert into', expressionToString(stmt.table));
|
|
495
|
-
|
|
496
|
-
if (stmt.columns && stmt.columns.length > 0) {
|
|
497
|
-
parts.push(`(${stmt.columns.map(quoteIdentifierIfNeeded).join(', ')})`);
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
if (stmt.contextValues && stmt.contextValues.length > 0) {
|
|
501
|
-
const contextAssignments = stmt.contextValues.map(assign =>
|
|
502
|
-
`${quoteIdentifierIfNeeded(assign.name)} = ${expressionToString(assign.value)}`
|
|
503
|
-
);
|
|
504
|
-
parts.push('with context', contextAssignments.join(', '));
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
if (stmt.values) {
|
|
508
|
-
const valueRows = stmt.values.map(row =>
|
|
509
|
-
`(${row.map(expressionToString).join(', ')})`
|
|
510
|
-
);
|
|
511
|
-
parts.push('values', valueRows.join(', '));
|
|
512
|
-
} else if (stmt.select) {
|
|
513
|
-
parts.push(selectToString(stmt.select));
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
if (stmt.onConflict && stmt.onConflict !== ConflictResolution.ABORT) {
|
|
517
|
-
parts.push(`on conflict ${ConflictResolution[stmt.onConflict].toLowerCase()}`);
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
if (stmt.returning && stmt.returning.length > 0) {
|
|
521
|
-
const returning = stmt.returning.map(col => {
|
|
522
|
-
if (col.type === 'all') {
|
|
523
|
-
return col.table ? `${quoteIdentifierIfNeeded(col.table)}.*` : '*';
|
|
524
|
-
} else {
|
|
525
|
-
let colStr = expressionToString(col.expr);
|
|
526
|
-
if (col.alias) colStr += ` as ${quoteIdentifierIfNeeded(col.alias)}`;
|
|
527
|
-
return colStr;
|
|
528
|
-
}
|
|
529
|
-
});
|
|
530
|
-
parts.push('returning', returning.join(', '));
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
return parts.join(' ');
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
export function updateToString(stmt: AST.UpdateStmt): string {
|
|
537
|
-
const parts: string[] = [];
|
|
538
|
-
|
|
539
|
-
if (stmt.withClause) {
|
|
540
|
-
parts.push(withClauseToString(stmt.withClause));
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
parts.push('update', expressionToString(stmt.table));
|
|
544
|
-
|
|
545
|
-
if (stmt.contextValues && stmt.contextValues.length > 0) {
|
|
546
|
-
const contextAssignments = stmt.contextValues.map(assign =>
|
|
547
|
-
`${quoteIdentifierIfNeeded(assign.name)} = ${expressionToString(assign.value)}`
|
|
548
|
-
);
|
|
549
|
-
parts.push('with context', contextAssignments.join(', '));
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
parts.push('set');
|
|
553
|
-
|
|
554
|
-
const assignments = stmt.assignments.map(assign =>
|
|
555
|
-
`${quoteIdentifierIfNeeded(assign.column)} = ${expressionToString(assign.value)}`
|
|
556
|
-
);
|
|
557
|
-
parts.push(assignments.join(', '));
|
|
558
|
-
|
|
559
|
-
if (stmt.where) {
|
|
560
|
-
parts.push('where', expressionToString(stmt.where));
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
if (stmt.onConflict && stmt.onConflict !== ConflictResolution.ABORT) {
|
|
564
|
-
parts.push(`on conflict ${ConflictResolution[stmt.onConflict].toLowerCase()}`);
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
if (stmt.returning && stmt.returning.length > 0) {
|
|
568
|
-
const returning = stmt.returning.map(col => {
|
|
569
|
-
if (col.type === 'all') {
|
|
570
|
-
return col.table ? `${quoteIdentifierIfNeeded(col.table)}.*` : '*';
|
|
571
|
-
} else {
|
|
572
|
-
let colStr = expressionToString(col.expr);
|
|
573
|
-
if (col.alias) colStr += ` as ${quoteIdentifierIfNeeded(col.alias)}`;
|
|
574
|
-
return colStr;
|
|
575
|
-
}
|
|
576
|
-
});
|
|
577
|
-
parts.push('returning', returning.join(', '));
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
return parts.join(' ');
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
export function deleteToString(stmt: AST.DeleteStmt): string {
|
|
584
|
-
const parts: string[] = [];
|
|
585
|
-
|
|
586
|
-
if (stmt.withClause) {
|
|
587
|
-
parts.push(withClauseToString(stmt.withClause));
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
parts.push('delete from', expressionToString(stmt.table));
|
|
591
|
-
|
|
592
|
-
if (stmt.contextValues && stmt.contextValues.length > 0) {
|
|
593
|
-
const contextAssignments = stmt.contextValues.map(assign =>
|
|
594
|
-
`${quoteIdentifierIfNeeded(assign.name)} = ${expressionToString(assign.value)}`
|
|
595
|
-
);
|
|
596
|
-
parts.push('with context', contextAssignments.join(', '));
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
if (stmt.where) {
|
|
600
|
-
parts.push('where', expressionToString(stmt.where));
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
if (stmt.returning && stmt.returning.length > 0) {
|
|
604
|
-
const returning = stmt.returning.map(col => {
|
|
605
|
-
if (col.type === 'all') {
|
|
606
|
-
return col.table ? `${quoteIdentifierIfNeeded(col.table)}.*` : '*';
|
|
607
|
-
} else {
|
|
608
|
-
let colStr = expressionToString(col.expr);
|
|
609
|
-
if (col.alias) colStr += ` as ${quoteIdentifierIfNeeded(col.alias)}`;
|
|
610
|
-
return colStr;
|
|
611
|
-
}
|
|
612
|
-
});
|
|
613
|
-
parts.push('returning', returning.join(', '));
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
return parts.join(' ');
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
export function valuesToString(stmt: AST.ValuesStmt): string {
|
|
620
|
-
const valueRows = stmt.values.map(row =>
|
|
621
|
-
`(${row.map(expressionToString).join(', ')})`
|
|
622
|
-
);
|
|
623
|
-
return `values ${valueRows.join(', ')}`;
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
export function createIndexToString(stmt: AST.CreateIndexStmt): string {
|
|
627
|
-
const parts: string[] = ['create'];
|
|
628
|
-
if (stmt.isUnique) parts.push('unique');
|
|
629
|
-
parts.push('index');
|
|
630
|
-
if (stmt.ifNotExists) parts.push('if not exists');
|
|
631
|
-
|
|
632
|
-
parts.push(expressionToString(stmt.index), 'on', expressionToString(stmt.table));
|
|
633
|
-
|
|
634
|
-
const columns = stmt.columns.map(col => {
|
|
635
|
-
if (col.name) {
|
|
636
|
-
let colStr = quoteIdentifierIfNeeded(col.name);
|
|
637
|
-
if (col.collation) colStr += ` collate ${col.collation.toLowerCase()}`;
|
|
638
|
-
if (col.direction === 'desc') colStr += ' desc';
|
|
639
|
-
return colStr;
|
|
640
|
-
} else if (col.expr) {
|
|
641
|
-
return expressionToString(col.expr);
|
|
642
|
-
}
|
|
643
|
-
return '';
|
|
644
|
-
}).filter(s => s);
|
|
645
|
-
|
|
646
|
-
parts.push(`(${columns.join(', ')})`);
|
|
647
|
-
|
|
648
|
-
if (stmt.where) {
|
|
649
|
-
parts.push('where', expressionToString(stmt.where));
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
return parts.join(' ');
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
export function createViewToString(stmt: AST.CreateViewStmt): string {
|
|
656
|
-
const parts: string[] = ['create'];
|
|
657
|
-
if (stmt.isTemporary) parts.push('temp');
|
|
658
|
-
parts.push('view');
|
|
659
|
-
if (stmt.ifNotExists) parts.push('if not exists');
|
|
660
|
-
|
|
661
|
-
parts.push(expressionToString(stmt.view));
|
|
662
|
-
|
|
663
|
-
if (stmt.columns && stmt.columns.length > 0) {
|
|
664
|
-
parts.push(`(${stmt.columns.map(quoteIdentifierIfNeeded).join(', ')})`);
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
parts.push('as', selectToString(stmt.select));
|
|
668
|
-
|
|
669
|
-
return parts.join(' ');
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
function dropToString(stmt: AST.DropStmt): string {
|
|
673
|
-
const parts: string[] = ['drop', stmt.objectType.toLowerCase()];
|
|
674
|
-
if (stmt.ifExists) parts.push('if exists');
|
|
675
|
-
parts.push(expressionToString(stmt.name));
|
|
676
|
-
return parts.join(' ');
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
function beginToString(stmt: AST.BeginStmt): string {
|
|
680
|
-
return 'begin transaction';
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
function rollbackToString(stmt: AST.RollbackStmt): string {
|
|
684
|
-
let result = 'rollback';
|
|
685
|
-
if (stmt.savepoint) {
|
|
686
|
-
result += ` to ${stmt.savepoint}`;
|
|
687
|
-
}
|
|
688
|
-
return result;
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
function savepointToString(stmt: AST.SavepointStmt): string {
|
|
692
|
-
return `savepoint ${stmt.name}`;
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
function releaseToString(stmt: AST.ReleaseStmt): string {
|
|
696
|
-
let result = 'release';
|
|
697
|
-
if (stmt.savepoint) {
|
|
698
|
-
result += ` ${stmt.savepoint}`;
|
|
699
|
-
}
|
|
700
|
-
return result;
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
function pragmaToString(stmt: AST.PragmaStmt): string {
|
|
704
|
-
let result = `pragma ${stmt.name.toLowerCase()}`;
|
|
705
|
-
if (stmt.value) {
|
|
706
|
-
result += ` = ${expressionToString(stmt.value)}`;
|
|
707
|
-
}
|
|
708
|
-
return result;
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
function declareSchemaToString(stmt: AST.DeclareSchemaStmt): string {
|
|
712
|
-
let s = `declare schema ${quoteIdentifierIfNeeded(stmt.schemaName || 'main')}`;
|
|
713
|
-
if (stmt.version) s += ` version '${stmt.version}'`;
|
|
714
|
-
if (stmt.using && (stmt.using.defaultVtabModule || stmt.using.defaultVtabArgs)) {
|
|
715
|
-
const opts: string[] = [];
|
|
716
|
-
if (stmt.using.defaultVtabModule) opts.push(`default_vtab_module = '${stmt.using.defaultVtabModule}'`);
|
|
717
|
-
if (stmt.using.defaultVtabArgs) opts.push(`default_vtab_args = '${stmt.using.defaultVtabArgs}'`);
|
|
718
|
-
s += ` using (${opts.join(', ')})`;
|
|
719
|
-
}
|
|
720
|
-
s += ' {';
|
|
721
|
-
for (const it of stmt.items) {
|
|
722
|
-
s += ' ' + declareItemToString(it) + ';';
|
|
723
|
-
}
|
|
724
|
-
s += ' }';
|
|
725
|
-
return s;
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
function declareItemToString(it: AST.DeclareItem): string {
|
|
729
|
-
if (it.type === 'declaredTable') {
|
|
730
|
-
return `table ${it.tableStmt.table.name} { ... }`;
|
|
731
|
-
}
|
|
732
|
-
if (it.type === 'declaredIndex') {
|
|
733
|
-
return `index ${it.indexStmt.index.name} on ${it.indexStmt.table.name} (...)`;
|
|
734
|
-
}
|
|
735
|
-
if (it.type === 'declaredView') {
|
|
736
|
-
return `view ${it.viewStmt.view.name} as ...`;
|
|
737
|
-
}
|
|
738
|
-
if (it.type === 'declaredSeed') {
|
|
739
|
-
const rowsStr = it.seedData?.map(r => `(${r.map(v => JSON.stringify(v)).join(', ')})`).join(', ') || '';
|
|
740
|
-
return `seed ${it.tableName} (${rowsStr})`;
|
|
741
|
-
}
|
|
742
|
-
return (it as unknown as AST.DeclareIgnoredItem).text || '-- ignored';
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
// Helper to stringify conflict clauses
|
|
746
|
-
function conflictToString(res: ConflictResolution | undefined): string {
|
|
747
|
-
// ABORT is the default, so don't emit it
|
|
748
|
-
if (!res || res === ConflictResolution.ABORT) return '';
|
|
749
|
-
// Assuming ConflictResolution enum values are uppercase, convert them to lowercase
|
|
750
|
-
return ` on conflict ${ConflictResolution[res].toLowerCase()}`;
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
// Helper to stringify column constraints
|
|
754
|
-
function columnConstraintsToString(constraints: AST.ColumnConstraint[]): string {
|
|
755
|
-
return constraints.map(c => {
|
|
756
|
-
let s = '';
|
|
757
|
-
if (c.name) s += `constraint ${quoteIdentifierIfNeeded(c.name)} `;
|
|
758
|
-
switch (c.type) {
|
|
759
|
-
case 'primaryKey':
|
|
760
|
-
s += 'primary key';
|
|
761
|
-
// ASC is default, only specify DESC
|
|
762
|
-
if (c.direction === 'desc') s += ` desc`;
|
|
763
|
-
s += conflictToString(c.onConflict);
|
|
764
|
-
if (c.autoincrement) s += ' autoincrement';
|
|
765
|
-
break;
|
|
766
|
-
case 'notNull':
|
|
767
|
-
s += 'not null';
|
|
768
|
-
s += conflictToString(c.onConflict);
|
|
769
|
-
break;
|
|
770
|
-
case 'null':
|
|
771
|
-
s += 'null';
|
|
772
|
-
s += conflictToString(c.onConflict);
|
|
773
|
-
break;
|
|
774
|
-
case 'unique':
|
|
775
|
-
s += 'unique';
|
|
776
|
-
s += conflictToString(c.onConflict);
|
|
777
|
-
break;
|
|
778
|
-
case 'check':
|
|
779
|
-
s += `check (${expressionToString(c.expr!)})`;
|
|
780
|
-
break;
|
|
781
|
-
case 'default':
|
|
782
|
-
s += `default ${expressionToString(c.expr!)}`;
|
|
783
|
-
break;
|
|
784
|
-
case 'collate':
|
|
785
|
-
s += `collate ${c.collation!.toLowerCase()}`;
|
|
786
|
-
break;
|
|
787
|
-
case 'foreignKey':
|
|
788
|
-
if (c.foreignKey) {
|
|
789
|
-
const fk = c.foreignKey;
|
|
790
|
-
s += `references ${quoteIdentifierIfNeeded(fk.table)}`;
|
|
791
|
-
if (fk.columns && fk.columns.length > 0) {
|
|
792
|
-
s += `(${fk.columns.map(quoteIdentifierIfNeeded).join(', ')})`;
|
|
793
|
-
}
|
|
794
|
-
if (fk.onDelete) s += ` on delete ${foreignKeyActionToString(fk.onDelete)}`;
|
|
795
|
-
if (fk.onUpdate) s += ` on update ${foreignKeyActionToString(fk.onUpdate)}`;
|
|
796
|
-
}
|
|
797
|
-
break;
|
|
798
|
-
case 'generated':
|
|
799
|
-
s += `generated always as (${expressionToString(c.generated!.expr)})`;
|
|
800
|
-
// VIRTUAL is default, only specify STORED
|
|
801
|
-
if (c.generated!.stored) s += ' stored';
|
|
802
|
-
break;
|
|
803
|
-
}
|
|
804
|
-
return s;
|
|
805
|
-
}).filter(s => s.length > 0).join(' ');
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
// Helper to stringify table constraints
|
|
809
|
-
function tableConstraintsToString(constraints: AST.TableConstraint[]): string {
|
|
810
|
-
return constraints.map(c => {
|
|
811
|
-
let s = '';
|
|
812
|
-
if (c.name) s += `constraint ${quoteIdentifierIfNeeded(c.name)} `;
|
|
813
|
-
switch (c.type) {
|
|
814
|
-
case 'primaryKey':
|
|
815
|
-
// ASC is default, only specify DESC
|
|
816
|
-
s += `primary key (${c.columns!.map(col => `${quoteIdentifierIfNeeded(col.name)}${col.direction === 'desc' ? ' desc' : ''}`).join(', ')})`;
|
|
817
|
-
s += conflictToString(c.onConflict);
|
|
818
|
-
break;
|
|
819
|
-
case 'unique':
|
|
820
|
-
s += `unique (${c.columns!.map(col => quoteIdentifierIfNeeded(col.name)).join(', ')})`;
|
|
821
|
-
s += conflictToString(c.onConflict);
|
|
822
|
-
break;
|
|
823
|
-
case 'check':
|
|
824
|
-
s += `check (${expressionToString(c.expr!)})`;
|
|
825
|
-
break;
|
|
826
|
-
case 'foreignKey':
|
|
827
|
-
if (c.foreignKey) {
|
|
828
|
-
const fk = c.foreignKey;
|
|
829
|
-
s += `foreign key (${c.columns!.map(col => quoteIdentifierIfNeeded(col.name)).join(', ')}) references ${quoteIdentifierIfNeeded(fk.table)}`;
|
|
830
|
-
if (fk.columns && fk.columns.length > 0) {
|
|
831
|
-
s += `(${fk.columns.map(quoteIdentifierIfNeeded).join(', ')})`;
|
|
832
|
-
}
|
|
833
|
-
if (fk.onDelete) s += ` on delete ${foreignKeyActionToString(fk.onDelete)}`;
|
|
834
|
-
if (fk.onUpdate) s += ` on update ${foreignKeyActionToString(fk.onUpdate)}`;
|
|
835
|
-
}
|
|
836
|
-
break;
|
|
837
|
-
}
|
|
838
|
-
return s;
|
|
839
|
-
}).filter(s => s.length > 0).join(', ');
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
function foreignKeyActionToString(action: AST.ForeignKeyAction): string {
|
|
843
|
-
switch (action) {
|
|
844
|
-
case 'setNull': return 'set null';
|
|
845
|
-
case 'setDefault': return 'set default';
|
|
846
|
-
case 'cascade': return 'cascade';
|
|
847
|
-
case 'restrict': return 'restrict';
|
|
848
|
-
case 'noAction': return 'no action';
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
export function createTableToString(stmt: AST.CreateTableStmt): string {
|
|
853
|
-
const parts: string[] = ['create'];
|
|
854
|
-
if (stmt.isTemporary) parts.push('temp');
|
|
855
|
-
parts.push('table');
|
|
856
|
-
if (stmt.ifNotExists) parts.push('if not exists');
|
|
857
|
-
// Handle schema.table quoting
|
|
858
|
-
const tableName = quoteIdentifierIfNeeded(stmt.table.name);
|
|
859
|
-
const schemaName = stmt.table.schema ? quoteIdentifierIfNeeded(stmt.table.schema) : undefined;
|
|
860
|
-
parts.push(schemaName ? `${schemaName}.${tableName}` : tableName);
|
|
861
|
-
|
|
862
|
-
const definitions: string[] = [];
|
|
863
|
-
stmt.columns.forEach(col => {
|
|
864
|
-
let colDef = quoteIdentifierIfNeeded(col.name);
|
|
865
|
-
if (col.dataType) colDef += ` ${col.dataType}`; // Keep data type casing as is
|
|
866
|
-
const constraints = columnConstraintsToString(col.constraints);
|
|
867
|
-
if (constraints) colDef += ` ${constraints}`;
|
|
868
|
-
definitions.push(colDef);
|
|
869
|
-
});
|
|
870
|
-
|
|
871
|
-
const tableConstraints = tableConstraintsToString(stmt.constraints);
|
|
872
|
-
if (tableConstraints) definitions.push(tableConstraints);
|
|
873
|
-
|
|
874
|
-
parts.push(`(${definitions.join(', ')})`);
|
|
875
|
-
|
|
876
|
-
if (stmt.moduleName) {
|
|
877
|
-
parts.push('using', stmt.moduleName);
|
|
878
|
-
if (stmt.moduleArgs && Object.keys(stmt.moduleArgs).length > 0) {
|
|
879
|
-
const args = Object.entries(stmt.moduleArgs).map(([key, value]) =>
|
|
880
|
-
`${quoteIdentifierIfNeeded(key)} = ${JSON.stringify(value)}`
|
|
881
|
-
).join(', ');
|
|
882
|
-
parts.push(`(${args})`);
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
return parts.join(' ');
|
|
887
|
-
}
|