Skip to content

Commit 748cbf5

Browse files
committed
Add Truncate statement
1 parent ef12414 commit 748cbf5

1 file changed

Lines changed: 43 additions & 1 deletion

File tree

lib/statement.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@ export type Statement = {
2020

2121
Analyze?: unknown;
2222
Set?: unknown;
23-
Truncate?: unknown;
23+
Truncate?: {
24+
table_names: TruncateTableTarget,
25+
partitions?: Expr[],
26+
table: boolean,
27+
identity?: TruncateIdentityOption,
28+
cascade?: CascadeOption,
29+
on_cluster?: Ident,
30+
};
2431
Msck?: unknown;
2532
Install?: unknown;
2633
Load?: unknown
@@ -132,6 +139,41 @@ export type Statement = {
132139
Vacuum?: unknown;
133140
}
134141

142+
/**
143+
* Target of a `TRUNCATE TABLE` command.
144+
* Note this is its own struct because `visit_relation` requires an `ObjectName` (not a `ObjectName[]`)
145+
*
146+
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/struct.TruncateTableTarget.html
147+
*/
148+
export interface TruncateTableTarget {
149+
/**
150+
* name of the table being truncated
151+
*/
152+
name: ObjectName;
153+
154+
/**
155+
* Postgres-specific option [ TRUNCATE TABLE ONLY ] https://www.postgresql.org/docs/current/sql-truncate.html
156+
*/
157+
only: boolean;
158+
}
159+
160+
/**
161+
* PostgreSQL identity option for TRUNCATE table [ RESTART IDENTITY | CONTINUE IDENTITY ]
162+
*
163+
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/enum.TruncateIdentityOption.html
164+
*/
165+
export type TruncateIdentityOption =
166+
| 'Restart'
167+
| 'Continue';
168+
169+
/**
170+
* Cascade/restrict option for Postgres TRUNCATE table, MySQL GRANT/REVOKE, etc. [ CASCADE | RESTRICT ]
171+
*
172+
* @see https://docs.rs/sqlparser/latest/sqlparser/ast/enum.CascadeOption.html
173+
*/
174+
export type CascadeOption =
175+
| 'Cascade'
176+
| 'Restrict';
135177

136178

137179
/**

0 commit comments

Comments
 (0)