Skip to content

Commit a41330b

Browse files
committed
Add INSERT, UPDATE, and DELETE statement types
1 parent 10be2a0 commit a41330b

3 files changed

Lines changed: 500 additions & 3 deletions

File tree

lib/data-type.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ import type { ObjectName, Ident } from "./ident";
33
import type { Keyword } from "./keyword";
44
import type { Token } from "./token";
55

6+
/**
7+
* Specifies Ignore / Respect NULL within window functions.
8+
* For example `FIRST_VALUE(column2) IGNORE NULLS OVER (PARTITION BY column1)`
9+
*
10+
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/enum.NullTreatment.html
11+
*/
12+
export type NullTreatment =
13+
| 'IgnoreNulls'
14+
| 'RespectNulls';
15+
616
/**
717
* Simple SQL data types.
818
*

lib/function.ts

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,175 @@
1+
import { NullTreatment } from "./data-type";
12
import type { Expr } from "./expr";
23
import type { Ident, ObjectName } from "./ident";
4+
import { OrderByExpr, Query } from "./statement";
5+
import { Value } from "./token";
6+
7+
/**
8+
* A function call
9+
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/struct.Function.html
10+
*/
11+
export interface SQLFunction {
12+
name: ObjectName,
13+
uses_odbc_syntax: boolean,
14+
parameters: FunctionArguments,
15+
args: FunctionArguments,
16+
filter?: Expr,
17+
null_treatment?: NullTreatment,
18+
over?: WindowType,
19+
within_group: OrderByExpr[],
20+
}
21+
22+
/**
23+
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/enum.WindowType.html
24+
*/
25+
export type WindowType = {
26+
WindowSpec?: WindowSpec;
27+
NamedWindow?: Ident;
28+
}
29+
30+
/**
31+
* A window specification (i.e. `OVER ([window_name] PARTITION BY .. ORDER BY .. etc.)`)
32+
*
33+
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/struct.WindowSpec.html
34+
*/
35+
export interface WindowSpec {
36+
window_name?: Ident,
37+
partition_by: Expr[],
38+
order_by: OrderByExpr[],
39+
window_frame?: WindowFrame,
40+
}
41+
42+
/**
43+
*
44+
Specifies the data processed by a window function, e.g. `RANGE UNBOUNDED PRECEDING` or `ROWS BETWEEN 5 PRECEDING AND CURRENT ROW`.
45+
46+
Note: The parser does not validate the specified bounds; the caller should reject invalid bounds like `ROWS UNBOUNDED FOLLOWING` before execution.
47+
*
48+
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/struct.WindowFrame.html
49+
*/
50+
export interface WindowFrame {
51+
units: WindowFrameUnits;
52+
start_bound: WindowFrameBound;
53+
end_bound?: WindowFrameBound;
54+
}
55+
56+
/**
57+
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/enum.WindowFrameUnits.html
58+
*/
59+
export type WindowFrameUnits = 'Rows' | 'Range' | 'Groups';
60+
61+
/**
62+
* Specifies WindowFrame’s `start_bound` and `end_bound`.
63+
*
64+
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/enum.WindowFrameBound.html
65+
*/
66+
export type WindowFrameBound = 'CurrentRow' | {
67+
/**
68+
* `<N> PRECEDING` or `UNBOUNDED PRECEDING`
69+
*/
70+
Preceding?: Expr | undefined;
71+
72+
/**
73+
* `<N> FOLLOWING` or `UNBOUNDED FOLLOWING`
74+
*/
75+
Following?: Expr | undefined;
76+
}
77+
78+
/**
79+
* The arguments passed to a function call.
80+
*
81+
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/enum.FunctionArguments.html
82+
*/
83+
export type FunctionArguments = 'None' | {
84+
/**
85+
* On some dialects, a subquery can be passed without surrounding parentheses if it’s the sole argument to the function.
86+
*/
87+
Subquery?: Query;
88+
89+
/**
90+
* A normal function argument list, including any clauses within it such as `DISTINCT` or `ORDER BY`.
91+
*/
92+
List?: FunctionArgumentList;
93+
}
94+
95+
/**
96+
* This represents everything inside the parentheses when calling a function.
97+
*
98+
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/struct.FunctionArgumentList.html
99+
*/
100+
export interface FunctionArgumentList {
101+
/**
102+
* `[ ALL | DISTINCT ]`
103+
*/
104+
duplicate_treatment?: DuplicateTreatment,
105+
106+
/**
107+
* The function arguments.
108+
*/
109+
args: FunctionArg[],
110+
111+
/**
112+
* Additional clauses specified within the argument list.
113+
*/
114+
clauses: FunctionArgumentClause[],
115+
}
116+
117+
/**
118+
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/enum.DuplicateTreatment.html
119+
*/
120+
export type DuplicateTreatment =
121+
| 'Distinct'
122+
| 'All';
123+
124+
/**
125+
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/enum.FunctionArgumentClause.html
126+
*/
127+
export type FunctionArgumentClause = {
128+
/**
129+
* Indicates how NULLs should be handled in the calculation, e.g. in `FIRST_VALUE` on BigQuery.
130+
*
131+
* Syntax:
132+
* `{ IGNORE | RESPECT } NULLS ]`
133+
*/
134+
IgnoreOrRespectNulls?: NullTreatment;
135+
136+
/**
137+
* Specifies the the ordering for some ordered set aggregates, e.g. `ARRAY_AGG` on BigQuery.
138+
*/
139+
OrderBy?: OrderByExpr[];
140+
141+
/**
142+
* Specifies a limit for the `ARRAY_AGG` and `ARRAY_CONCAT_AGG` functions on BigQuery.
143+
*/
144+
Limit?: Expr;
145+
146+
/**
147+
* Specifies the behavior on overflow of the LISTAGG function.
148+
*
149+
* @see https://trino.io/docs/current/functions/aggregate.html
150+
*/
151+
OnOverflow?: unknown;
152+
153+
/**
154+
* Specifies a minimum or maximum bound on the input to ANY_VALUE on BigQuery.
155+
*/
156+
Having?: unknown;
157+
158+
/**
159+
* The `SEPARATOR` clause to the `GROUP_CONCAT` function in MySQL.
160+
*/
161+
Separator?: Value;
162+
163+
/**
164+
* The `ON NULL` clause for some JSON functions.
165+
*/
166+
JsonNullClause?: unknown; // TODO: Define proper type
167+
168+
/**
169+
* The `RETURNING` clause for some JSON functions in PostgreSQL
170+
*/
171+
JsonReturningClause?: unknown; // TODO: Define proper type
172+
}
3173

4174
/**
5175
* A function argument.

0 commit comments

Comments
 (0)