@uwdata/mosaic-sql 0.13.0 → 0.14.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/dist/types/ast/aggregate.d.ts +5 -4
- package/dist/types/ast/case.d.ts +6 -7
- package/dist/types/ast/column-param.d.ts +7 -7
- package/dist/types/ast/column-ref.d.ts +7 -6
- package/dist/types/ast/param.d.ts +5 -4
- package/dist/types/ast/query.d.ts +46 -39
- package/dist/types/ast/window.d.ts +15 -12
- package/dist/types/functions/aggregate.d.ts +89 -88
- package/dist/types/functions/case.d.ts +6 -8
- package/dist/types/functions/column.d.ts +5 -3
- package/dist/types/functions/datetime.d.ts +12 -11
- package/dist/types/functions/numeric.d.ts +48 -46
- package/dist/types/functions/operators.d.ts +80 -78
- package/dist/types/functions/order-by.d.ts +5 -4
- package/dist/types/functions/spatial.d.ts +14 -13
- package/dist/types/functions/sql-template-tag.d.ts +4 -5
- package/dist/types/functions/string.d.ts +22 -20
- package/dist/types/functions/util.d.ts +8 -0
- package/dist/types/functions/window.d.ts +18 -16
- package/dist/types/index.d.ts +3 -0
- package/dist/types/transforms/bin-1d.d.ts +3 -2
- package/dist/types/transforms/bin-2d.d.ts +6 -5
- package/dist/types/transforms/bin-date.d.ts +44 -0
- package/dist/types/transforms/bin-histogram.d.ts +51 -0
- package/dist/types/transforms/bin-linear-1d.d.ts +6 -4
- package/dist/types/transforms/bin-linear-2d.d.ts +6 -5
- package/dist/types/transforms/line-density.d.ts +5 -4
- package/dist/types/transforms/m4.d.ts +7 -4
- package/dist/types/transforms/util/bin-step.d.ts +61 -0
- package/dist/types/transforms/util/time-interval.d.ts +13 -0
- package/dist/types/types.d.ts +1 -0
- package/dist/types/util/ast.d.ts +6 -5
- package/dist/types/util/function.d.ts +6 -4
- package/dist/types/util/type-check.d.ts +6 -2
- package/dist/types/visit/visitors.d.ts +3 -2
- package/dist/types/visit/walk.d.ts +7 -4
- package/package.json +2 -2
- package/src/ast/aggregate.js +5 -2
- package/src/ast/case.js +6 -5
- package/src/ast/column-param.js +7 -5
- package/src/ast/column-ref.js +6 -3
- package/src/ast/param.js +5 -2
- package/src/ast/query.js +23 -19
- package/src/ast/window.js +10 -6
- package/src/functions/aggregate.js +55 -52
- package/src/functions/case.js +7 -7
- package/src/functions/column.js +6 -2
- package/src/functions/datetime.js +9 -6
- package/src/functions/numeric.js +35 -31
- package/src/functions/operators.js +53 -50
- package/src/functions/order-by.js +5 -2
- package/src/functions/spatial.js +10 -7
- package/src/functions/sql-template-tag.js +5 -5
- package/src/functions/string.js +16 -13
- package/src/functions/util.js +14 -0
- package/src/functions/window.js +13 -10
- package/src/index.js +3 -0
- package/src/transforms/bin-1d.js +4 -1
- package/src/transforms/bin-2d.js +7 -4
- package/src/transforms/bin-date.js +37 -0
- package/src/transforms/bin-histogram.js +52 -0
- package/src/transforms/bin-linear-1d.js +7 -3
- package/src/transforms/bin-linear-2d.js +12 -8
- package/src/transforms/line-density.js +7 -3
- package/src/transforms/m4.js +7 -3
- package/src/transforms/util/bin-step.js +79 -0
- package/src/transforms/util/time-interval.js +97 -0
- package/src/types.ts +11 -0
- package/src/util/ast.js +6 -3
- package/src/util/function.js +6 -2
- package/src/util/type-check.js +5 -1
- package/src/visit/visitors.js +6 -2
- package/src/visit/walk.js +8 -3
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} BinHistogramOptions
|
|
3
|
+
* @property {number} [step] An exact binning step to use.
|
|
4
|
+
* @property {number} [steps] The desired number of binning steps.
|
|
5
|
+
* This value is a hint, it does not guarantee an exact number of steps.
|
|
6
|
+
* @property {number} [minstep] A minimum binning step value. No generated
|
|
7
|
+
* step can be less than this value.
|
|
8
|
+
* @property {boolean} [nice] A boolean flag (default true) indicating if bin
|
|
9
|
+
* extents should be snapped to "nice" numbers such as multiples of 5 or 10.
|
|
10
|
+
* @property {number} [offset] The number of bin steps (default 0) by
|
|
11
|
+
* which to offset the result.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Return a SQL expression for histogram bins.
|
|
15
|
+
* @param {ExprValue} field The column or expression to bin.
|
|
16
|
+
* @param {[number, number]} extent The min/max extent over which to bin.
|
|
17
|
+
* @param {BinHistogramOptions} [options] Binning options.
|
|
18
|
+
* @param {ReturnType<typeof scaleTransform>} [transform] Scale transforms to
|
|
19
|
+
* apply to create (potentially non-linear) binning intervals.
|
|
20
|
+
* @returns {ExprNode} The resulting SQL expression
|
|
21
|
+
*/
|
|
22
|
+
export function binHistogram(field: ExprValue, extent: [number, number], options?: BinHistogramOptions, transform?: ReturnType<typeof scaleTransform>): ExprNode;
|
|
23
|
+
export type BinHistogramOptions = {
|
|
24
|
+
/**
|
|
25
|
+
* An exact binning step to use.
|
|
26
|
+
*/
|
|
27
|
+
step?: number;
|
|
28
|
+
/**
|
|
29
|
+
* The desired number of binning steps.
|
|
30
|
+
* This value is a hint, it does not guarantee an exact number of steps.
|
|
31
|
+
*/
|
|
32
|
+
steps?: number;
|
|
33
|
+
/**
|
|
34
|
+
* A minimum binning step value. No generated
|
|
35
|
+
* step can be less than this value.
|
|
36
|
+
*/
|
|
37
|
+
minstep?: number;
|
|
38
|
+
/**
|
|
39
|
+
* A boolean flag (default true) indicating if bin
|
|
40
|
+
* extents should be snapped to "nice" numbers such as multiples of 5 or 10.
|
|
41
|
+
*/
|
|
42
|
+
nice?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* The number of bin steps (default 0) by
|
|
45
|
+
* which to offset the result.
|
|
46
|
+
*/
|
|
47
|
+
offset?: number;
|
|
48
|
+
};
|
|
49
|
+
import type { ExprValue } from '../types.js';
|
|
50
|
+
import { scaleTransform } from './scales.js';
|
|
51
|
+
import type { ExprNode } from '../ast/node.js';
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Perform linear binning in one dimension.
|
|
3
|
-
* @param {
|
|
4
|
-
* @param {
|
|
5
|
-
* @param {
|
|
3
|
+
* @param {SelectQuery} query The base query to bin.
|
|
4
|
+
* @param {ExprValue} x The expression to bin.
|
|
5
|
+
* @param {ExprValue} [weight] The expression to weight by.
|
|
6
6
|
* @param {string[]} [groupby] Group by expressions.
|
|
7
7
|
* @returns {Query}
|
|
8
8
|
*/
|
|
9
|
-
export function binLinear1d(query:
|
|
9
|
+
export function binLinear1d(query: SelectQuery, x: ExprValue, weight?: ExprValue, groupby?: string[]): Query;
|
|
10
|
+
import type { SelectQuery } from '../ast/query.js';
|
|
11
|
+
import type { ExprValue } from '../types.js';
|
|
10
12
|
import { Query } from '../ast/query.js';
|
|
@@ -6,13 +6,14 @@
|
|
|
6
6
|
* should be in units of grid indices, but can contain fractional components.
|
|
7
7
|
* @param {SelectQuery} q The input query. The FROM and WHERE clauses should
|
|
8
8
|
* be added to the query separately, before this method is invoked.
|
|
9
|
-
* @param {
|
|
10
|
-
* @param {
|
|
11
|
-
* @param {
|
|
9
|
+
* @param {ExprValue} xp The x grid bin expression
|
|
10
|
+
* @param {ExprValue} yp The y grid bin expression
|
|
11
|
+
* @param {ExprValue | undefined} weight Point weights.
|
|
12
12
|
* @param {number} xn The number of x grid bins.
|
|
13
13
|
* @param {string[]} [groupby] Group by expressions.
|
|
14
14
|
* @returns {SelectQuery} A linear binning query for bin `index` and
|
|
15
15
|
* aggregate `density` columns, in addition to any group by expressions.
|
|
16
16
|
*/
|
|
17
|
-
export function binLinear2d(q: SelectQuery, xp:
|
|
18
|
-
import { SelectQuery } from '../ast/query.js';
|
|
17
|
+
export function binLinear2d(q: SelectQuery, xp: ExprValue, yp: ExprValue, weight: ExprValue | undefined, xn: number, groupby?: string[]): SelectQuery;
|
|
18
|
+
import type { SelectQuery } from '../ast/query.js';
|
|
19
|
+
import type { ExprValue } from '../types.js';
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* and then sum results for all line series to produce a density map.
|
|
6
6
|
* Based on Moritz and Fisher's work: https://arxiv.org/abs/1808.06019
|
|
7
7
|
* @param {SelectQuery} q The base query over the data.
|
|
8
|
-
* @param {
|
|
8
|
+
* @param {ExprValue} x Bin expression for x dimension.
|
|
9
9
|
* Provides gridded x coordinates, potentially with a fractional component.
|
|
10
|
-
* @param {
|
|
10
|
+
* @param {ExprValue} y Bin expression for x dimension.
|
|
11
11
|
* Provides gridded y coordinates, potentially with a fractional component.
|
|
12
12
|
* @param {string[]} z Group by columns that segment data into individual line
|
|
13
13
|
* series. An empty array indicates there is only a single line series.
|
|
@@ -19,5 +19,6 @@
|
|
|
19
19
|
* normalization to improve accuracy and reduce artifacts (default `true`).
|
|
20
20
|
* @returns {SelectQuery}
|
|
21
21
|
*/
|
|
22
|
-
export function lineDensity(q: SelectQuery, x:
|
|
23
|
-
import { SelectQuery } from '../ast/query.js';
|
|
22
|
+
export function lineDensity(q: SelectQuery, x: ExprValue, y: ExprValue, z: string[], xn: number, yn: number, groupby?: string[], normalize?: boolean): SelectQuery;
|
|
23
|
+
import type { SelectQuery } from '../ast/query.js';
|
|
24
|
+
import type { ExprValue } from '../types.js';
|
|
@@ -5,14 +5,17 @@
|
|
|
5
5
|
* argmin and argmax, following https://arxiv.org/pdf/2306.03714.pdf.
|
|
6
6
|
* This method can bin along either the *x* or *y* dimension, as determined
|
|
7
7
|
* by the caller-provided *bin* expression.
|
|
8
|
-
* @param {
|
|
9
|
-
* @param {
|
|
8
|
+
* @param {FromExpr} input The base query or table.
|
|
9
|
+
* @param {ExprValue} bin An expression that maps
|
|
10
10
|
* time-series values to fractional pixel positions.
|
|
11
11
|
* @param {string} x The x dimension column name.
|
|
12
12
|
* @param {string} y The y dimension column name.
|
|
13
|
-
* @param {
|
|
13
|
+
* @param {ExprNode[]} [groups] Additional
|
|
14
14
|
* groupby columns, for example for faceted charts.
|
|
15
15
|
* @returns {Query} The resulting M4 query.
|
|
16
16
|
*/
|
|
17
|
-
export function m4(input:
|
|
17
|
+
export function m4(input: FromExpr, bin: ExprValue, x: string, y: string, groups?: ExprNode[]): Query;
|
|
18
|
+
import type { FromExpr } from '../types.js';
|
|
19
|
+
import type { ExprValue } from '../types.js';
|
|
20
|
+
import type { ExprNode } from '../ast/node.js';
|
|
18
21
|
import { Query } from '../ast/query.js';
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} BinOptions
|
|
3
|
+
* @property {number} [step] An exact binning step to use.
|
|
4
|
+
* @property {number} [steps] The desired number of binning steps.
|
|
5
|
+
* This value is a hint, it does not guarantee an exact number of steps.
|
|
6
|
+
* @property {number} [minstep] A minimum binning step value. No generated
|
|
7
|
+
* step can be less than this value.
|
|
8
|
+
* @property {boolean} [nice] A boolean flag (default true) indicating if bin
|
|
9
|
+
* extents should be snapped to "nice" numbers such as multiples of 5 or 10.
|
|
10
|
+
* @property {number} [base] A number indicating the the logarithm base to
|
|
11
|
+
* use for automatic step size determination. Defaults to base 10.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Generate a numeric binning scheme suitable for a histogram.
|
|
15
|
+
* @param {number} min The minimum value of the extent to bin.
|
|
16
|
+
* @param {number} max The maximum value of the extent to bin.
|
|
17
|
+
* @param {BinOptions} options Binning scheme options.
|
|
18
|
+
*/
|
|
19
|
+
export function bins(min: number, max: number, options: BinOptions): {
|
|
20
|
+
min: number;
|
|
21
|
+
max: number;
|
|
22
|
+
steps: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Determine a bin step interval.
|
|
26
|
+
* @param {number} span The span from maximum to minimum value.
|
|
27
|
+
* @param {number} steps The approximate number of desired bins.
|
|
28
|
+
* @param {number} [minstep=0] The minimum acceptable bin step size.
|
|
29
|
+
* @param {number} [logb=Math.LN10] The log base for determining
|
|
30
|
+
* orders of magnitude for step sizes. Defaults to log base 10
|
|
31
|
+
* (`Math.LN10`). For example to use log base 2, provide the
|
|
32
|
+
* argument `Math.LN2` instead.
|
|
33
|
+
* @returns {number} The bin step interval (bin size).
|
|
34
|
+
*/
|
|
35
|
+
export function binStep(span: number, steps: number, minstep?: number, logb?: number): number;
|
|
36
|
+
export type BinOptions = {
|
|
37
|
+
/**
|
|
38
|
+
* An exact binning step to use.
|
|
39
|
+
*/
|
|
40
|
+
step?: number;
|
|
41
|
+
/**
|
|
42
|
+
* The desired number of binning steps.
|
|
43
|
+
* This value is a hint, it does not guarantee an exact number of steps.
|
|
44
|
+
*/
|
|
45
|
+
steps?: number;
|
|
46
|
+
/**
|
|
47
|
+
* A minimum binning step value. No generated
|
|
48
|
+
* step can be less than this value.
|
|
49
|
+
*/
|
|
50
|
+
minstep?: number;
|
|
51
|
+
/**
|
|
52
|
+
* A boolean flag (default true) indicating if bin
|
|
53
|
+
* extents should be snapped to "nice" numbers such as multiples of 5 or 10.
|
|
54
|
+
*/
|
|
55
|
+
nice?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* A number indicating the the logarithm base to
|
|
58
|
+
* use for automatic step size determination. Defaults to base 10.
|
|
59
|
+
*/
|
|
60
|
+
base?: number;
|
|
61
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determine a time interval for binning based on provided min
|
|
3
|
+
* and max timestamps and approximate step count.
|
|
4
|
+
* @param {Date|number} min The minimum timestamp value.
|
|
5
|
+
* @param {Date|number} max The maximum timestamp value.
|
|
6
|
+
* @param {number} steps The approximate number of bins desired.
|
|
7
|
+
* @returns {{ unit: TimeUnit, step: number }}
|
|
8
|
+
*/
|
|
9
|
+
export function timeInterval(min: Date | number, max: Date | number, steps: number): {
|
|
10
|
+
unit: TimeUnit;
|
|
11
|
+
step: number;
|
|
12
|
+
};
|
|
13
|
+
import type { TimeUnit } from '../../types.js';
|
package/dist/types/types.d.ts
CHANGED
|
@@ -59,3 +59,4 @@ export type FromExpr = MaybeArray<FromEntry>;
|
|
|
59
59
|
export type FilterExpr = MaybeArray<string | ExprNode>;
|
|
60
60
|
export type GroupByExpr = MaybeArray<string | ExprNode>;
|
|
61
61
|
export type OrderByExpr = MaybeArray<string | ExprNode>;
|
|
62
|
+
export type TimeUnit = 'year' | 'quarter' | 'month' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond' | 'microsecond';
|
package/dist/types/util/ast.d.ts
CHANGED
|
@@ -38,16 +38,16 @@ export function asTableRef(value: string | string[] | TableRefNode): TableRefNod
|
|
|
38
38
|
* Parse a string as a column reference, potentially with
|
|
39
39
|
* dot ('.') delimited table, schema, and database references.
|
|
40
40
|
* @param {string} ref The column reference string.
|
|
41
|
-
* @returns {
|
|
41
|
+
* @returns {ColumnRefNode}
|
|
42
42
|
*/
|
|
43
|
-
export function parseColumnRef(ref: string):
|
|
43
|
+
export function parseColumnRef(ref: string): ColumnRefNode;
|
|
44
44
|
/**
|
|
45
45
|
* Parse a string as a table reference, potentially with
|
|
46
46
|
* dot ('.') delimited schema and database references.
|
|
47
47
|
* @param {string} ref The table reference string.
|
|
48
|
-
* @returns {
|
|
48
|
+
* @returns {TableRefNode}
|
|
49
49
|
*/
|
|
50
|
-
export function parseTableRef(ref: string):
|
|
50
|
+
export function parseTableRef(ref: string): TableRefNode;
|
|
51
51
|
/**
|
|
52
52
|
* Create a new window definition node. The return value is an empty
|
|
53
53
|
* window definition. Use chained calls such as `partitionby` and `orderby`
|
|
@@ -56,5 +56,6 @@ export function parseTableRef(ref: string): import("../ast/table-ref.js").TableR
|
|
|
56
56
|
*/
|
|
57
57
|
export function over(): WindowDefNode;
|
|
58
58
|
import { ExprNode } from '../ast/node.js';
|
|
59
|
-
import { TableRefNode } from '../ast/table-ref.js';
|
|
59
|
+
import type { TableRefNode } from '../ast/table-ref.js';
|
|
60
|
+
import type { ColumnRefNode } from '../ast/column-ref.js';
|
|
60
61
|
import { WindowDefNode } from '../ast/window.js';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Test if an AST node is a specific function call.
|
|
3
|
-
* @param {
|
|
3
|
+
* @param {SQLNode} node The SQL AST node to test.
|
|
4
4
|
* @param {string} name The function name.
|
|
5
5
|
* @returns {node is FunctionNode}
|
|
6
6
|
*/
|
|
7
|
-
export function isFunctionCall(node:
|
|
7
|
+
export function isFunctionCall(node: SQLNode, name: string): node is FunctionNode;
|
|
8
8
|
/**
|
|
9
9
|
* Create a new function call AST node.
|
|
10
10
|
* @param {string} name The function name.
|
|
@@ -23,11 +23,11 @@ export function aggFn(name: string, ...args: any[]): AggregateNode;
|
|
|
23
23
|
* Create a new window AST node. The output node has an empty window
|
|
24
24
|
* definition. Use chained calls such as `partitionby` and `orderby`
|
|
25
25
|
* to specify the window settings.
|
|
26
|
-
* @param {
|
|
26
|
+
* @param {WindowFunctionName} name The function name.
|
|
27
27
|
* @param {...any} args The function arguments.
|
|
28
28
|
* @returns {WindowNode}
|
|
29
29
|
*/
|
|
30
|
-
export function winFn(name:
|
|
30
|
+
export function winFn(name: WindowFunctionName, ...args: any[]): WindowNode;
|
|
31
31
|
/**
|
|
32
32
|
* Process a list of expression inputs. Nested arrays are flattened,
|
|
33
33
|
* null results are removed, and each input is cast (as needed) to
|
|
@@ -49,6 +49,8 @@ export function exprList(list: any[], cast?: Function): ReturnType<Function>[];
|
|
|
49
49
|
* @returns {T[]} The prepared argument list.
|
|
50
50
|
*/
|
|
51
51
|
export function argsList<T>(list: T[]): T[];
|
|
52
|
+
import type { SQLNode } from '../ast/node.js';
|
|
52
53
|
import { FunctionNode } from '../ast/function.js';
|
|
53
54
|
import { AggregateNode } from '../ast/aggregate.js';
|
|
55
|
+
import type { WindowFunctionName } from '../types.js';
|
|
54
56
|
import { WindowNode } from '../ast/window.js';
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { ParamLike } from '../types.js'
|
|
3
|
+
*/
|
|
1
4
|
/**
|
|
2
5
|
* Check if a value is a string.
|
|
3
6
|
* @param {*} value The value to check.
|
|
@@ -13,6 +16,7 @@ export function isArray(value: any): value is any[];
|
|
|
13
16
|
/**
|
|
14
17
|
* Check if a value is a dynamic parameter.
|
|
15
18
|
* @param {*} value The value to check.
|
|
16
|
-
* @returns {value is
|
|
19
|
+
* @returns {value is ParamLike}
|
|
17
20
|
*/
|
|
18
|
-
export function isParamLike(value: any): value is
|
|
21
|
+
export function isParamLike(value: any): value is ParamLike;
|
|
22
|
+
import type { ParamLike } from '../types.js';
|
|
@@ -25,9 +25,10 @@ export function collectColumns(root: SQLNode): ColumnRefNode[];
|
|
|
25
25
|
/**
|
|
26
26
|
* Collect all unique dynamic parameter instances.
|
|
27
27
|
* @param {SQLNode} root The root of the AST to search.
|
|
28
|
-
* @returns {
|
|
28
|
+
* @returns {ParamLike[]}
|
|
29
29
|
*/
|
|
30
|
-
export function collectParams(root: SQLNode):
|
|
30
|
+
export function collectParams(root: SQLNode): ParamLike[];
|
|
31
31
|
import { SQLNode } from '../ast/node.js';
|
|
32
32
|
import { AggregateNode } from '../ast/aggregate.js';
|
|
33
33
|
import { ColumnRefNode } from '../ast/column-ref.js';
|
|
34
|
+
import type { ParamLike } from '../types.js';
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Perform a traversal of a SQL expression AST.
|
|
3
|
-
* @param {
|
|
4
|
-
* @param {
|
|
5
|
-
* @return {
|
|
3
|
+
* @param {SQLNode} node Root node for AST traversal.
|
|
4
|
+
* @param {VisitorCallback} visit Visitor callback function.
|
|
5
|
+
* @return {VisitorResult}
|
|
6
6
|
*/
|
|
7
|
-
export function walk(node:
|
|
7
|
+
export function walk(node: SQLNode, visit: VisitorCallback): VisitorResult;
|
|
8
|
+
import type { SQLNode } from '../ast/node.js';
|
|
9
|
+
import type { VisitorCallback } from '../types.js';
|
|
10
|
+
import type { VisitorResult } from '../types.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uwdata/mosaic-sql",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "SQL query construction and analysis.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sql",
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"tsc": "tsc -p jsconfig.json",
|
|
28
28
|
"prepublishOnly": "npm run test && npm run lint && npm run build"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "a882aab60867e4e9d9738bc950aa9de32729a806"
|
|
31
31
|
}
|
package/src/ast/aggregate.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { ExprVarArgs } from '../types.js'
|
|
3
|
+
*/
|
|
1
4
|
import { AGGREGATE } from '../constants.js';
|
|
2
5
|
import { asVerbatim } from '../util/ast.js';
|
|
3
6
|
import { isString } from '../util/type-check.js';
|
|
@@ -69,7 +72,7 @@ export class AggregateNode extends ExprNode {
|
|
|
69
72
|
|
|
70
73
|
/**
|
|
71
74
|
* Return a new window function over this aggregate with the given partitions.
|
|
72
|
-
* @param {...
|
|
75
|
+
* @param {...ExprVarArgs} expr The partition by criteria.
|
|
73
76
|
* @returns {WindowNode} A new window node.
|
|
74
77
|
*/
|
|
75
78
|
partitionby(...expr) {
|
|
@@ -78,7 +81,7 @@ export class AggregateNode extends ExprNode {
|
|
|
78
81
|
|
|
79
82
|
/**
|
|
80
83
|
* Return a new window function over this aggregate with the given ordering.
|
|
81
|
-
* @param {...
|
|
84
|
+
* @param {...ExprVarArgs} expr The order by criteria.
|
|
82
85
|
* @returns {WindowNode} A new window node.
|
|
83
86
|
*/
|
|
84
87
|
orderby(...expr) {
|
package/src/ast/case.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { ExprValue } from '../types.js'
|
|
3
|
+
*/
|
|
1
4
|
import { CASE, WHEN } from '../constants.js';
|
|
2
5
|
import { asNode } from '../util/ast.js';
|
|
3
6
|
import { ExprNode, SQLNode } from './node.js';
|
|
@@ -37,10 +40,8 @@ export class CaseNode extends ExprNode {
|
|
|
37
40
|
/**
|
|
38
41
|
* Return a new case node with the given conditional added as
|
|
39
42
|
* the last WHEN / THEN pair.
|
|
40
|
-
* @param {
|
|
41
|
-
*
|
|
42
|
-
* @param {import('../types.js').ExprValue} value
|
|
43
|
-
* The THEN value expression.
|
|
43
|
+
* @param {ExprValue} cond The WHEN condition expression.
|
|
44
|
+
* @param {ExprValue} value The THEN value expression.
|
|
44
45
|
* @returns {CaseNode}
|
|
45
46
|
*/
|
|
46
47
|
when(cond, value) {
|
|
@@ -53,7 +54,7 @@ export class CaseNode extends ExprNode {
|
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
56
|
* Return a new case node with the given ELSE expression.
|
|
56
|
-
* @param {
|
|
57
|
+
* @param {ExprValue} expr The ELSE expression.
|
|
57
58
|
* @returns {CaseNode}
|
|
58
59
|
*/
|
|
59
60
|
else(expr) {
|
package/src/ast/column-param.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { ParamNode } from './param.js'
|
|
3
|
+
* @import { TableRefNode } from './table-ref.js'
|
|
4
|
+
*/
|
|
1
5
|
import { COLUMN_PARAM } from '../constants.js';
|
|
2
6
|
import { ColumnRefNode } from './column-ref.js';
|
|
3
7
|
|
|
@@ -13,16 +17,14 @@ export function isColumnParam(value) {
|
|
|
13
17
|
export class ColumnParamNode extends ColumnRefNode {
|
|
14
18
|
/**
|
|
15
19
|
* Instantiate a column param node.
|
|
16
|
-
* @param {
|
|
17
|
-
*
|
|
18
|
-
* @param {import('./table-ref.js').TableRefNode} [table] The table
|
|
19
|
-
* reference.
|
|
20
|
+
* @param {ParamNode} param The column name as a parameter node.
|
|
21
|
+
* @param {TableRefNode} [table] The table reference.
|
|
20
22
|
*/
|
|
21
23
|
constructor(param, table) {
|
|
22
24
|
super(COLUMN_PARAM, table);
|
|
23
25
|
/**
|
|
24
26
|
* The column name as a parameter node.
|
|
25
|
-
* @type {
|
|
27
|
+
* @type {ParamNode}
|
|
26
28
|
* @readonly
|
|
27
29
|
*/
|
|
28
30
|
this.param = param;
|
package/src/ast/column-ref.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { TableRefNode } from './table-ref.js'
|
|
3
|
+
*/
|
|
1
4
|
import { COLUMN_REF } from '../constants.js';
|
|
2
5
|
import { quoteIdentifier } from '../util/string.js';
|
|
3
6
|
import { ExprNode } from './node.js';
|
|
@@ -14,13 +17,13 @@ export function isColumnRef(value) {
|
|
|
14
17
|
export class ColumnRefNode extends ExprNode {
|
|
15
18
|
/**
|
|
16
19
|
* Instantiate a column reference node.
|
|
17
|
-
* @param {
|
|
20
|
+
* @param {TableRefNode} [table] The table reference.
|
|
18
21
|
*/
|
|
19
22
|
constructor(type, table) {
|
|
20
23
|
super(type);
|
|
21
24
|
/**
|
|
22
25
|
* The table reference.
|
|
23
|
-
* @type {
|
|
26
|
+
* @type {TableRefNode}
|
|
24
27
|
* @readonly
|
|
25
28
|
*/
|
|
26
29
|
this.table = table;
|
|
@@ -50,7 +53,7 @@ export class ColumnNameRefNode extends ColumnRefNode {
|
|
|
50
53
|
/**
|
|
51
54
|
* Instantiate a column reference node.
|
|
52
55
|
* @param {string} name The column name.
|
|
53
|
-
* @param {
|
|
56
|
+
* @param {TableRefNode} [table] The table reference.
|
|
54
57
|
*/
|
|
55
58
|
constructor(name, table) {
|
|
56
59
|
super(COLUMN_REF, table);
|
package/src/ast/param.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { ParamLike } from '../types.js'
|
|
3
|
+
*/
|
|
1
4
|
import { PARAM } from '../constants.js';
|
|
2
5
|
import { literalToSQL } from './literal.js';
|
|
3
6
|
import { ExprNode } from './node.js';
|
|
@@ -5,13 +8,13 @@ import { ExprNode } from './node.js';
|
|
|
5
8
|
export class ParamNode extends ExprNode {
|
|
6
9
|
/**
|
|
7
10
|
* Instantiate a param node with a dynamic parameter.
|
|
8
|
-
* @param {
|
|
11
|
+
* @param {ParamLike} param The dynamic parameter.
|
|
9
12
|
*/
|
|
10
13
|
constructor(param) {
|
|
11
14
|
super(PARAM);
|
|
12
15
|
/**
|
|
13
16
|
* The dynamic parameter.
|
|
14
|
-
* @type {
|
|
17
|
+
* @type {ParamLike}
|
|
15
18
|
* @readonly
|
|
16
19
|
*/
|
|
17
20
|
this.param = param;
|
package/src/ast/query.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { FilterExpr, FromExpr, GroupByExpr, OrderByExpr, SelectExpr, WithExpr } from '../types.js'
|
|
3
|
+
* @import { SampleMethod } from './sample.js'
|
|
4
|
+
*/
|
|
1
5
|
import { DESCRIBE_QUERY, SELECT_QUERY, SET_OPERATION } from '../constants.js';
|
|
2
6
|
import { asNode, asTableRef, asVerbatim } from '../util/ast.js';
|
|
3
7
|
import { exprList } from '../util/function.js';
|
|
@@ -42,7 +46,7 @@ export function isDescribeQuery(value) {
|
|
|
42
46
|
export class Query extends ExprNode {
|
|
43
47
|
/**
|
|
44
48
|
* Create a new WITH clause with the given CTE queries.
|
|
45
|
-
* @param {...
|
|
49
|
+
* @param {...WithExpr} expr The WITH CTE queries.
|
|
46
50
|
* @returns {WithClause}
|
|
47
51
|
*/
|
|
48
52
|
static with(...expr) {
|
|
@@ -51,7 +55,7 @@ export class Query extends ExprNode {
|
|
|
51
55
|
|
|
52
56
|
/**
|
|
53
57
|
* Create a new select query with the given SELECT expressions.
|
|
54
|
-
* @param {...
|
|
58
|
+
* @param {...SelectExpr} expr The SELECT expressions.
|
|
55
59
|
* @returns {SelectQuery}
|
|
56
60
|
*/
|
|
57
61
|
static select(...expr) {
|
|
@@ -60,7 +64,7 @@ export class Query extends ExprNode {
|
|
|
60
64
|
|
|
61
65
|
/**
|
|
62
66
|
* Create a new select query with the given FROM expressions.
|
|
63
|
-
* @param {...
|
|
67
|
+
* @param {...FromExpr} expr The FROM expressions.
|
|
64
68
|
* @returns {SelectQuery}
|
|
65
69
|
*/
|
|
66
70
|
static from(...expr) {
|
|
@@ -147,7 +151,7 @@ export class Query extends ExprNode {
|
|
|
147
151
|
|
|
148
152
|
/**
|
|
149
153
|
* Add WITH common table expressions (CTEs).
|
|
150
|
-
* @param {...
|
|
154
|
+
* @param {...WithExpr} expr Expressions to add.
|
|
151
155
|
* @returns {this}
|
|
152
156
|
*/
|
|
153
157
|
with(...expr) {
|
|
@@ -168,7 +172,7 @@ export class Query extends ExprNode {
|
|
|
168
172
|
|
|
169
173
|
/**
|
|
170
174
|
* Add ORDER BY expressions.
|
|
171
|
-
* @param {...
|
|
175
|
+
* @param {...OrderByExpr} expr Expressions to add.
|
|
172
176
|
* @returns
|
|
173
177
|
*/
|
|
174
178
|
orderby(...expr) {
|
|
@@ -255,7 +259,7 @@ export class SelectQuery extends Query {
|
|
|
255
259
|
|
|
256
260
|
/**
|
|
257
261
|
* Add SELECT expressions.
|
|
258
|
-
* @param {...
|
|
262
|
+
* @param {...SelectExpr} expr Expressions to add.
|
|
259
263
|
* @returns {this}
|
|
260
264
|
*/
|
|
261
265
|
select(...expr) {
|
|
@@ -281,7 +285,7 @@ export class SelectQuery extends Query {
|
|
|
281
285
|
|
|
282
286
|
/**
|
|
283
287
|
* Set SELECT expressions, replacing any prior expressions.
|
|
284
|
-
* @param {...
|
|
288
|
+
* @param {...SelectExpr} expr Expressions to add.
|
|
285
289
|
* @returns {this}
|
|
286
290
|
*/
|
|
287
291
|
setSelect(...expr) {
|
|
@@ -301,7 +305,7 @@ export class SelectQuery extends Query {
|
|
|
301
305
|
|
|
302
306
|
/**
|
|
303
307
|
* Add table FROM expressions.
|
|
304
|
-
* @param {...
|
|
308
|
+
* @param {...FromExpr} expr Expressions to add.
|
|
305
309
|
* @returns {this}
|
|
306
310
|
*/
|
|
307
311
|
from(...expr) {
|
|
@@ -321,7 +325,7 @@ export class SelectQuery extends Query {
|
|
|
321
325
|
|
|
322
326
|
/**
|
|
323
327
|
* Set FROM expressions, replacing any prior expressions.
|
|
324
|
-
* @param {...
|
|
328
|
+
* @param {...FromExpr} expr Expressions to add.
|
|
325
329
|
* @returns {this}
|
|
326
330
|
*/
|
|
327
331
|
setFrom(...expr) {
|
|
@@ -333,7 +337,7 @@ export class SelectQuery extends Query {
|
|
|
333
337
|
* Set SAMPLE settings.
|
|
334
338
|
* @param {number | SampleClauseNode} value Either a sample clause node
|
|
335
339
|
* or the sample size as either a row count or percentage.
|
|
336
|
-
* @param {
|
|
340
|
+
* @param {SampleMethod} [method] The sampling method
|
|
337
341
|
* to use.
|
|
338
342
|
* @param {number} [seed] The random seed.
|
|
339
343
|
* @returns {this}
|
|
@@ -353,7 +357,7 @@ export class SelectQuery extends Query {
|
|
|
353
357
|
|
|
354
358
|
/**
|
|
355
359
|
* Add WHERE expressions.
|
|
356
|
-
* @param {...
|
|
360
|
+
* @param {...FilterExpr} expr Expressions to add.
|
|
357
361
|
* @returns {this}
|
|
358
362
|
*/
|
|
359
363
|
where(...expr) {
|
|
@@ -363,7 +367,7 @@ export class SelectQuery extends Query {
|
|
|
363
367
|
|
|
364
368
|
/**
|
|
365
369
|
* Set WHERE expressions, replacing any prior expressions.
|
|
366
|
-
* @param {...
|
|
370
|
+
* @param {...FilterExpr} expr Expressions to add.
|
|
367
371
|
* @returns {this}
|
|
368
372
|
*/
|
|
369
373
|
setWhere(...expr) {
|
|
@@ -373,7 +377,7 @@ export class SelectQuery extends Query {
|
|
|
373
377
|
|
|
374
378
|
/**
|
|
375
379
|
* Add GROUP BY expressions.
|
|
376
|
-
* @param {...
|
|
380
|
+
* @param {...GroupByExpr} expr Expressions to add.
|
|
377
381
|
* @returns {this}
|
|
378
382
|
*/
|
|
379
383
|
groupby(...expr) {
|
|
@@ -383,7 +387,7 @@ export class SelectQuery extends Query {
|
|
|
383
387
|
|
|
384
388
|
/**
|
|
385
389
|
* Set GROUP BY expressions, replacing any prior expressions.
|
|
386
|
-
* @param {...
|
|
390
|
+
* @param {...GroupByExpr} expr Expressions to add.
|
|
387
391
|
* @returns {this}
|
|
388
392
|
*/
|
|
389
393
|
setGroupby(...expr) {
|
|
@@ -393,7 +397,7 @@ export class SelectQuery extends Query {
|
|
|
393
397
|
|
|
394
398
|
/**
|
|
395
399
|
* Add HAVING expressions.
|
|
396
|
-
* @param {...
|
|
400
|
+
* @param {...FilterExpr} expr Expressions to add.
|
|
397
401
|
* @returns {this}
|
|
398
402
|
*/
|
|
399
403
|
having(...expr) {
|
|
@@ -419,7 +423,7 @@ export class SelectQuery extends Query {
|
|
|
419
423
|
|
|
420
424
|
/**
|
|
421
425
|
* Add QUALIFY expressions.
|
|
422
|
-
* @param {...
|
|
426
|
+
* @param {...FilterExpr} expr Expressions to add.
|
|
423
427
|
* @returns {this}
|
|
424
428
|
*/
|
|
425
429
|
qualify(...expr) {
|
|
@@ -585,7 +589,7 @@ export class SetOperation extends Query {
|
|
|
585
589
|
class WithClause {
|
|
586
590
|
/**
|
|
587
591
|
* Instantiate a new WITH clause instance.
|
|
588
|
-
* @param {...
|
|
592
|
+
* @param {...WithExpr} expr The WITH CTE queries.
|
|
589
593
|
*/
|
|
590
594
|
constructor(...expr) {
|
|
591
595
|
this._with = expr;
|
|
@@ -593,7 +597,7 @@ class WithClause {
|
|
|
593
597
|
|
|
594
598
|
/**
|
|
595
599
|
* Create a new select query with the given SELECT expressions.
|
|
596
|
-
* @param {...
|
|
600
|
+
* @param {...SelectExpr} expr The SELECT expressions.
|
|
597
601
|
* @returns {SelectQuery}
|
|
598
602
|
*/
|
|
599
603
|
select(...expr) {
|
|
@@ -602,7 +606,7 @@ class WithClause {
|
|
|
602
606
|
|
|
603
607
|
/**
|
|
604
608
|
* Create a new select query with the given FROM expressions.
|
|
605
|
-
* @param {...
|
|
609
|
+
* @param {...FromExpr} expr The FROM expressions.
|
|
606
610
|
* @returns {SelectQuery}
|
|
607
611
|
*/
|
|
608
612
|
from(...expr) {
|