@nongt/visql-core 0.10.1 → 0.12.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.
@@ -5,13 +5,16 @@ export type BinaryOperator = typeof binaryOperators[number];
5
5
  export declare const unaryOperators: readonly ["IS NULL", "IS NOT NULL"];
6
6
  export declare function isUnaryOperator(operator: BinaryOperator | undefined): boolean;
7
7
  export type LogicalOperator = 'AND' | 'OR';
8
+ /** A calculation's operators (issue 26). */
9
+ export declare const arithmeticOperators: readonly ["+", "-", "*", "/"];
10
+ export type ArithmeticOperator = typeof arithmeticOperators[number];
8
11
  /** A value's type (issue 130, see valueTypes.ts). `integer` is a whole
9
12
  * number, `number` any. A `date` is a calendar day and a `dateTime` a day
10
13
  * and a time, both as calendarDate.ts holds them; a `time` is a time of
11
14
  * day, stored as `HH:MM:SS` text. */
12
15
  export type ValueType = 'text' | 'integer' | 'number' | 'date' | 'dateTime' | 'time' | 'boolean';
13
16
  export type LiteralValue = string | number | bigint | boolean | null | Date;
14
- export type ExpressionNode = LiteralNode | FieldNode | FunctionCallNode | BinaryNode | LogicalNode | NotNode | IfNode | CaseNode | ParamNode | ExistsNode | SubqueryNode | ListNode;
17
+ export type ExpressionNode = LiteralNode | FieldNode | FunctionCallNode | BinaryNode | ArithmeticNode | LogicalNode | NotNode | IfNode | CaseNode | ParamNode | ExistsNode | SubqueryNode | ListNode;
15
18
  /** A named value supplied by the application when the SQL is generated —
16
19
  * `astToParameterizedSql(query, dialect, { values: { [name]: … } })` —
17
20
  * never by the user. Code (typically a backend) adds it, e.g. a tenant or
@@ -70,8 +73,16 @@ export interface FunctionCallNode extends Record<string, unknown>, ColumnCopy {
70
73
  /** An aggregate over distinct values only: `COUNT(DISTINCT x)`. */
71
74
  distinct?: boolean;
72
75
  /** The order an aggregate takes its values in (issue 164): STRING_AGG's
73
- * text lists them so. Only STRING_AGG takes one. */
76
+ * text lists them so. A window call's (`over`) is its OVER's ORDER BY.
77
+ * Only STRING_AGG and window calls take one. */
74
78
  orderBy?: FunctionSortKey[];
79
+ /** A window function's call (issue 20, `window` in the registry): written
80
+ * with `OVER (PARTITION BY … ORDER BY …)`, over the rows its body
81
+ * returns rather than one value per row or group. */
82
+ over?: boolean;
83
+ /** A window call's PARTITION BY: the rows it looks at for a row are
84
+ * those with the same values. */
85
+ partitionBy?: ExpressionNode[];
75
86
  }
76
87
  /** One key of a function call's `orderBy`. */
77
88
  export interface FunctionSortKey {
@@ -85,6 +96,17 @@ export interface BinaryNode extends Record<string, unknown>, ColumnCopy {
85
96
  /** Absent exactly when `operator` is IS NULL / IS NOT NULL. */
86
97
  right?: ExpressionNode;
87
98
  }
99
+ /** A calculation on two numbers (issue 26): `left + right`, `left / right`.
100
+ * A value, where `binary` is a condition. `a + b + c` nests, `(a + b) + c`;
101
+ * sqlGen writes parentheses only where the order needs them. Division
102
+ * keeps its fraction in every database unless sqlGen's `division` option
103
+ * says otherwise. */
104
+ export interface ArithmeticNode extends Record<string, unknown>, ColumnCopy {
105
+ type: 'arithmetic';
106
+ operator: ArithmeticOperator;
107
+ left: ExpressionNode;
108
+ right: ExpressionNode;
109
+ }
88
110
  export interface LogicalNode extends Record<string, unknown> {
89
111
  type: 'logical';
90
112
  operator: LogicalOperator;
@@ -1,4 +1,4 @@
1
- import type { ExpressionNode, ValueType } from './ast.js';
1
+ import type { ExpressionNode, FunctionCallNode, ValueType } from './ast.js';
2
2
  import type { DatabaseColumnType } from './schema.js';
3
3
  import type { SqlDialect } from './sqlGen.js';
4
4
  /**
@@ -13,8 +13,11 @@ import type { SqlDialect } from './sqlGen.js';
13
13
  * fixed-text — a text written into the SQL itself, never a parameter (STRING_AGG's
14
14
  * separator: MySQL takes only a literal there), stored as string literal,
15
15
  * shown as text input
16
+ * fixed-count — a whole number from 0 written into the SQL itself, never a parameter
17
+ * (LAG's offset: MySQL takes only a literal there), stored as number
18
+ * literal, shown as number input
16
19
  */
17
- export type ArgKind = 'expr' | 'date-expr' | 'num-expr' | 'str-expr' | 'unit' | 'type-name' | 'fixed-text';
20
+ export type ArgKind = 'expr' | 'date-expr' | 'num-expr' | 'str-expr' | 'unit' | 'type-name' | 'fixed-text' | 'fixed-count';
18
21
  /**
19
22
  * Maps ArgKind to the column types that should be shown when the arg value is a field.
20
23
  * Undefined means no filter (all column types are shown).
@@ -46,6 +49,10 @@ export interface FunctionSignature {
46
49
  * SQL allows one — SELECT, HAVING and ORDER BY, not WHERE, JOIN ON or
47
50
  * GROUP BY — and what makes a query grouped (see grouping.ts). */
48
51
  aggregate?: boolean;
52
+ /** A window function (issue 20: LAG, ROW_NUMBER, …): its call has `over`
53
+ * and an ORDER BY, and goes only in SELECT and ORDER BY, of a body that
54
+ * isn't grouped. */
55
+ window?: boolean;
49
56
  /** The type of its result (issue 130), so a value compared with it gets
50
57
  * the matching input: `'arg'` for its first argument's (MIN, COALESCE,
51
58
  * DATE_ADD). Omitted: not known (the user picks the value's type). */
@@ -112,6 +119,12 @@ export declare function normalizeRegistry(registry: FunctionRegistry): FunctionR
112
119
  /** `registry` without its aggregates — what's offered where SQL doesn't
113
120
  * allow one (WHERE, JOIN ON, GROUP BY). */
114
121
  export declare function withoutAggregates(registry: FunctionRegistry): FunctionRegistry;
122
+ /** A new call to `sig`, as a function picker starts one: its default
123
+ * arguments, and OVER for a window function (issue 20). `name` is what
124
+ * it's stored by. */
125
+ export declare function startCall(sig: FunctionSignature, name: string): FunctionCallNode;
126
+ /** `registry` without its window functions (issue 20). */
127
+ export declare function withoutWindows(registry: FunctionRegistry): FunctionRegistry;
115
128
  /** Only the functions available in `dialect` (those with no `dialects` list
116
129
  * are available everywhere). */
117
130
  export declare function functionsForDialect(registry: FunctionRegistry, dialect: SqlDialect): FunctionRegistry;
@@ -60,6 +60,11 @@ export declare const DEFAULT_MESSAGES: {
60
60
  removeElse: string;
61
61
  addArg: string;
62
62
  removeArg: string;
63
+ calcFirst: string;
64
+ calcSecond: string;
65
+ calcOperator: string;
66
+ /** Makes a calculation the first value of a new one. */
67
+ wrapInCalculation: string;
63
68
  typeField: string;
64
69
  typeValue: string;
65
70
  /** NULL, picked as a value (no value, on purpose). */
@@ -71,6 +76,8 @@ export declare const DEFAULT_MESSAGES: {
71
76
  typeDate: string;
72
77
  typeBoolean: string;
73
78
  typeFunction: string;
79
+ /** A calculation, `a + b` (issue 26). */
80
+ typeCalculation: string;
74
81
  typeExpression: string;
75
82
  /** A named param (set by the application, shown read-only). */
76
83
  typeParam: string;
@@ -94,6 +101,9 @@ export declare const DEFAULT_MESSAGES: {
94
101
  * (which group the rows) apart from the rest. Kept short: the list is
95
102
  * as narrow as the name box. */
96
103
  functionGroupAggregate: string;
104
+ /** Window functions (LAG, ROW_NUMBER, …): each looks at the rows around
105
+ * a row. */
106
+ functionGroupWindow: string;
97
107
  functionGroupOther: string;
98
108
  typeMenuCondition: string;
99
109
  /** IN's value as a query of its own (issue 122), when offered: its type,
@@ -239,6 +249,12 @@ export declare const DEFAULT_MESSAGES: {
239
249
  addSort: string;
240
250
  removeSort: string;
241
251
  toggleSortDirection: string;
252
+ /** A window function's OVER (issue 20): the columns its rows are split
253
+ * by, and their order. */
254
+ windowPartitionBy: string;
255
+ windowOrderBy: string;
256
+ addPartition: string;
257
+ removePartition: string;
242
258
  /** Opens the row-count inputs. */
243
259
  limitRows: string;
244
260
  removeLimit: string;
@@ -300,6 +316,7 @@ export declare const DEFAULT_MESSAGES: {
300
316
  locationColumn: (n: number) => string;
301
317
  locationGroupKey: (n: number) => string;
302
318
  locationSortKey: (n: number) => string;
319
+ locationPartitionKey: (n: number) => string;
303
320
  locationCondition: (n: number) => string;
304
321
  locationLeft: string;
305
322
  locationRight: string;
@@ -343,6 +360,9 @@ export declare const DEFAULT_MESSAGES: {
343
360
  issueSharedOrder: string;
344
361
  issueUnusedShared: string;
345
362
  issueJoinOnlyColumn: string;
363
+ issueMisplacedWindow: string;
364
+ issueGroupedWindow: string;
365
+ issueUnorderedWindow: string;
346
366
  issueUnknownTableNamed: (table: string) => string;
347
367
  issueUnknownColumnNamed: (table: string, column: string) => string;
348
368
  issueJoinOnlyColumnNamed: (column: string) => string;
@@ -370,6 +390,9 @@ export declare const DEFAULT_MESSAGES: {
370
390
  issueNotGroupedNamed: (column: string) => string;
371
391
  issueSelectAllGrouped: string;
372
392
  issueMisplacedAggregateNamed: (fn: string) => string;
393
+ issueMisplacedWindowNamed: (fn: string) => string;
394
+ issueGroupedWindowNamed: (fn: string) => string;
395
+ issueUnorderedWindowNamed: (fn: string) => string;
373
396
  peekHint: string;
374
397
  /** `keys`: its shortcut, as the user's keyboard has it (⌘F, Ctrl+F). */
375
398
  find: (keys: string) => string;
@@ -50,6 +50,11 @@ export type IssueLocationStep =
50
50
  kind: 'sortKey';
51
51
  number: number;
52
52
  }
53
+ /** One of a window call's PARTITION BY keys (issue 20), from 1. */
54
+ | {
55
+ kind: 'partitionKey';
56
+ number: number;
57
+ }
53
58
  /** One of a group's conditions (from 1). */
54
59
  | {
55
60
  kind: 'condition';
@@ -57,7 +62,7 @@ export type IssueLocationStep =
57
62
  } | {
58
63
  kind: 'not';
59
64
  }
60
- /** A comparison's side. */
65
+ /** A comparison's or a calculation's side. */
61
66
  | {
62
67
  kind: 'side';
63
68
  side: 'left' | 'right';
@@ -1,4 +1,4 @@
1
- import type { BinaryNode, BinaryOperator, ExistsNode, ExpressionNode, FieldNode, FunctionCallNode, LiteralNode, ListNode, LiteralValue, LogicalNode, LogicalOperator, NotNode, ParamNode, RelativeDate, SubqueryNode } from './ast.js';
1
+ import type { ArithmeticNode, ArithmeticOperator, BinaryNode, BinaryOperator, ExistsNode, ExpressionNode, FieldNode, FunctionCallNode, FunctionSortKey, LiteralNode, ListNode, LiteralValue, LogicalNode, LogicalOperator, NotNode, ParamNode, RelativeDate, SubqueryNode } from './ast.js';
2
2
  import { type DerivedQuery, type JoinClause, type TableFrom, type JoinType, type QueryPipeline, type QueryValue, type SortDirection } from './queryAst.js';
3
3
  import type { DatabaseSchema } from './schema.js';
4
4
  export declare const expr: {
@@ -17,6 +17,9 @@ export declare const expr: {
17
17
  }) => ParamNode;
18
18
  /** `left <operator> right`. */
19
19
  compare: (left: ExpressionNode, operator: BinaryOperator, right: ExpressionNode) => BinaryNode;
20
+ /** A calculation (issue 26), `left <operator> right`:
21
+ * `expr.calc(price, '*', quantity)`. */
22
+ calc: (left: ExpressionNode, operator: ArithmeticOperator, right: ExpressionNode) => ArithmeticNode;
20
23
  /** `operand IS NULL`. */
21
24
  isNull: (operand: ExpressionNode) => BinaryNode;
22
25
  /** `operand IS NOT NULL`. */
@@ -28,6 +31,14 @@ export declare const expr: {
28
31
  not: (operand: ExpressionNode) => NotNode;
29
32
  /** A function call: `expr.fn('LOWER', expr.field('users', 'email'))`. */
30
33
  fn: (name: string, ...args: ExpressionNode[]) => FunctionCallNode;
34
+ /** A window function's call (issue 20), over the rows of its body:
35
+ * `expr.over(expr.fn('LAG', status), { partitionBy: [employee], orderBy:
36
+ * [{ expression: payDate, direction: 'asc' }] })` is `LAG(status) OVER
37
+ * (PARTITION BY employee ORDER BY pay_date ASC)`. */
38
+ over: (call: FunctionCallNode, window: {
39
+ partitionBy?: ExpressionNode[];
40
+ orderBy?: FunctionSortKey[];
41
+ }) => FunctionCallNode;
31
42
  /** Whether the outer row has related rows: `EXISTS (SELECT 1 FROM …
32
43
  * WHERE <link> AND <where>)`. `link` matches them to the outer row;
33
44
  * `where` names the subquery's own tables only. NOT EXISTS:
@@ -61,6 +61,16 @@ export type QueryIssueKind =
61
61
  | 'unknownAggregate'
62
62
  /** An aggregate where SQL doesn't allow one: WHERE, JOIN ON, GROUP BY. */
63
63
  | 'misplacedAggregate'
64
+ /** A window function (issue 20) where SQL doesn't allow one: anywhere but
65
+ * SELECT and ORDER BY (WHERE, JOIN ON, GROUP BY, HAVING, an EXISTS), or
66
+ * inside another window function or an aggregate. */
67
+ | 'misplacedWindow'
68
+ /** A window function in a grouped query (aggregates, GROUP BY or
69
+ * HAVING): work it out in a sub query, and group around it. */
70
+ | 'groupedWindow'
71
+ /** A window function with no ORDER BY: which row comes before which
72
+ * isn't said, and SQL Server refuses it. */
73
+ | 'unorderedWindow'
64
74
  /** A param compared against columns of different types (`:x` against a
65
75
  * date and a number) — no one value suits both. */
66
76
  | 'paramConflict'
@@ -135,7 +145,7 @@ export type QueryIssueKind =
135
145
  /** A join-only column (a key, issue 234) used outside a join's ON or an
136
146
  * EXISTS's link, and not in a sub query's SELECT or GROUP BY. */
137
147
  | 'joinOnlyColumn';
138
- export declare const QUERY_ISSUE_KINDS: readonly ["invalidStructure", "duplicateId", "unknownTable", "unknownColumn", "tableNotInQuery", "unqualifiedField", "incomplete", "argCount", "ambiguousTable", "duplicateTableName", "derivedColumnName", "unknownFunction", "joinOrder", "distinctSort", "notGrouped", "unknownAggregate", "misplacedAggregate", "paramConflict", "fanOut", "crossJoin", "unlinkedJoin", "drillAcrossOutOfStep", "drillAcrossFilterMixed", "tooLong", "dialectUnsupported", "subqueryColumns", "notInSubquery", "noLimit", "limitTooHigh", "typeMismatch", "invalidPattern", "unionColumns", "unionTypes", "sharedOrder", "unusedShared", "joinOnlyColumn"];
148
+ export declare const QUERY_ISSUE_KINDS: readonly ["invalidStructure", "duplicateId", "unknownTable", "unknownColumn", "tableNotInQuery", "unqualifiedField", "incomplete", "argCount", "ambiguousTable", "duplicateTableName", "derivedColumnName", "unknownFunction", "joinOrder", "distinctSort", "notGrouped", "unknownAggregate", "misplacedAggregate", "paramConflict", "fanOut", "crossJoin", "misplacedWindow", "groupedWindow", "unorderedWindow", "unlinkedJoin", "drillAcrossOutOfStep", "drillAcrossFilterMixed", "tooLong", "dialectUnsupported", "subqueryColumns", "notInSubquery", "noLimit", "limitTooHigh", "typeMismatch", "invalidPattern", "unionColumns", "unionTypes", "sharedOrder", "unusedShared", "joinOnlyColumn"];
139
149
  /** The kinds that are warnings: the query can run with them. Only these
140
150
  * can be hidden (ValidateQueryOptions' hideWarnings). */
141
151
  export declare const QUERY_WARNING_KINDS: readonly ["fanOut", "crossJoin", "unlinkedJoin", "drillAcrossFilterMixed", "notInSubquery", "noLimit", "limitTooHigh", "typeMismatch", "unknownAggregate", "unusedShared"];
@@ -29,6 +29,12 @@ export declare function writeMarked<T>(marks: SpanMarks, write: () => T): T;
29
29
  * NULL AND b IS NULL))`, the same rows in any database, for SQL Server
30
30
  * before 2022, which has no IS NOT DISTINCT FROM. */
31
31
  export type NullSafeEqual = 'native' | 'expanded';
32
+ /** How a calculation's `/` is written (issue 26). `'decimal'`: with its
33
+ * fraction in every database, `5 / 2` is 2.5 — written `a * 1.0 / b` in
34
+ * PostgreSQL and SQL Server, which drop it when both sides are whole
35
+ * numbers (MySQL's `/` keeps it). `'native'`: `a / b`, each database's
36
+ * own division. */
37
+ export type Division = 'decimal' | 'native';
32
38
  export declare function astToWhereClause(ast: ExpressionNode, dialect: SqlDialect, params?: SqlParams): string;
33
39
  export declare function formatFromClause(from: FromClause, dialect: SqlDialect, params?: SqlParams): string;
34
40
  export declare function formatJoinClause(join: JoinClause, dialect: SqlDialect, params?: SqlParams): string;
@@ -66,6 +72,8 @@ export declare function astToSql(pipeline: QueryPipeline, dialect: SqlDialect, o
66
72
  schema?: DatabaseSchema;
67
73
  /** How a null-safe equal is written (see ParameterizedSqlOptions). */
68
74
  nullSafeEqual?: NullSafeEqual;
75
+ /** How a calculation divides (see ParameterizedSqlOptions). */
76
+ division?: Division;
69
77
  }): string;
70
78
  /** SQL with its values as bound parameters, for executing it. */
71
79
  export interface ParameterizedSql {
@@ -101,6 +109,10 @@ export interface ParameterizedSqlOptions {
101
109
  /** How `IS NOT DISTINCT FROM` is written: `'native'` (default), or
102
110
  * `'expanded'` into `=` and IS NULL for SQL Server before 2022. */
103
111
  nullSafeEqual?: NullSafeEqual;
112
+ /** How a calculation's `/` is written: `'decimal'` (default), with its
113
+ * fraction everywhere (`5 / 2` is 2.5), or `'native'`, each database's
114
+ * own (2 in PostgreSQL and SQL Server for two whole numbers). */
115
+ division?: Division;
104
116
  }
105
117
  /** The query as SQL whose values — in WHERE, JOIN ON and SELECT, including
106
118
  * inside functions, IF/CASE and IN lists — are bound parameters rather than
@@ -2,7 +2,7 @@ import type { LiteralValue } from './ast.js';
2
2
  import type { QueryValue } from './queryAst.js';
3
3
  /** The format saveQuery writes. Raised when a change to the query's shape
4
4
  * needs older stored queries migrated (see MIGRATIONS). */
5
- export declare const QUERY_FORMAT_VERSION = 4;
5
+ export declare const QUERY_FORMAT_VERSION = 6;
6
6
  /** A query as stored: plain JSON, with the format it's in. */
7
7
  export interface StoredQuery {
8
8
  version: number;
@@ -3,7 +3,7 @@ export { MAX_NUMBER_DIGITS, MAX_TEXT_LENGTH, MAX_TYPE_NAME_LENGTH } from './core
3
3
  export { calendarDay, fromIsoDay, isoDay } from './core/calendarDate.js';
4
4
  export { createEmptyQuery } from './core/pipelineFlow.js';
5
5
  export { addMeasure, keepMeasuresInStep, measureFacts, type MeasureFact, type MeasureSpec, } from './core/measures.js';
6
- export type { BinaryNode, BinaryOperator, CaseNode, ExistsNode, ExistsQuery, ExpressionNode, FieldNode, FunctionCallNode, FunctionSortKey, IfNode, LiteralNode, LiteralValue, LogicalNode, LogicalOperator, NotNode, ParamNode, RelativeDate, ListNode, SubqueryNode, } from './core/ast.js';
6
+ export type { ArithmeticNode, ArithmeticOperator, BinaryNode, BinaryOperator, CaseNode, ExistsNode, ExistsQuery, ExpressionNode, FieldNode, FunctionCallNode, FunctionSortKey, IfNode, LiteralNode, LiteralValue, LogicalNode, LogicalOperator, NotNode, ParamNode, RelativeDate, ListNode, SubqueryNode, } from './core/ast.js';
7
7
  export { addUnionBranch, addUnionJoin, addUnionTable, createUnion, removeUnionTable, renameUnionColumn, setUnionAll, unwrapUnion, unionName, unionWithQuery, unionableTables, unionTableColumns, type UnionTableOptions, type UnionTableColumn, type UnionTableColumnKind, type UnionTableSpec, } from './core/unionTables.js';
8
8
  export { SharedBaseError, addSharedQuery, joinSharedQuery, makeShared, makeSubQuery, removeSharedQuery, renameSharedQuery, setSharedBase, sharedQueryName, sharedUses, } from './core/sharedQueries.js';
9
9
  export { joinMultiplicity, repeatedReads, repeatedTables, rowsPerBase, type JoinMultiplicity, } from './core/fanOut.js';
@@ -13,7 +13,7 @@ export { queryParams, type ParamColumn, type QueryParam } from './core/params.js
13
13
  export { relativeDateLabel } from './core/relativeDates.js';
14
14
  export { QUERY_FORMAT_VERSION, QueryFormatError, loadQuery, saveQuery, type StoredQuery, } from './core/storedQuery.js';
15
15
  export type { ResolveName } from './core/resolveNames.js';
16
- export { astToParameterizedSql, astToSql, DIALECTS, DIALECT_LABELS, type NullSafeEqual, type ParameterizedSql, type ParameterizedSqlOptions, type SqlDialect, } from './core/sqlGen.js';
16
+ export { astToParameterizedSql, astToSql, DIALECTS, DIALECT_LABELS, type Division, type NullSafeEqual, type ParameterizedSql, type ParameterizedSqlOptions, type SqlDialect, } from './core/sqlGen.js';
17
17
  export { EMPTY_SCHEMA, filterSchema, validateSchema, type DatabaseColumnType, type DatabaseSchema, type ColumnOption, type Relation, findJoinPath, reachableTables, suggestJoin, type JoinPathOptions, type JoinSuggestion, type SuggestJoinOptions, type SchemaIssue, type SchemaIssueKind, type Table, type TableColumn, type TableGroup, } from './core/schema.js';
18
18
  export { QUERY_ISSUE_KINDS, QUERY_WARNING_KINDS, validateQuery, type QueryIssue, type QueryIssueKind, type QueryWarningKind, type QueryIssueSeverity, type ValidateQueryOptions, } from './core/queryValidation.js';
19
19
  export type { OnExplain, PlanFinding, PlanFindingKind } from './core/planFindings.js';
@@ -7,8 +7,8 @@ import type { SqlQuery, SqlSpan } from './syntax.js';
7
7
  import { type SqlPosition } from './tokenize.js';
8
8
  /** What can stop SQL from being imported:
9
9
  * - `syntax`: SQL that can't be read at all.
10
- * - `unsupported`: SQL the query can't hold (UNION at the top, WITH,
11
- * arithmetic, a window function, …).
10
+ * - `unsupported`: SQL the query can't hold (a window frame, RECURSIVE,
11
+ * `||`, …).
12
12
  * - `unknownTable`, `unknownColumn`: a name the schema doesn't have.
13
13
  * - `ambiguousColumn`: a column name more than one table has.
14
14
  * - `duplicateTable`: two tables of one query by the same name.
@@ -111,8 +111,16 @@ export interface SqlBetween {
111
111
  high: SqlExpr;
112
112
  span: SqlSpan;
113
113
  }
114
- /** A function call, with what aggregates take besides arguments. A window
115
- * (`OVER …`) and PostgreSQL's FILTER are only marked: the AST has neither. */
114
+ /** A window's `OVER (PARTITION BY … ORDER BY …)`. A frame (`ROWS
115
+ * BETWEEN …`) is only marked: the AST has none. */
116
+ export interface SqlWindow {
117
+ partitionBy: SqlExpr[];
118
+ orderBy?: SqlOrderItem[];
119
+ frame?: SqlSpan;
120
+ }
121
+ /** A function call, with what aggregates take besides arguments. PostgreSQL's
122
+ * FILTER is only marked: the AST has none. `over` is the whole `OVER …`,
123
+ * and `window` what's in it — none for a named window (`OVER w`). */
116
124
  export interface SqlCall {
117
125
  kind: 'call';
118
126
  name: SqlIdent[];
@@ -126,6 +134,7 @@ export interface SqlCall {
126
134
  withinGroup?: SqlOrderItem[];
127
135
  filter?: SqlSpan;
128
136
  over?: SqlSpan;
137
+ window?: SqlWindow;
129
138
  span: SqlSpan;
130
139
  }
131
140
  /** `CAST(x AS type)`, or PostgreSQL's `x::type`. `type` as written, its
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nongt/visql-core",
3
- "version": "0.10.1",
3
+ "version": "0.12.0",
4
4
  "description": "The query logic of @nongt/visql, for a backend: load, check, scope, write SQL, import SQL, read query plans. No React, no dependencies.",
5
5
  "keywords": [
6
6
  "sql",