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