@uwdata/mosaic-sql 0.17.0 → 0.19.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/LICENSE +47 -0
- package/README.md +0 -2
- package/dist/src/ast/aggregate.d.ts +82 -0
- package/dist/src/ast/aggregate.d.ts.map +1 -0
- package/dist/src/ast/aggregate.js +180 -0
- package/dist/src/ast/aggregate.js.map +1 -0
- package/dist/src/ast/between-op.d.ts +46 -0
- package/dist/src/ast/between-op.d.ts.map +1 -0
- package/dist/src/ast/between-op.js +60 -0
- package/dist/src/ast/between-op.js.map +1 -0
- package/dist/src/ast/binary-op.d.ts +21 -0
- package/dist/src/ast/binary-op.d.ts.map +1 -0
- package/dist/src/ast/binary-op.js +29 -0
- package/dist/src/ast/binary-op.js.map +1 -0
- package/dist/src/ast/case.d.ts +53 -0
- package/dist/src/ast/case.d.ts.map +1 -0
- package/dist/src/ast/case.js +75 -0
- package/dist/src/ast/case.js.map +1 -0
- package/dist/src/ast/cast.d.ts +18 -0
- package/dist/src/ast/cast.d.ts.map +1 -0
- package/dist/src/ast/cast.js +26 -0
- package/dist/src/ast/cast.js.map +1 -0
- package/dist/src/ast/collate.d.ts +18 -0
- package/dist/src/ast/collate.d.ts.map +1 -0
- package/dist/src/ast/collate.js +25 -0
- package/dist/src/ast/collate.js.map +1 -0
- package/dist/src/ast/column-param.d.ts +23 -0
- package/dist/src/ast/column-param.d.ts.map +1 -0
- package/dist/src/ast/column-param.js +29 -0
- package/dist/src/ast/column-param.js.map +1 -0
- package/dist/src/ast/column-ref.d.ts +40 -0
- package/dist/src/ast/column-ref.d.ts.map +1 -0
- package/dist/src/ast/column-ref.js +58 -0
- package/dist/src/ast/column-ref.js.map +1 -0
- package/dist/src/ast/fragment.d.ts +20 -0
- package/dist/src/ast/fragment.d.ts.map +1 -0
- package/dist/src/ast/fragment.js +26 -0
- package/dist/src/ast/fragment.js.map +1 -0
- package/dist/src/ast/from.d.ts +22 -0
- package/dist/src/ast/from.d.ts.map +1 -0
- package/dist/src/ast/from.js +37 -0
- package/dist/src/ast/from.js.map +1 -0
- package/dist/src/ast/function.d.ts +18 -0
- package/dist/src/ast/function.d.ts.map +1 -0
- package/dist/src/ast/function.js +26 -0
- package/dist/src/ast/function.js.map +1 -0
- package/dist/src/ast/in-op.d.ts +18 -0
- package/dist/src/ast/in-op.d.ts.map +1 -0
- package/dist/src/ast/in-op.js +25 -0
- package/dist/src/ast/in-op.js.map +1 -0
- package/dist/src/ast/interval.d.ts +18 -0
- package/dist/src/ast/interval.d.ts.map +1 -0
- package/dist/src/ast/interval.js +25 -0
- package/dist/src/ast/interval.js.map +1 -0
- package/dist/src/ast/list.d.ts +15 -0
- package/dist/src/ast/list.d.ts.map +1 -0
- package/dist/src/ast/list.js +21 -0
- package/dist/src/ast/list.js.map +1 -0
- package/dist/src/ast/literal.d.ts +16 -0
- package/dist/src/ast/literal.d.ts.map +1 -0
- package/dist/src/ast/literal.js +53 -0
- package/dist/src/ast/literal.js.map +1 -0
- package/dist/src/ast/logical-op.d.ts +32 -0
- package/dist/src/ast/logical-op.d.ts.map +1 -0
- package/dist/src/ast/logical-op.js +46 -0
- package/dist/src/ast/logical-op.js.map +1 -0
- package/dist/src/ast/node.d.ts +25 -0
- package/dist/src/ast/node.d.ts.map +1 -0
- package/dist/src/ast/node.js +36 -0
- package/dist/src/ast/node.js.map +1 -0
- package/dist/src/ast/order-by.d.ts +21 -0
- package/dist/src/ast/order-by.d.ts.map +1 -0
- package/dist/src/ast/order-by.js +36 -0
- package/dist/src/ast/order-by.js.map +1 -0
- package/dist/src/ast/param.d.ts +20 -0
- package/dist/src/ast/param.d.ts.map +1 -0
- package/dist/src/ast/param.js +28 -0
- package/dist/src/ast/param.js.map +1 -0
- package/dist/src/ast/query.d.ts +334 -0
- package/dist/src/ast/query.d.ts.map +1 -0
- package/dist/src/ast/query.js +640 -0
- package/dist/src/ast/query.js.map +1 -0
- package/dist/src/ast/sample.d.ts +27 -0
- package/dist/src/ast/sample.d.ts.map +1 -0
- package/dist/src/ast/sample.js +38 -0
- package/dist/src/ast/sample.js.map +1 -0
- package/dist/src/ast/select.d.ts +19 -0
- package/dist/src/ast/select.d.ts.map +1 -0
- package/dist/src/ast/select.js +35 -0
- package/dist/src/ast/select.js.map +1 -0
- package/dist/src/ast/subquery.d.ts +16 -0
- package/dist/src/ast/subquery.d.ts.map +1 -0
- package/dist/src/ast/subquery.js +21 -0
- package/dist/src/ast/subquery.js.map +1 -0
- package/dist/src/ast/table-ref.d.ts +24 -0
- package/dist/src/ast/table-ref.d.ts.map +1 -0
- package/dist/src/ast/table-ref.js +35 -0
- package/dist/src/ast/table-ref.js.map +1 -0
- package/dist/src/ast/unary-op.d.ts +40 -0
- package/dist/src/ast/unary-op.d.ts.map +1 -0
- package/dist/src/ast/unary-op.js +52 -0
- package/dist/src/ast/unary-op.js.map +1 -0
- package/dist/src/ast/unnest.d.ts +19 -0
- package/dist/src/ast/unnest.d.ts.map +1 -0
- package/dist/src/ast/unnest.js +29 -0
- package/dist/src/ast/unnest.js.map +1 -0
- package/dist/src/ast/verbatim.d.ts +18 -0
- package/dist/src/ast/verbatim.d.ts.map +1 -0
- package/dist/src/ast/verbatim.js +25 -0
- package/dist/src/ast/verbatim.js.map +1 -0
- package/dist/src/ast/window-frame.d.ts +54 -0
- package/dist/src/ast/window-frame.d.ts.map +1 -0
- package/dist/src/ast/window-frame.js +79 -0
- package/dist/src/ast/window-frame.js.map +1 -0
- package/dist/src/ast/window.d.ts +128 -0
- package/dist/src/ast/window.d.ts.map +1 -0
- package/dist/src/ast/window.js +194 -0
- package/dist/src/ast/window.js.map +1 -0
- package/dist/src/ast/with.d.ts +25 -0
- package/dist/src/ast/with.d.ts.map +1 -0
- package/dist/src/ast/with.js +36 -0
- package/dist/src/ast/with.js.map +1 -0
- package/dist/src/constants.d.ts +40 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +40 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/functions/aggregate.d.ts +236 -0
- package/dist/src/functions/aggregate.d.ts.map +1 -0
- package/dist/src/functions/aggregate.js +308 -0
- package/dist/src/functions/aggregate.js.map +1 -0
- package/dist/src/functions/case.d.ts +13 -0
- package/dist/src/functions/case.d.ts.map +1 -0
- package/dist/src/functions/case.js +17 -0
- package/dist/src/functions/case.js.map +1 -0
- package/dist/src/functions/cast.d.ts +23 -0
- package/dist/src/functions/cast.d.ts.map +1 -0
- package/dist/src/functions/cast.js +32 -0
- package/dist/src/functions/cast.js.map +1 -0
- package/dist/src/functions/collate.d.ts +10 -0
- package/dist/src/functions/collate.d.ts.map +1 -0
- package/dist/src/functions/collate.js +12 -0
- package/dist/src/functions/collate.js.map +1 -0
- package/dist/src/functions/column.d.ts +10 -0
- package/dist/src/functions/column.d.ts.map +1 -0
- package/dist/src/functions/column.js +17 -0
- package/dist/src/functions/column.js.map +1 -0
- package/dist/src/functions/cte.d.ts +13 -0
- package/dist/src/functions/cte.d.ts.map +1 -0
- package/dist/src/functions/cte.js +14 -0
- package/dist/src/functions/cte.js.map +1 -0
- package/dist/src/functions/datetime.d.ts +32 -0
- package/dist/src/functions/datetime.d.ts.map +1 -0
- package/dist/src/functions/datetime.js +45 -0
- package/dist/src/functions/datetime.js.map +1 -0
- package/dist/src/functions/interval.d.ts +48 -0
- package/dist/src/functions/interval.d.ts.map +1 -0
- package/dist/src/functions/interval.js +66 -0
- package/dist/src/functions/interval.js.map +1 -0
- package/dist/src/functions/list.d.ts +31 -0
- package/dist/src/functions/list.d.ts.map +1 -0
- package/dist/src/functions/list.js +49 -0
- package/dist/src/functions/list.js.map +1 -0
- package/dist/src/functions/literal.d.ts +16 -0
- package/dist/src/functions/literal.d.ts.map +1 -0
- package/dist/src/functions/literal.js +20 -0
- package/dist/src/functions/literal.js.map +1 -0
- package/dist/src/functions/numeric.d.ts +80 -0
- package/dist/src/functions/numeric.d.ts.map +1 -0
- package/dist/src/functions/numeric.js +110 -0
- package/dist/src/functions/numeric.js.map +1 -0
- package/dist/src/functions/operators.d.ts +169 -0
- package/dist/src/functions/operators.d.ts.map +1 -0
- package/dist/src/functions/operators.js +235 -0
- package/dist/src/functions/operators.js.map +1 -0
- package/dist/src/functions/order-by.d.ts +15 -0
- package/dist/src/functions/order-by.d.ts.map +1 -0
- package/dist/src/functions/order-by.js +19 -0
- package/dist/src/functions/order-by.js.map +1 -0
- package/dist/src/functions/spatial.d.ts +32 -0
- package/dist/src/functions/spatial.d.ts.map +1 -0
- package/dist/src/functions/spatial.js +44 -0
- package/dist/src/functions/spatial.js.map +1 -0
- package/dist/src/functions/sql-template-tag.d.ts +13 -0
- package/dist/src/functions/sql-template-tag.d.ts.map +1 -0
- package/dist/src/functions/sql-template-tag.js +44 -0
- package/dist/src/functions/sql-template-tag.js.map +1 -0
- package/dist/src/functions/string.d.ts +49 -0
- package/dist/src/functions/string.d.ts.map +1 -0
- package/dist/src/functions/string.js +67 -0
- package/dist/src/functions/string.js.map +1 -0
- package/dist/src/functions/table-ref.d.ts +10 -0
- package/dist/src/functions/table-ref.d.ts.map +1 -0
- package/dist/src/functions/table-ref.js +13 -0
- package/dist/src/functions/table-ref.js.map +1 -0
- package/dist/src/functions/unnest.d.ts +10 -0
- package/dist/src/functions/unnest.d.ts.map +1 -0
- package/dist/src/functions/unnest.js +12 -0
- package/dist/src/functions/unnest.js.map +1 -0
- package/dist/src/functions/util.d.ts +7 -0
- package/dist/src/functions/util.d.ts.map +1 -0
- package/dist/src/functions/util.js +9 -0
- package/dist/src/functions/util.js.map +1 -0
- package/dist/src/functions/window-frame.d.ts +41 -0
- package/dist/src/functions/window-frame.d.ts.map +1 -0
- package/dist/src/functions/window-frame.js +52 -0
- package/dist/src/functions/window-frame.js.map +1 -0
- package/dist/src/functions/window.d.ts +74 -0
- package/dist/src/functions/window.d.ts.map +1 -0
- package/dist/src/functions/window.js +96 -0
- package/dist/src/functions/window.js.map +1 -0
- package/dist/src/index.d.ts +73 -0
- package/dist/src/index.d.ts.map +1 -0
- package/{src → dist/src}/index.js +8 -8
- package/dist/src/index.js.map +1 -0
- package/dist/src/load/create.d.ts +10 -0
- package/dist/src/load/create.d.ts.map +1 -0
- package/dist/src/load/create.js +14 -0
- package/dist/src/load/create.js.map +1 -0
- package/dist/src/load/extension.d.ts +2 -0
- package/dist/src/load/extension.d.ts.map +1 -0
- package/dist/src/load/extension.js +4 -0
- package/dist/src/load/extension.js.map +1 -0
- package/dist/src/load/load.d.ts +18 -0
- package/dist/src/load/load.d.ts.map +1 -0
- package/dist/src/load/load.js +80 -0
- package/dist/src/load/load.js.map +1 -0
- package/dist/src/load/sql-from.d.ts +14 -0
- package/dist/src/load/sql-from.d.ts.map +1 -0
- package/dist/src/load/sql-from.js +29 -0
- package/dist/src/load/sql-from.js.map +1 -0
- package/dist/src/transforms/bin-1d.d.ts +16 -0
- package/dist/src/transforms/bin-1d.d.ts.map +1 -0
- package/dist/src/transforms/bin-1d.js +21 -0
- package/dist/src/transforms/bin-1d.js.map +1 -0
- package/dist/src/transforms/bin-2d.d.ts +19 -0
- package/dist/src/transforms/bin-2d.d.ts.map +1 -0
- package/dist/src/transforms/bin-2d.js +27 -0
- package/dist/src/transforms/bin-2d.js.map +1 -0
- package/dist/src/transforms/bin-date.d.ts +31 -0
- package/dist/src/transforms/bin-date.d.ts.map +1 -0
- package/dist/src/transforms/bin-date.js +20 -0
- package/dist/src/transforms/bin-date.js.map +1 -0
- package/dist/src/transforms/bin-histogram.d.ts +37 -0
- package/dist/src/transforms/bin-histogram.d.ts.map +1 -0
- package/dist/src/transforms/bin-histogram.js +32 -0
- package/dist/src/transforms/bin-histogram.js.map +1 -0
- package/dist/src/transforms/bin-linear-1d.d.ts +11 -0
- package/dist/src/transforms/bin-linear-1d.d.ts.map +1 -0
- package/dist/src/transforms/bin-linear-1d.js +25 -0
- package/dist/src/transforms/bin-linear-1d.js.map +1 -0
- package/dist/src/transforms/bin-linear-2d.d.ts +20 -0
- package/dist/src/transforms/bin-linear-2d.d.ts.map +1 -0
- package/dist/src/transforms/bin-linear-2d.js +49 -0
- package/dist/src/transforms/bin-linear-2d.js.map +1 -0
- package/dist/src/transforms/filter-query.d.ts +12 -0
- package/dist/src/transforms/filter-query.d.ts.map +1 -0
- package/dist/src/transforms/filter-query.js +39 -0
- package/dist/src/transforms/filter-query.js.map +1 -0
- package/dist/src/transforms/line-density.d.ts +24 -0
- package/dist/src/transforms/line-density.d.ts.map +1 -0
- package/dist/src/transforms/line-density.js +98 -0
- package/dist/src/transforms/line-density.js.map +1 -0
- package/dist/src/transforms/m4.d.ts +19 -0
- package/dist/src/transforms/m4.d.ts.map +1 -0
- package/dist/src/transforms/m4.js +38 -0
- package/dist/src/transforms/m4.js.map +1 -0
- package/dist/src/transforms/scales.d.ts +30 -0
- package/dist/src/transforms/scales.d.ts.map +1 -0
- package/dist/src/transforms/scales.js +103 -0
- package/dist/src/transforms/scales.js.map +1 -0
- package/dist/src/transforms/util/bin-step.d.ts +50 -0
- package/dist/src/transforms/util/bin-step.d.ts.map +1 -0
- package/dist/src/transforms/util/bin-step.js +53 -0
- package/dist/src/transforms/util/bin-step.js.map +1 -0
- package/dist/src/transforms/util/time-interval.d.ts +14 -0
- package/dist/src/transforms/util/time-interval.d.ts.map +1 -0
- package/dist/src/transforms/util/time-interval.js +88 -0
- package/dist/src/transforms/util/time-interval.js.map +1 -0
- package/dist/src/types.d.ts +49 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/util/ast.d.ts +62 -0
- package/dist/src/util/ast.d.ts.map +1 -0
- package/{src → dist/src}/util/ast.js +36 -41
- package/dist/src/util/ast.js.map +1 -0
- package/dist/src/util/function.d.ts +56 -0
- package/dist/src/util/function.d.ts.map +1 -0
- package/dist/src/util/function.js +73 -0
- package/dist/src/util/function.js.map +1 -0
- package/dist/src/util/identity.d.ts +6 -0
- package/dist/src/util/identity.d.ts.map +1 -0
- package/dist/src/util/identity.js +8 -0
- package/dist/src/util/identity.js.map +1 -0
- package/dist/src/util/string.d.ts +4 -0
- package/dist/src/util/string.d.ts.map +1 -0
- package/dist/src/util/string.js +14 -0
- package/dist/src/util/string.js.map +1 -0
- package/dist/src/util/type-check.d.ts +17 -0
- package/dist/src/util/type-check.d.ts.map +1 -0
- package/dist/src/util/type-check.js +28 -0
- package/dist/src/util/type-check.js.map +1 -0
- package/dist/src/visit/clone.d.ts +7 -0
- package/dist/src/visit/clone.d.ts.map +1 -0
- package/dist/src/visit/clone.js +52 -0
- package/dist/src/visit/clone.js.map +1 -0
- package/dist/src/visit/recurse.d.ts +2 -0
- package/dist/src/visit/recurse.d.ts.map +1 -0
- package/dist/src/visit/recurse.js +37 -0
- package/dist/src/visit/recurse.js.map +1 -0
- package/dist/src/visit/rewrite.d.ts +9 -0
- package/dist/src/visit/rewrite.d.ts.map +1 -0
- package/dist/src/visit/rewrite.js +39 -0
- package/dist/src/visit/rewrite.js.map +1 -0
- package/dist/src/visit/visitors.d.ts +32 -0
- package/dist/src/visit/visitors.d.ts.map +1 -0
- package/dist/src/visit/visitors.js +95 -0
- package/dist/src/visit/visitors.js.map +1 -0
- package/dist/src/visit/walk.d.ts +21 -0
- package/dist/src/visit/walk.d.ts.map +1 -0
- package/dist/src/visit/walk.js +32 -0
- package/dist/src/visit/walk.js.map +1 -0
- package/package.json +13 -7
- package/src/ast/{aggregate.js → aggregate.ts} +49 -60
- package/src/ast/{between-op.js → between-op.ts} +19 -26
- package/src/ast/binary-op.ts +31 -0
- package/src/ast/{case.js → case.ts} +29 -44
- package/src/ast/{cast.js → cast.ts} +8 -14
- package/src/ast/{collate.js → collate.ts} +8 -14
- package/src/ast/column-param.ts +34 -0
- package/src/ast/{column-ref.js → column-ref.ts} +16 -25
- package/src/ast/fragment.ts +28 -0
- package/src/ast/{from.js → from.ts} +12 -21
- package/src/ast/{function.js → function.ts} +8 -14
- package/src/ast/{in-op.js → in-op.ts} +8 -14
- package/src/ast/{interval.js → interval.ts} +8 -14
- package/src/ast/list.ts +23 -0
- package/src/ast/{literal.js → literal.ts} +6 -9
- package/src/ast/logical-op.ts +50 -0
- package/src/ast/{node.js → node.ts} +10 -13
- package/src/ast/order-by.ts +38 -0
- package/src/ast/{param.js → param.ts} +6 -12
- package/src/ast/{query.js → query.ts} +224 -204
- package/src/ast/sample.ts +47 -0
- package/src/ast/{select.js → select.ts} +10 -16
- package/src/ast/{subquery.js → subquery.ts} +9 -8
- package/src/ast/{table-ref.js → table-ref.ts} +7 -12
- package/src/ast/{unary-op.js → unary-op.ts} +16 -23
- package/src/ast/unnest.ts +31 -0
- package/src/ast/verbatim.ts +27 -0
- package/src/ast/{window-frame.js → window-frame.ts} +37 -47
- package/src/ast/window.ts +246 -0
- package/src/ast/{with.js → with.ts} +19 -20
- package/src/{constants.js → constants.ts} +2 -0
- package/src/functions/aggregate.ts +344 -0
- package/src/functions/{case.js → case.ts} +5 -8
- package/src/functions/{cast.js → cast.ts} +9 -13
- package/src/functions/{collate.js → collate.ts} +4 -7
- package/src/functions/{column.js → column.ts} +9 -10
- package/src/functions/{cte.js → cte.ts} +9 -6
- package/src/functions/{datetime.js → datetime.ts} +12 -20
- package/src/functions/interval.ts +74 -0
- package/src/functions/list.ts +63 -0
- package/src/functions/{literal.js → literal.ts} +5 -7
- package/src/functions/numeric.ts +125 -0
- package/src/functions/operators.ts +272 -0
- package/src/functions/order-by.ts +21 -0
- package/src/functions/spatial.ts +50 -0
- package/src/functions/{sql-template-tag.js → sql-template-tag.ts} +16 -13
- package/src/functions/string.ts +79 -0
- package/src/functions/{table-ref.js → table-ref.ts} +4 -4
- package/src/functions/unnest.ts +13 -0
- package/src/functions/util.ts +10 -0
- package/src/functions/window-frame.ts +58 -0
- package/src/functions/{window.js → window.ts} +18 -35
- package/src/index.ts +79 -0
- package/src/load/{create.js → create.ts} +9 -3
- package/src/load/extension.ts +3 -0
- package/src/load/{load.js → load.ts} +25 -10
- package/src/load/{sql-from.js → sql-from.ts} +14 -7
- package/src/transforms/{bin-1d.js → bin-1d.ts} +13 -9
- package/src/transforms/{bin-2d.js → bin-2d.ts} +17 -13
- package/src/transforms/bin-date.ts +48 -0
- package/src/transforms/bin-histogram.ts +61 -0
- package/src/transforms/{bin-linear-1d.js → bin-linear-1d.ts} +16 -11
- package/src/transforms/{bin-linear-2d.js → bin-linear-2d.ts} +23 -35
- package/src/transforms/{filter-query.js → filter-query.ts} +10 -14
- package/src/transforms/{line-density.js → line-density.ts} +19 -17
- package/src/transforms/{m4.js → m4.ts} +17 -14
- package/src/transforms/{scales.js → scales.ts} +57 -14
- package/src/transforms/util/bin-step.ts +100 -0
- package/src/transforms/util/{time-interval.js → time-interval.ts} +32 -21
- package/src/types.ts +5 -39
- package/src/util/ast.ts +104 -0
- package/src/util/{function.js → function.ts} +40 -31
- package/src/util/identity.ts +7 -0
- package/src/util/{string.js → string.ts} +4 -4
- package/src/util/type-check.ts +31 -0
- package/src/visit/{clone.js → clone.ts} +10 -10
- package/src/visit/{recurse.js → recurse.ts} +3 -1
- package/src/visit/{rewrite.js → rewrite.ts} +7 -7
- package/src/visit/{visitors.js → visitors.ts} +22 -30
- package/src/visit/walk.ts +46 -0
- package/src/ast/binary-op.js +0 -40
- package/src/ast/column-param.js +0 -40
- package/src/ast/fragment.js +0 -26
- package/src/ast/logical-op.js +0 -67
- package/src/ast/order-by.js +0 -48
- package/src/ast/sample.js +0 -53
- package/src/ast/verbatim.js +0 -33
- package/src/ast/window.js +0 -260
- package/src/functions/aggregate.js +0 -347
- package/src/functions/interval.js +0 -83
- package/src/functions/numeric.js +0 -143
- package/src/functions/operators.js +0 -301
- package/src/functions/order-by.js +0 -27
- package/src/functions/spatial.js +0 -59
- package/src/functions/string.js +0 -85
- package/src/functions/util.js +0 -14
- package/src/functions/window-frame.js +0 -61
- package/src/index-types.ts +0 -2
- package/src/load/extension.js +0 -3
- package/src/transforms/bin-date.js +0 -38
- package/src/transforms/bin-histogram.js +0 -52
- package/src/transforms/util/bin-step.js +0 -79
- package/src/util/type-check.js +0 -33
- package/src/visit/walk.js +0 -34
- package/tsconfig.json +0 -8
- package/vitest.config.ts +0 -3
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* @import { SampleMethod } from './sample.js'
|
|
4
|
-
*/
|
|
1
|
+
import type { FilterExpr, FromExpr, GroupByExpr, MaybeArray, OrderByExpr, SelectExpr, WithExpr } from '../types.js';
|
|
2
|
+
import type { SampleMethod } from './sample.js';
|
|
5
3
|
import { DESCRIBE_QUERY, SELECT_QUERY, SET_OPERATION } from '../constants.js';
|
|
6
|
-
import { asNode,
|
|
7
|
-
import { exprList } from '../util/function.js';
|
|
4
|
+
import { asNode, asVerbatim, maybeTableRef } from '../util/ast.js';
|
|
5
|
+
import { exprList, nodeList } from '../util/function.js';
|
|
8
6
|
import { unquote } from '../util/string.js';
|
|
9
7
|
import { isArray, isString } from '../util/type-check.js';
|
|
10
8
|
import { isColumnRef } from './column-ref.js';
|
|
@@ -13,161 +11,173 @@ import { ExprNode, SQLNode, isNode } from './node.js';
|
|
|
13
11
|
import { SampleClauseNode } from './sample.js';
|
|
14
12
|
import { SelectClauseNode } from './select.js';
|
|
15
13
|
import { isTableRef } from './table-ref.js';
|
|
16
|
-
import { WindowClauseNode } from './window.js';
|
|
14
|
+
import { WindowClauseNode, type WindowDefNode } from './window.js';
|
|
17
15
|
import { WithClauseNode } from './with.js';
|
|
18
16
|
|
|
19
17
|
/**
|
|
20
18
|
* Check if a value is a selection query or set operation.
|
|
21
|
-
* @param
|
|
22
|
-
* @returns {value is Query}
|
|
19
|
+
* @param value The value to check.
|
|
23
20
|
*/
|
|
24
|
-
export function isQuery(value) {
|
|
21
|
+
export function isQuery(value: unknown): value is Query {
|
|
25
22
|
return value instanceof Query;
|
|
26
23
|
}
|
|
27
24
|
|
|
28
25
|
/**
|
|
29
26
|
* Check if a value is a selection query.
|
|
30
|
-
* @param
|
|
31
|
-
* @returns {value is SelectQuery}
|
|
27
|
+
* @param value The value to check.
|
|
32
28
|
*/
|
|
33
|
-
export function isSelectQuery(value) {
|
|
29
|
+
export function isSelectQuery(value: unknown): value is SelectQuery {
|
|
34
30
|
return value instanceof SelectQuery;
|
|
35
31
|
}
|
|
36
32
|
|
|
37
33
|
/**
|
|
38
34
|
* Check if a value is a describe query.
|
|
39
|
-
* @param
|
|
40
|
-
* @returns {value is DescribeQuery}
|
|
35
|
+
* @param value The value to check.
|
|
41
36
|
*/
|
|
42
|
-
export function isDescribeQuery(value) {
|
|
37
|
+
export function isDescribeQuery(value: unknown): value is DescribeQuery {
|
|
43
38
|
return value instanceof DescribeQuery;
|
|
44
39
|
}
|
|
45
40
|
|
|
46
41
|
export class Query extends ExprNode {
|
|
47
42
|
/**
|
|
48
43
|
* Create a new WITH clause with the given CTE queries.
|
|
49
|
-
* @param
|
|
50
|
-
* @returns {WithClause}
|
|
44
|
+
* @param expr The WITH CTE queries.
|
|
51
45
|
*/
|
|
52
|
-
static with(...expr) {
|
|
46
|
+
static with(...expr: WithExpr[]) {
|
|
53
47
|
return new WithClause(...expr);
|
|
54
48
|
}
|
|
55
49
|
|
|
56
50
|
/**
|
|
57
51
|
* Create a new select query with the given SELECT expressions.
|
|
58
|
-
* @param
|
|
59
|
-
* @returns {SelectQuery}
|
|
52
|
+
* @param expr The SELECT expressions.
|
|
60
53
|
*/
|
|
61
|
-
static select(...expr) {
|
|
54
|
+
static select(...expr: SelectExpr[]) {
|
|
62
55
|
return new SelectQuery().select(...expr);
|
|
63
56
|
}
|
|
64
57
|
|
|
65
58
|
/**
|
|
66
59
|
* Create a new select query with the given FROM expressions.
|
|
67
|
-
* @param
|
|
68
|
-
* @returns {SelectQuery}
|
|
60
|
+
* @param expr The FROM expressions.
|
|
69
61
|
*/
|
|
70
|
-
static from(...expr) {
|
|
62
|
+
static from(...expr: FromExpr[]) {
|
|
71
63
|
return new SelectQuery().from(...expr);
|
|
72
64
|
}
|
|
73
65
|
|
|
74
66
|
/**
|
|
75
67
|
* Create a new UNION set operation over the given queries.
|
|
76
|
-
* @param
|
|
77
|
-
* @returns {SetOperation}
|
|
68
|
+
* @param queries The queries.
|
|
78
69
|
*/
|
|
79
|
-
static union(...queries) {
|
|
70
|
+
static union(...queries: MaybeArray<Query>[]) {
|
|
80
71
|
return new SetOperation('UNION', queries.flat());
|
|
81
72
|
}
|
|
82
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Create a new UNION BY NAME set operation over the given queries.
|
|
76
|
+
* @param queries The queries.
|
|
77
|
+
*/
|
|
78
|
+
static unionByName(...queries: MaybeArray<Query>[]) {
|
|
79
|
+
return new SetOperation('UNION BY NAME', queries.flat());
|
|
80
|
+
}
|
|
81
|
+
|
|
83
82
|
/**
|
|
84
83
|
* Create a new UNION ALL set operation over the given queries.
|
|
85
|
-
* @param
|
|
86
|
-
* @returns {SetOperation}
|
|
84
|
+
* @param queries The queries.
|
|
87
85
|
*/
|
|
88
|
-
static unionAll(...queries) {
|
|
86
|
+
static unionAll(...queries: MaybeArray<Query>[]) {
|
|
89
87
|
return new SetOperation('UNION ALL', queries.flat());
|
|
90
88
|
}
|
|
91
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Create a new UNION ALL BY NAME set operation over the given queries.
|
|
92
|
+
* @param queries The queries.
|
|
93
|
+
*/
|
|
94
|
+
static unionAllByName(...queries: MaybeArray<Query>[]) {
|
|
95
|
+
return new SetOperation('UNION ALL BY NAME', queries.flat());
|
|
96
|
+
}
|
|
97
|
+
|
|
92
98
|
/**
|
|
93
99
|
* Create a new INTERSECT set operation over the given queries.
|
|
94
|
-
* @param
|
|
95
|
-
* @returns {SetOperation}
|
|
100
|
+
* @param queries The queries.
|
|
96
101
|
*/
|
|
97
|
-
static intersect(...queries) {
|
|
102
|
+
static intersect(...queries: MaybeArray<Query>[]) {
|
|
98
103
|
return new SetOperation('INTERSECT', queries.flat());
|
|
99
104
|
}
|
|
100
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Create a new INTERSECT ALL set operation over the given queries.
|
|
108
|
+
* @param queries The queries.
|
|
109
|
+
*/
|
|
110
|
+
static intersectAll(...queries: MaybeArray<Query>[]) {
|
|
111
|
+
return new SetOperation('INTERSECT ALL', queries.flat());
|
|
112
|
+
}
|
|
113
|
+
|
|
101
114
|
/**
|
|
102
115
|
* Create a new EXCEPT set operation over the given queries.
|
|
103
|
-
* @param
|
|
104
|
-
* @returns {SetOperation}
|
|
116
|
+
* @param queries The queries.
|
|
105
117
|
*/
|
|
106
|
-
static except(...queries) {
|
|
118
|
+
static except(...queries: MaybeArray<Query>[]) {
|
|
107
119
|
return new SetOperation('EXCEPT', queries.flat());
|
|
108
120
|
}
|
|
109
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Create a new EXCEPT ALL set operation over the given queries.
|
|
124
|
+
* @param queries The queries.
|
|
125
|
+
*/
|
|
126
|
+
static exceptAll(...queries: MaybeArray<Query>[]) {
|
|
127
|
+
return new SetOperation('EXCEPT ALL', queries.flat());
|
|
128
|
+
}
|
|
129
|
+
|
|
110
130
|
/**
|
|
111
131
|
* Create a new describe query for the given input query.
|
|
112
|
-
* @param
|
|
113
|
-
* @returns {DescribeQuery}
|
|
132
|
+
* @param query The query to describe.
|
|
114
133
|
*/
|
|
115
|
-
static describe(query) {
|
|
134
|
+
static describe(query: Query) {
|
|
116
135
|
return new DescribeQuery(query);
|
|
117
136
|
}
|
|
118
137
|
|
|
138
|
+
_with: WithClauseNode[] = [];
|
|
139
|
+
_orderby: ExprNode[] = [];
|
|
140
|
+
_limitPerc: boolean = false;
|
|
141
|
+
_limit?: ExprNode;
|
|
142
|
+
_offset?: ExprNode;
|
|
143
|
+
cteFor?: Query | null = null;
|
|
144
|
+
|
|
119
145
|
/**
|
|
120
146
|
* Instantiate a new query.
|
|
121
147
|
*/
|
|
122
|
-
constructor(type) {
|
|
148
|
+
constructor(type: string) {
|
|
123
149
|
super(type);
|
|
124
|
-
/** @type {WithClauseNode[]} */
|
|
125
|
-
this._with = [];
|
|
126
|
-
/** @type {ExprNode[]} */
|
|
127
|
-
this._orderby = [];
|
|
128
|
-
/** @type {boolean} */
|
|
129
|
-
this._limitPerc = false;
|
|
130
|
-
/** @type {ExprNode} */
|
|
131
|
-
this._limit = undefined;
|
|
132
|
-
/** @type {ExprNode} */
|
|
133
|
-
this._offset = undefined;
|
|
134
|
-
/** @type {Query | null} */
|
|
135
|
-
this.cteFor = null;
|
|
136
150
|
}
|
|
137
151
|
|
|
138
152
|
/**
|
|
139
153
|
* Return a list of subqueries.
|
|
140
|
-
* @returns {Query[]}
|
|
141
154
|
*/
|
|
142
|
-
get subqueries() {
|
|
155
|
+
get subqueries(): Query[] {
|
|
143
156
|
return [];
|
|
144
157
|
}
|
|
145
158
|
|
|
146
159
|
/**
|
|
147
160
|
* Clone this query.
|
|
148
|
-
* @returns {this}
|
|
149
161
|
*/
|
|
150
|
-
clone() {
|
|
162
|
+
clone(): this {
|
|
151
163
|
return this;
|
|
152
164
|
}
|
|
153
165
|
|
|
154
166
|
/**
|
|
155
167
|
* Add a pointer to the query for which this query is a CTE.
|
|
156
|
-
* @param
|
|
168
|
+
* @param query The query for which this query is a CTE.
|
|
157
169
|
*/
|
|
158
|
-
setCteFor(query) {
|
|
170
|
+
setCteFor(query: Query | null): void {
|
|
159
171
|
this.cteFor = query;
|
|
160
172
|
}
|
|
161
173
|
|
|
162
174
|
/**
|
|
163
175
|
* Add WITH common table expressions (CTEs).
|
|
164
|
-
* @param
|
|
165
|
-
* @returns {this}
|
|
176
|
+
* @param expr Expressions to add.
|
|
166
177
|
*/
|
|
167
|
-
with(...expr) {
|
|
168
|
-
|
|
169
|
-
const
|
|
170
|
-
const add = (name, q) => {
|
|
178
|
+
with(...expr: WithExpr[]): this {
|
|
179
|
+
const list: WithClauseNode[] = [];
|
|
180
|
+
const add = (name: string, q: Query) => {
|
|
171
181
|
const query = q.clone();
|
|
172
182
|
query.setCteFor(this);
|
|
173
183
|
list.push(new WithClauseNode(name, query));
|
|
@@ -182,20 +192,18 @@ export class Query extends ExprNode {
|
|
|
182
192
|
|
|
183
193
|
/**
|
|
184
194
|
* Add ORDER BY expressions.
|
|
185
|
-
* @param
|
|
186
|
-
* @returns
|
|
195
|
+
* @param expr Expressions to add.
|
|
187
196
|
*/
|
|
188
|
-
orderby(...expr) {
|
|
189
|
-
this._orderby = this._orderby.concat(
|
|
197
|
+
orderby(...expr: OrderByExpr[]): this {
|
|
198
|
+
this._orderby = this._orderby.concat(nodeList(expr));
|
|
190
199
|
return this;
|
|
191
200
|
}
|
|
192
201
|
|
|
193
202
|
/**
|
|
194
203
|
* Set the query result LIMIT as a percentage value.
|
|
195
|
-
* @param
|
|
196
|
-
* @returns {this}
|
|
204
|
+
* @param value The limit percentage value.
|
|
197
205
|
*/
|
|
198
|
-
limitPercent(value) {
|
|
206
|
+
limitPercent(value: number | ExprNode): this {
|
|
199
207
|
this._limitPerc = true;
|
|
200
208
|
this._limit = asNode(value);
|
|
201
209
|
return this;
|
|
@@ -203,10 +211,9 @@ export class Query extends ExprNode {
|
|
|
203
211
|
|
|
204
212
|
/**
|
|
205
213
|
* Set the query result LIMIT.
|
|
206
|
-
* @param
|
|
207
|
-
* @returns {this}
|
|
214
|
+
* @param value The limit value.
|
|
208
215
|
*/
|
|
209
|
-
limit(value) {
|
|
216
|
+
limit(value: number | ExprNode): this {
|
|
210
217
|
this._limitPerc = false;
|
|
211
218
|
this._limit = asNode(value);
|
|
212
219
|
return this;
|
|
@@ -214,52 +221,47 @@ export class Query extends ExprNode {
|
|
|
214
221
|
|
|
215
222
|
/**
|
|
216
223
|
* Set the query result OFFSET.
|
|
217
|
-
* @param
|
|
218
|
-
* @returns {this}
|
|
224
|
+
* @param value The offset value.
|
|
219
225
|
*/
|
|
220
|
-
offset(value) {
|
|
226
|
+
offset(value: number | ExprNode): this {
|
|
221
227
|
this._offset = asNode(value);
|
|
222
228
|
return this;
|
|
223
229
|
}
|
|
224
230
|
}
|
|
225
231
|
|
|
226
232
|
export class SelectQuery extends Query {
|
|
233
|
+
_select: SelectClauseNode[] = [];
|
|
234
|
+
_from: FromClauseNode[] = [];
|
|
235
|
+
_where: ExprNode[] = [];
|
|
236
|
+
_sample?: SampleClauseNode;
|
|
237
|
+
_groupby: ExprNode[] = [];
|
|
238
|
+
_having: ExprNode[] = [];
|
|
239
|
+
_window: WindowClauseNode[] = [];
|
|
240
|
+
_qualify: ExprNode[] = [];
|
|
241
|
+
_distinct: boolean = false;
|
|
242
|
+
|
|
227
243
|
/**
|
|
228
244
|
* Instantiate a new select query.
|
|
229
245
|
*/
|
|
230
246
|
constructor() {
|
|
231
247
|
super(SELECT_QUERY);
|
|
232
|
-
/** @type {SelectClauseNode[]} */
|
|
233
|
-
this._select = [];
|
|
234
|
-
/** @type {FromClauseNode[]} */
|
|
235
|
-
this._from = [];
|
|
236
|
-
/** @type {ExprNode[]} */
|
|
237
|
-
this._where = [];
|
|
238
|
-
/** @type {SampleClauseNode} */
|
|
239
|
-
this._sample = undefined;
|
|
240
|
-
/** @type {ExprNode[]} */
|
|
241
|
-
this._groupby = [];
|
|
242
|
-
/** @type {ExprNode[]} */
|
|
243
|
-
this._having = [];
|
|
244
|
-
/** @type {WindowClauseNode[]} */
|
|
245
|
-
this._window = [];
|
|
246
|
-
/** @type {ExprNode[]} */
|
|
247
|
-
this._qualify = [];
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
/**
|
|
251
251
|
* Return a list of subqueries.
|
|
252
|
-
* @returns {Query[]}
|
|
253
252
|
*/
|
|
254
|
-
get subqueries() {
|
|
253
|
+
get subqueries(): Query[] {
|
|
255
254
|
// build map of ctes within base query WITH clause
|
|
256
255
|
const q = this.cteFor || this;
|
|
257
256
|
const w = q instanceof SelectQuery ? q._with : [];
|
|
258
|
-
const cte = w.reduce(
|
|
257
|
+
const cte = w.reduce(
|
|
258
|
+
(obj, c) => (obj[c.name] = c.query, obj),
|
|
259
|
+
{} as Record<string, Query>
|
|
260
|
+
);
|
|
259
261
|
|
|
260
262
|
// extract subqueries in FROM clause
|
|
261
263
|
// unused CTEs will be ignored
|
|
262
|
-
const queries = [];
|
|
264
|
+
const queries: Query[] = [];
|
|
263
265
|
this._from.forEach(({ expr }) => {
|
|
264
266
|
if (isQuery(expr)) {
|
|
265
267
|
queries.push(expr);
|
|
@@ -273,66 +275,67 @@ export class SelectQuery extends Query {
|
|
|
273
275
|
|
|
274
276
|
/**
|
|
275
277
|
* Clone this query.
|
|
276
|
-
* @returns {this}
|
|
277
278
|
*/
|
|
278
|
-
clone() {
|
|
279
|
+
clone(): this {
|
|
279
280
|
return Object.assign(new SelectQuery(), this);
|
|
280
281
|
}
|
|
281
282
|
|
|
282
283
|
/**
|
|
283
284
|
* Add SELECT expressions.
|
|
284
|
-
* @param
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
const add = (v, as) =>
|
|
291
|
-
|
|
292
|
-
|
|
285
|
+
* @param expr Expressions to add.
|
|
286
|
+
*/
|
|
287
|
+
select(...expr: SelectExpr[]): this {
|
|
288
|
+
const keys: Set<string> = new Set;
|
|
289
|
+
const list: SelectClauseNode[] = [];
|
|
290
|
+
|
|
291
|
+
const add = (v: unknown, as: string) => {
|
|
292
|
+
const key = unquote(as)!;
|
|
293
|
+
keys.add(key);
|
|
294
|
+
if (v) list.push(new SelectClauseNode(asNode(v), key));
|
|
295
|
+
};
|
|
296
|
+
|
|
293
297
|
expr.flat().forEach(e => {
|
|
294
298
|
if (e == null) return;
|
|
295
299
|
else if (isString(e)) add(e, e);
|
|
296
300
|
else if (isColumnRef(e)) add(e, e.column);
|
|
297
301
|
else if (isArray(e)) add(e[1], e[0]);
|
|
302
|
+
else if (isNode(e)) add(e, `${e}`);
|
|
298
303
|
else for (const alias in e) add(e[alias], alias);
|
|
299
304
|
});
|
|
300
305
|
|
|
301
|
-
|
|
302
|
-
this._select = this._select
|
|
303
|
-
.filter(x => x.alias && !keys.has(x.alias))
|
|
304
|
-
.concat(list.filter(x => x.expr));
|
|
306
|
+
this._select = this._select.filter(x => !keys.has(x.alias)).concat(list);
|
|
305
307
|
return this;
|
|
306
308
|
}
|
|
307
309
|
|
|
308
310
|
/**
|
|
309
311
|
* Set SELECT expressions, replacing any prior expressions.
|
|
310
|
-
* @param
|
|
311
|
-
* @returns {this}
|
|
312
|
+
* @param expr Expressions to add.
|
|
312
313
|
*/
|
|
313
|
-
setSelect(...expr) {
|
|
314
|
+
setSelect(...expr: SelectExpr[]): this {
|
|
314
315
|
this._select = [];
|
|
315
316
|
return this.select(...expr);
|
|
316
317
|
}
|
|
317
318
|
|
|
318
319
|
/**
|
|
319
320
|
* Indicate if this query should retrieve distinct values only.
|
|
320
|
-
* @param
|
|
321
|
-
* @returns {this}
|
|
321
|
+
* @param value The distinct flag
|
|
322
322
|
*/
|
|
323
|
-
distinct(value = true) {
|
|
323
|
+
distinct(value: boolean = true): this {
|
|
324
324
|
this._distinct = !!value;
|
|
325
325
|
return this;
|
|
326
326
|
}
|
|
327
327
|
|
|
328
328
|
/**
|
|
329
329
|
* Add table FROM expressions.
|
|
330
|
-
* @param
|
|
331
|
-
* @returns {this}
|
|
330
|
+
* @param expr Expressions to add.
|
|
332
331
|
*/
|
|
333
|
-
from(...expr) {
|
|
334
|
-
const list = [];
|
|
335
|
-
|
|
332
|
+
from(...expr: FromExpr[]): this {
|
|
333
|
+
const list: FromClauseNode[] = [];
|
|
334
|
+
|
|
335
|
+
const add = (v: string | string[] | SQLNode, as?: string) => {
|
|
336
|
+
list.push(new FromClauseNode(maybeTableRef(v), unquote(as)));
|
|
337
|
+
};
|
|
338
|
+
|
|
336
339
|
expr.flat().forEach(e => {
|
|
337
340
|
if (e == null) return;
|
|
338
341
|
else if (e instanceof FromClauseNode) list.push(e);
|
|
@@ -348,24 +351,25 @@ export class SelectQuery extends Query {
|
|
|
348
351
|
|
|
349
352
|
/**
|
|
350
353
|
* Set FROM expressions, replacing any prior expressions.
|
|
351
|
-
* @param
|
|
352
|
-
* @returns {this}
|
|
354
|
+
* @param expr Expressions to add.
|
|
353
355
|
*/
|
|
354
|
-
setFrom(...expr) {
|
|
356
|
+
setFrom(...expr: FromExpr[]): this {
|
|
355
357
|
this._from = [];
|
|
356
358
|
return this.from(...expr);
|
|
357
359
|
}
|
|
358
360
|
|
|
359
361
|
/**
|
|
360
362
|
* Set SAMPLE settings.
|
|
361
|
-
* @param
|
|
362
|
-
*
|
|
363
|
-
* @param
|
|
364
|
-
*
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
363
|
+
* @param value Either a sample clause node or the sample size as either
|
|
364
|
+
* a row count or percentage.
|
|
365
|
+
* @param method The sampling method to use.
|
|
366
|
+
* @param seed The random seed.
|
|
367
|
+
*/
|
|
368
|
+
sample(
|
|
369
|
+
value?: number | SampleClauseNode | null,
|
|
370
|
+
method?: SampleMethod,
|
|
371
|
+
seed?: number
|
|
372
|
+
): this {
|
|
369
373
|
let clause;
|
|
370
374
|
if (typeof value === 'number') {
|
|
371
375
|
const perc = value > 0 && value < 1;
|
|
@@ -374,70 +378,64 @@ export class SelectQuery extends Query {
|
|
|
374
378
|
} else {
|
|
375
379
|
clause = value;
|
|
376
380
|
}
|
|
377
|
-
this._sample = clause;
|
|
381
|
+
this._sample = clause ?? undefined;
|
|
378
382
|
return this;
|
|
379
383
|
}
|
|
380
384
|
|
|
381
385
|
/**
|
|
382
386
|
* Add WHERE expressions.
|
|
383
|
-
* @param
|
|
384
|
-
* @returns {this}
|
|
387
|
+
* @param expr Expressions to add.
|
|
385
388
|
*/
|
|
386
|
-
where(...expr) {
|
|
389
|
+
where(...expr: FilterExpr[]): this {
|
|
387
390
|
this._where = this._where.concat(exprList(expr, asVerbatim));
|
|
388
391
|
return this;
|
|
389
392
|
}
|
|
390
393
|
|
|
391
394
|
/**
|
|
392
395
|
* Set WHERE expressions, replacing any prior expressions.
|
|
393
|
-
* @param
|
|
394
|
-
* @returns {this}
|
|
396
|
+
* @param expr Expressions to add.
|
|
395
397
|
*/
|
|
396
|
-
setWhere(...expr) {
|
|
398
|
+
setWhere(...expr: FilterExpr[]): this {
|
|
397
399
|
this._where = [];
|
|
398
400
|
return this.where(...expr);
|
|
399
401
|
}
|
|
400
402
|
|
|
401
403
|
/**
|
|
402
404
|
* Add GROUP BY expressions.
|
|
403
|
-
* @param
|
|
404
|
-
* @returns {this}
|
|
405
|
+
* @param expr Expressions to add.
|
|
405
406
|
*/
|
|
406
|
-
groupby(...expr) {
|
|
407
|
-
this._groupby = this._groupby.concat(
|
|
407
|
+
groupby(...expr: GroupByExpr[]): this {
|
|
408
|
+
this._groupby = this._groupby.concat(nodeList(expr));
|
|
408
409
|
return this;
|
|
409
410
|
}
|
|
410
411
|
|
|
411
412
|
/**
|
|
412
413
|
* Set GROUP BY expressions, replacing any prior expressions.
|
|
413
|
-
* @param
|
|
414
|
-
* @returns {this}
|
|
414
|
+
* @param expr Expressions to add.
|
|
415
415
|
*/
|
|
416
|
-
setGroupby(...expr) {
|
|
416
|
+
setGroupby(...expr: GroupByExpr[]): this {
|
|
417
417
|
this._groupby = [];
|
|
418
418
|
return this.groupby(...expr);
|
|
419
419
|
}
|
|
420
420
|
|
|
421
421
|
/**
|
|
422
422
|
* Add HAVING expressions.
|
|
423
|
-
* @param
|
|
424
|
-
* @returns {this}
|
|
423
|
+
* @param expr Expressions to add.
|
|
425
424
|
*/
|
|
426
|
-
having(...expr) {
|
|
425
|
+
having(...expr: FilterExpr[]): this {
|
|
427
426
|
this._having = this._having.concat(exprList(expr, asVerbatim));
|
|
428
427
|
return this;
|
|
429
428
|
}
|
|
430
429
|
|
|
431
430
|
/**
|
|
432
431
|
* Add WINDOW definitions.
|
|
433
|
-
* @param
|
|
434
|
-
* @returns {this}
|
|
432
|
+
* @param expr Window definitions to add.
|
|
435
433
|
*/
|
|
436
|
-
window(...expr) {
|
|
437
|
-
const list = [];
|
|
434
|
+
window(...expr: (Record<string, WindowDefNode> | null)[]): this {
|
|
435
|
+
const list: WindowClauseNode[] = [];
|
|
438
436
|
expr.flat().forEach(e => {
|
|
439
437
|
if (e != null) for (const name in e) {
|
|
440
|
-
list.push(new WindowClauseNode(unquote(name)
|
|
438
|
+
list.push(new WindowClauseNode(unquote(name)!, e[name]));
|
|
441
439
|
}
|
|
442
440
|
});
|
|
443
441
|
this._window = this._window.concat(list);
|
|
@@ -446,17 +444,15 @@ export class SelectQuery extends Query {
|
|
|
446
444
|
|
|
447
445
|
/**
|
|
448
446
|
* Add QUALIFY expressions.
|
|
449
|
-
* @param
|
|
450
|
-
* @returns {this}
|
|
447
|
+
* @param expr Expressions to add.
|
|
451
448
|
*/
|
|
452
|
-
qualify(...expr) {
|
|
449
|
+
qualify(...expr: FilterExpr[]): this {
|
|
453
450
|
this._qualify = this._qualify.concat(exprList(expr, asVerbatim));
|
|
454
451
|
return this;
|
|
455
452
|
}
|
|
456
453
|
|
|
457
454
|
/**
|
|
458
455
|
* Generate a SQL query string.
|
|
459
|
-
* @returns {string}
|
|
460
456
|
*/
|
|
461
457
|
toString() {
|
|
462
458
|
const {
|
|
@@ -517,26 +513,27 @@ export class SelectQuery extends Query {
|
|
|
517
513
|
}
|
|
518
514
|
|
|
519
515
|
export class DescribeQuery extends SQLNode {
|
|
516
|
+
readonly query: Query;
|
|
517
|
+
|
|
520
518
|
/**
|
|
521
519
|
* Instantiate a describe query.
|
|
520
|
+
* @param query The query to describe.
|
|
522
521
|
*/
|
|
523
|
-
constructor(query) {
|
|
522
|
+
constructor(query: Query) {
|
|
524
523
|
super(DESCRIBE_QUERY);
|
|
525
524
|
this.query = query;
|
|
526
525
|
}
|
|
527
526
|
|
|
528
527
|
/**
|
|
529
528
|
* Clone this describe query.
|
|
530
|
-
* @returns {this}
|
|
531
529
|
*/
|
|
532
|
-
clone() {
|
|
533
|
-
// @ts-expect-error
|
|
530
|
+
clone(): this {
|
|
531
|
+
// @ts-expect-error creates describe query
|
|
534
532
|
return new DescribeQuery(this.query.clone());
|
|
535
533
|
}
|
|
536
534
|
|
|
537
535
|
/**
|
|
538
536
|
* Generate a SQL query string.
|
|
539
|
-
* @returns {string}
|
|
540
537
|
*/
|
|
541
538
|
toString() {
|
|
542
539
|
return `DESCRIBE ${this.query}`;
|
|
@@ -544,30 +541,27 @@ export class DescribeQuery extends SQLNode {
|
|
|
544
541
|
}
|
|
545
542
|
|
|
546
543
|
export class SetOperation extends Query {
|
|
544
|
+
/** The set operation to perform. */
|
|
545
|
+
readonly op: string;
|
|
546
|
+
/** The input queries to the set operation. */
|
|
547
|
+
readonly queries: Query[];
|
|
548
|
+
|
|
547
549
|
/**
|
|
548
550
|
* Instantiate a new set operation instance.
|
|
549
|
-
* @param
|
|
550
|
-
* @param
|
|
551
|
+
* @param op The set operation.
|
|
552
|
+
* @param queries The subqueries.
|
|
551
553
|
*/
|
|
552
|
-
constructor(op, queries) {
|
|
554
|
+
constructor(op: string, queries: Query[]) {
|
|
553
555
|
super(SET_OPERATION);
|
|
554
|
-
/**
|
|
555
|
-
* @type {string}
|
|
556
|
-
* @readonly
|
|
557
|
-
*/
|
|
558
556
|
this.op = op;
|
|
559
|
-
/**
|
|
560
|
-
* @type {Query[]}
|
|
561
|
-
* @readonly
|
|
562
|
-
*/
|
|
563
557
|
this.queries = queries;
|
|
564
558
|
}
|
|
565
559
|
|
|
566
560
|
/**
|
|
567
561
|
* Add a pointer to the query for which this query is a CTE.
|
|
568
|
-
* @param
|
|
562
|
+
* @param query The query for which this query is a CTE.
|
|
569
563
|
*/
|
|
570
|
-
setCteFor(query) {
|
|
564
|
+
setCteFor(query: Query | null) {
|
|
571
565
|
super.setCteFor(query);
|
|
572
566
|
const { queries, cteFor } = this;
|
|
573
567
|
if (cteFor) queries.forEach(q => q.setCteFor(cteFor));
|
|
@@ -575,7 +569,6 @@ export class SetOperation extends Query {
|
|
|
575
569
|
|
|
576
570
|
/**
|
|
577
571
|
* Return a list of subqueries.
|
|
578
|
-
* @returns {Query[]}
|
|
579
572
|
*/
|
|
580
573
|
get subqueries() {
|
|
581
574
|
return this.queries;
|
|
@@ -583,17 +576,15 @@ export class SetOperation extends Query {
|
|
|
583
576
|
|
|
584
577
|
/**
|
|
585
578
|
* Clone this set operation.
|
|
586
|
-
* @returns {this}
|
|
587
579
|
*/
|
|
588
|
-
clone() {
|
|
580
|
+
clone(): this {
|
|
589
581
|
const { op, queries, ...rest } = this;
|
|
590
|
-
// @ts-expect-error
|
|
582
|
+
// @ts-expect-error creates set operation
|
|
591
583
|
return Object.assign(new SetOperation(op, queries), rest);
|
|
592
584
|
}
|
|
593
585
|
|
|
594
586
|
/**
|
|
595
587
|
* Generate a SQL query string.
|
|
596
|
-
* @returns {string}
|
|
597
588
|
*/
|
|
598
589
|
toString() {
|
|
599
590
|
const { op, queries, _with, _orderby, _limitPerc, _limit, _offset } = this;
|
|
@@ -619,65 +610,94 @@ export class SetOperation extends Query {
|
|
|
619
610
|
}
|
|
620
611
|
|
|
621
612
|
class WithClause {
|
|
613
|
+
/** The common table expressions (CTE). */
|
|
614
|
+
readonly _with: WithExpr[];
|
|
615
|
+
|
|
622
616
|
/**
|
|
623
617
|
* Instantiate a new WITH clause instance.
|
|
624
|
-
* @param
|
|
618
|
+
* @param expr The WITH CTE queries.
|
|
625
619
|
*/
|
|
626
|
-
constructor(...expr) {
|
|
620
|
+
constructor(...expr: WithExpr[]) {
|
|
627
621
|
this._with = expr;
|
|
628
622
|
}
|
|
629
623
|
|
|
630
624
|
/**
|
|
631
625
|
* Create a new select query with the given SELECT expressions.
|
|
632
|
-
* @param
|
|
633
|
-
* @returns {SelectQuery}
|
|
626
|
+
* @param expr The SELECT expressions.
|
|
634
627
|
*/
|
|
635
|
-
select(...expr) {
|
|
628
|
+
select(...expr: SelectExpr[]) {
|
|
636
629
|
return Query.select(...expr).with(...this._with);
|
|
637
630
|
}
|
|
638
631
|
|
|
639
632
|
/**
|
|
640
633
|
* Create a new select query with the given FROM expressions.
|
|
641
|
-
* @param
|
|
642
|
-
* @returns {SelectQuery}
|
|
634
|
+
* @param expr The FROM expressions.
|
|
643
635
|
*/
|
|
644
|
-
from(...expr) {
|
|
636
|
+
from(...expr: FromExpr[]) {
|
|
645
637
|
return Query.from(...expr).with(...this._with);
|
|
646
638
|
}
|
|
647
639
|
|
|
648
640
|
/**
|
|
649
641
|
* Create a new UNION set operation over the given queries.
|
|
650
|
-
* @param
|
|
651
|
-
* @returns {SetOperation}
|
|
642
|
+
* @param queries The queries.
|
|
652
643
|
*/
|
|
653
|
-
union(...queries) {
|
|
644
|
+
union(...queries: Query[]) {
|
|
654
645
|
return Query.union(...queries).with(...this._with);
|
|
655
646
|
}
|
|
656
647
|
|
|
648
|
+
/**
|
|
649
|
+
* Create a new UNION BY NAME set operation over the given queries.
|
|
650
|
+
* @param queries The queries.
|
|
651
|
+
*/
|
|
652
|
+
unionByName(...queries: Query[]) {
|
|
653
|
+
return Query.unionByName(...queries).with(...this._with);
|
|
654
|
+
}
|
|
655
|
+
|
|
657
656
|
/**
|
|
658
657
|
* Create a new UNION ALL set operation over the given queries.
|
|
659
|
-
* @param
|
|
660
|
-
* @returns {SetOperation}
|
|
658
|
+
* @param queries The queries.
|
|
661
659
|
*/
|
|
662
|
-
unionAll(...queries) {
|
|
660
|
+
unionAll(...queries: Query[]) {
|
|
663
661
|
return Query.unionAll(...queries).with(...this._with);
|
|
664
662
|
}
|
|
665
663
|
|
|
664
|
+
/**
|
|
665
|
+
* Create a new UNION ALL BY NAME set operation over the given queries.
|
|
666
|
+
* @param queries The queries.
|
|
667
|
+
*/
|
|
668
|
+
unionAllByName(...queries: Query[]) {
|
|
669
|
+
return Query.unionAllByName(...queries).with(...this._with);
|
|
670
|
+
}
|
|
671
|
+
|
|
666
672
|
/**
|
|
667
673
|
* Create a new INTERSECT set operation over the given queries.
|
|
668
|
-
* @param
|
|
669
|
-
* @returns {SetOperation}
|
|
674
|
+
* @param queries The queries.
|
|
670
675
|
*/
|
|
671
|
-
intersect(...queries) {
|
|
676
|
+
intersect(...queries: Query[]) {
|
|
672
677
|
return Query.intersect(...queries).with(...this._with);
|
|
673
678
|
}
|
|
674
679
|
|
|
680
|
+
/**
|
|
681
|
+
* Create a new INTERSECT ALL set operation over the given queries.
|
|
682
|
+
* @param queries The queries.
|
|
683
|
+
*/
|
|
684
|
+
intersectAll(...queries: Query[]) {
|
|
685
|
+
return Query.intersectAll(...queries).with(...this._with);
|
|
686
|
+
}
|
|
687
|
+
|
|
675
688
|
/**
|
|
676
689
|
* Create a new EXCEPT set operation over the given queries.
|
|
677
|
-
* @param
|
|
678
|
-
* @returns {SetOperation}
|
|
690
|
+
* @param queries The queries.
|
|
679
691
|
*/
|
|
680
|
-
except(...queries) {
|
|
692
|
+
except(...queries: Query[]) {
|
|
681
693
|
return Query.except(...queries).with(...this._with);
|
|
682
694
|
}
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* Create a new EXCEPT ALL set operation over the given queries.
|
|
698
|
+
* @param queries The queries.
|
|
699
|
+
*/
|
|
700
|
+
exceptAll(...queries: Query[]) {
|
|
701
|
+
return Query.exceptAll(...queries).with(...this._with);
|
|
702
|
+
}
|
|
683
703
|
}
|