@guanmingchiu/sqlparser-ts 0.60.0-rc3
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/README.md +89 -0
- package/dist/index.cjs +403 -0
- package/dist/index.d.cts +1309 -0
- package/dist/index.d.mts +1309 -0
- package/dist/index.mjs +379 -0
- package/package.json +62 -0
- package/wasm/LICENSE +201 -0
- package/wasm/README.md +89 -0
- package/wasm/package.json +17 -0
- package/wasm/sqlparser_rs_wasm.d.ts +39 -0
- package/wasm/sqlparser_rs_wasm.js +541 -0
- package/wasm/sqlparser_rs_wasm_bg.wasm +0 -0
- package/wasm/sqlparser_rs_wasm_bg.wasm.d.ts +19 -0
- package/wasm/sqlparser_rs_wasm_web.js +628 -0
- package/wasm/sqlparser_rs_wasm_web_bg.wasm +0 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,1309 @@
|
|
|
1
|
+
//#region src/dialects.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* SQL Dialects
|
|
4
|
+
*
|
|
5
|
+
* Each dialect class represents a specific SQL dialect supported by the parser.
|
|
6
|
+
* These are thin wrappers that provide type safety and a clean API.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Base interface for all dialects
|
|
10
|
+
*/
|
|
11
|
+
interface Dialect {
|
|
12
|
+
/** The name of the dialect as recognized by the WASM module */
|
|
13
|
+
readonly name: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Generic SQL dialect - accepts most SQL syntax
|
|
17
|
+
*/
|
|
18
|
+
declare class GenericDialect implements Dialect {
|
|
19
|
+
readonly name = "generic";
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* ANSI SQL standard dialect
|
|
23
|
+
*/
|
|
24
|
+
declare class AnsiDialect implements Dialect {
|
|
25
|
+
readonly name = "ansi";
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* MySQL dialect
|
|
29
|
+
*/
|
|
30
|
+
declare class MySqlDialect implements Dialect {
|
|
31
|
+
readonly name = "mysql";
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* PostgreSQL dialect
|
|
35
|
+
*/
|
|
36
|
+
declare class PostgreSqlDialect implements Dialect {
|
|
37
|
+
readonly name = "postgresql";
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* SQLite dialect
|
|
41
|
+
*/
|
|
42
|
+
declare class SQLiteDialect implements Dialect {
|
|
43
|
+
readonly name = "sqlite";
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Snowflake dialect
|
|
47
|
+
*/
|
|
48
|
+
declare class SnowflakeDialect implements Dialect {
|
|
49
|
+
readonly name = "snowflake";
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Amazon Redshift dialect
|
|
53
|
+
*/
|
|
54
|
+
declare class RedshiftDialect implements Dialect {
|
|
55
|
+
readonly name = "redshift";
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Microsoft SQL Server dialect
|
|
59
|
+
*/
|
|
60
|
+
declare class MsSqlDialect implements Dialect {
|
|
61
|
+
readonly name = "mssql";
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* ClickHouse dialect
|
|
65
|
+
*/
|
|
66
|
+
declare class ClickHouseDialect implements Dialect {
|
|
67
|
+
readonly name = "clickhouse";
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Google BigQuery dialect
|
|
71
|
+
*/
|
|
72
|
+
declare class BigQueryDialect implements Dialect {
|
|
73
|
+
readonly name = "bigquery";
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* DuckDB dialect
|
|
77
|
+
*/
|
|
78
|
+
declare class DuckDbDialect implements Dialect {
|
|
79
|
+
readonly name = "duckdb";
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Databricks dialect
|
|
83
|
+
*/
|
|
84
|
+
declare class DatabricksDialect implements Dialect {
|
|
85
|
+
readonly name = "databricks";
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Apache Hive dialect
|
|
89
|
+
*/
|
|
90
|
+
declare class HiveDialect implements Dialect {
|
|
91
|
+
readonly name = "hive";
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Oracle dialect
|
|
95
|
+
*/
|
|
96
|
+
declare class OracleDialect implements Dialect {
|
|
97
|
+
readonly name = "oracle";
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* All supported dialect names
|
|
101
|
+
*/
|
|
102
|
+
declare const SUPPORTED_DIALECTS: readonly ["generic", "ansi", "mysql", "postgresql", "sqlite", "snowflake", "redshift", "mssql", "clickhouse", "bigquery", "duckdb", "databricks", "hive", "oracle"];
|
|
103
|
+
type DialectName = (typeof SUPPORTED_DIALECTS)[number];
|
|
104
|
+
/** Create a dialect instance from a string name (case-insensitive) */
|
|
105
|
+
declare function dialectFromString(name: string): Dialect | undefined;
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/types/ast.d.ts
|
|
108
|
+
/**
|
|
109
|
+
* TypeScript type definitions for sqlparser-ts AST
|
|
110
|
+
*
|
|
111
|
+
* These types mirror the Rust AST structure from the sqlparser crate.
|
|
112
|
+
* The AST is serialized as JSON from Rust, so these types represent
|
|
113
|
+
* the JSON structure.
|
|
114
|
+
*/
|
|
115
|
+
/**
|
|
116
|
+
* An identifier (table name, column name, etc.)
|
|
117
|
+
*/
|
|
118
|
+
interface Ident {
|
|
119
|
+
value: string;
|
|
120
|
+
quoteStyle?: string | null;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* A compound identifier like schema.table.column
|
|
124
|
+
*/
|
|
125
|
+
type ObjectName = Ident[];
|
|
126
|
+
/**
|
|
127
|
+
* Binary operators
|
|
128
|
+
*/
|
|
129
|
+
type BinaryOperator = 'Plus' | 'Minus' | 'Multiply' | 'Divide' | 'Modulo' | 'StringConcat' | 'Gt' | 'Lt' | 'GtEq' | 'LtEq' | 'Spaceship' | 'Eq' | 'NotEq' | 'And' | 'Or' | 'Xor' | 'BitwiseOr' | 'BitwiseAnd' | 'BitwiseXor' | 'PGBitwiseXor' | 'PGBitwiseShiftLeft' | 'PGBitwiseShiftRight' | 'PGRegexMatch' | 'PGRegexIMatch' | 'PGRegexNotMatch' | 'PGRegexNotIMatch';
|
|
130
|
+
/**
|
|
131
|
+
* Unary operators
|
|
132
|
+
*/
|
|
133
|
+
type UnaryOperator = 'Plus' | 'Minus' | 'Not' | 'PGBitwiseNot' | 'PGSquareRoot' | 'PGCubeRoot' | 'PGPostfixFactorial' | 'PGPrefixFactorial' | 'PGAbs';
|
|
134
|
+
/**
|
|
135
|
+
* SQL Value types
|
|
136
|
+
*/
|
|
137
|
+
type Value = {
|
|
138
|
+
Number: [string, boolean];
|
|
139
|
+
} | {
|
|
140
|
+
SingleQuotedString: string;
|
|
141
|
+
} | {
|
|
142
|
+
DoubleQuotedString: string;
|
|
143
|
+
} | {
|
|
144
|
+
DollarQuotedString: {
|
|
145
|
+
value: string;
|
|
146
|
+
tag?: string;
|
|
147
|
+
};
|
|
148
|
+
} | {
|
|
149
|
+
EscapedStringLiteral: string;
|
|
150
|
+
} | {
|
|
151
|
+
NationalStringLiteral: string;
|
|
152
|
+
} | {
|
|
153
|
+
HexStringLiteral: string;
|
|
154
|
+
} | {
|
|
155
|
+
Boolean: boolean;
|
|
156
|
+
} | {
|
|
157
|
+
Null: null;
|
|
158
|
+
} | {
|
|
159
|
+
Placeholder: string;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* SQL Expression
|
|
163
|
+
*/
|
|
164
|
+
type Expr = {
|
|
165
|
+
Identifier: Ident;
|
|
166
|
+
} | {
|
|
167
|
+
CompoundIdentifier: Ident[];
|
|
168
|
+
} | {
|
|
169
|
+
Value: Value;
|
|
170
|
+
} | {
|
|
171
|
+
BinaryOp: {
|
|
172
|
+
left: Expr;
|
|
173
|
+
op: BinaryOperator;
|
|
174
|
+
right: Expr;
|
|
175
|
+
};
|
|
176
|
+
} | {
|
|
177
|
+
UnaryOp: {
|
|
178
|
+
op: UnaryOperator;
|
|
179
|
+
expr: Expr;
|
|
180
|
+
};
|
|
181
|
+
} | {
|
|
182
|
+
Nested: Expr;
|
|
183
|
+
} | {
|
|
184
|
+
IsNull: Expr;
|
|
185
|
+
} | {
|
|
186
|
+
IsNotNull: Expr;
|
|
187
|
+
} | {
|
|
188
|
+
IsTrue: Expr;
|
|
189
|
+
} | {
|
|
190
|
+
IsFalse: Expr;
|
|
191
|
+
} | {
|
|
192
|
+
IsUnknown: Expr;
|
|
193
|
+
} | {
|
|
194
|
+
IsNotTrue: Expr;
|
|
195
|
+
} | {
|
|
196
|
+
IsNotFalse: Expr;
|
|
197
|
+
} | {
|
|
198
|
+
IsNotUnknown: Expr;
|
|
199
|
+
} | {
|
|
200
|
+
InList: {
|
|
201
|
+
expr: Expr;
|
|
202
|
+
list: Expr[];
|
|
203
|
+
negated: boolean;
|
|
204
|
+
};
|
|
205
|
+
} | {
|
|
206
|
+
InSubquery: {
|
|
207
|
+
expr: Expr;
|
|
208
|
+
subquery: Query;
|
|
209
|
+
negated: boolean;
|
|
210
|
+
};
|
|
211
|
+
} | {
|
|
212
|
+
Between: {
|
|
213
|
+
expr: Expr;
|
|
214
|
+
negated: boolean;
|
|
215
|
+
low: Expr;
|
|
216
|
+
high: Expr;
|
|
217
|
+
};
|
|
218
|
+
} | {
|
|
219
|
+
Like: {
|
|
220
|
+
expr: Expr;
|
|
221
|
+
negated: boolean;
|
|
222
|
+
pattern: Expr;
|
|
223
|
+
escapeChar?: string;
|
|
224
|
+
};
|
|
225
|
+
} | {
|
|
226
|
+
ILike: {
|
|
227
|
+
expr: Expr;
|
|
228
|
+
negated: boolean;
|
|
229
|
+
pattern: Expr;
|
|
230
|
+
escapeChar?: string;
|
|
231
|
+
};
|
|
232
|
+
} | {
|
|
233
|
+
SimilarTo: {
|
|
234
|
+
expr: Expr;
|
|
235
|
+
negated: boolean;
|
|
236
|
+
pattern: Expr;
|
|
237
|
+
escapeChar?: string;
|
|
238
|
+
};
|
|
239
|
+
} | {
|
|
240
|
+
Case: {
|
|
241
|
+
operand?: Expr;
|
|
242
|
+
conditions: Expr[];
|
|
243
|
+
results: Expr[];
|
|
244
|
+
elseResult?: Expr;
|
|
245
|
+
};
|
|
246
|
+
} | {
|
|
247
|
+
Cast: {
|
|
248
|
+
expr: Expr;
|
|
249
|
+
dataType: DataType;
|
|
250
|
+
};
|
|
251
|
+
} | {
|
|
252
|
+
TryCast: {
|
|
253
|
+
expr: Expr;
|
|
254
|
+
dataType: DataType;
|
|
255
|
+
};
|
|
256
|
+
} | {
|
|
257
|
+
SafeCast: {
|
|
258
|
+
expr: Expr;
|
|
259
|
+
dataType: DataType;
|
|
260
|
+
};
|
|
261
|
+
} | {
|
|
262
|
+
Extract: {
|
|
263
|
+
field: DateTimeField;
|
|
264
|
+
expr: Expr;
|
|
265
|
+
};
|
|
266
|
+
} | {
|
|
267
|
+
Substring: {
|
|
268
|
+
expr: Expr;
|
|
269
|
+
substringFrom?: Expr;
|
|
270
|
+
substringFor?: Expr;
|
|
271
|
+
};
|
|
272
|
+
} | {
|
|
273
|
+
Trim: {
|
|
274
|
+
expr: Expr;
|
|
275
|
+
trimWhere?: TrimWhereField;
|
|
276
|
+
trimWhat?: Expr;
|
|
277
|
+
};
|
|
278
|
+
} | {
|
|
279
|
+
Collate: {
|
|
280
|
+
expr: Expr;
|
|
281
|
+
collation: ObjectName;
|
|
282
|
+
};
|
|
283
|
+
} | {
|
|
284
|
+
Function: FunctionExpr;
|
|
285
|
+
} | {
|
|
286
|
+
Subquery: Query;
|
|
287
|
+
} | {
|
|
288
|
+
Exists: {
|
|
289
|
+
subquery: Query;
|
|
290
|
+
negated: boolean;
|
|
291
|
+
};
|
|
292
|
+
} | {
|
|
293
|
+
Wildcard: null;
|
|
294
|
+
} | {
|
|
295
|
+
QualifiedWildcard: ObjectName;
|
|
296
|
+
} | {
|
|
297
|
+
Tuple: Expr[];
|
|
298
|
+
} | {
|
|
299
|
+
Array: {
|
|
300
|
+
elem: Expr[];
|
|
301
|
+
named: boolean;
|
|
302
|
+
};
|
|
303
|
+
} | {
|
|
304
|
+
MapAccess: {
|
|
305
|
+
column: Expr;
|
|
306
|
+
keys: Expr[];
|
|
307
|
+
};
|
|
308
|
+
} | {
|
|
309
|
+
CompositeAccess: {
|
|
310
|
+
expr: Expr;
|
|
311
|
+
key: Ident;
|
|
312
|
+
};
|
|
313
|
+
} | {
|
|
314
|
+
TypedString: {
|
|
315
|
+
dataType: DataType;
|
|
316
|
+
value: string;
|
|
317
|
+
};
|
|
318
|
+
} | {
|
|
319
|
+
AtTimeZone: {
|
|
320
|
+
timestamp: Expr;
|
|
321
|
+
timeZone: string;
|
|
322
|
+
};
|
|
323
|
+
} | {
|
|
324
|
+
Interval: IntervalExpr;
|
|
325
|
+
} | 'Wildcard';
|
|
326
|
+
/**
|
|
327
|
+
* Function expression
|
|
328
|
+
*/
|
|
329
|
+
interface FunctionExpr {
|
|
330
|
+
name: ObjectName;
|
|
331
|
+
args: FunctionArg[];
|
|
332
|
+
over?: WindowSpec;
|
|
333
|
+
distinct: boolean;
|
|
334
|
+
special: boolean;
|
|
335
|
+
orderBy: OrderByExpr[];
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Function argument
|
|
339
|
+
*/
|
|
340
|
+
type FunctionArg = {
|
|
341
|
+
Unnamed: FunctionArgExpr;
|
|
342
|
+
} | {
|
|
343
|
+
Named: {
|
|
344
|
+
name: Ident;
|
|
345
|
+
arg: FunctionArgExpr;
|
|
346
|
+
};
|
|
347
|
+
};
|
|
348
|
+
type FunctionArgExpr = {
|
|
349
|
+
Expr: Expr;
|
|
350
|
+
} | {
|
|
351
|
+
QualifiedWildcard: ObjectName;
|
|
352
|
+
} | 'Wildcard';
|
|
353
|
+
/**
|
|
354
|
+
* Interval expression
|
|
355
|
+
*/
|
|
356
|
+
interface IntervalExpr {
|
|
357
|
+
value: Expr;
|
|
358
|
+
leadingField?: DateTimeField;
|
|
359
|
+
leadingPrecision?: number;
|
|
360
|
+
lastField?: DateTimeField;
|
|
361
|
+
fractionalSecondsPrecision?: number;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Date/time field for EXTRACT
|
|
365
|
+
*/
|
|
366
|
+
type DateTimeField = 'Year' | 'Month' | 'Week' | 'Day' | 'Hour' | 'Minute' | 'Second' | 'Millisecond' | 'Microsecond' | 'Nanosecond' | 'Century' | 'Decade' | 'Dow' | 'Doy' | 'Epoch' | 'Isodow' | 'Isoyear' | 'Julian' | 'Quarter' | 'Timezone' | 'TimezoneHour' | 'TimezoneMinute';
|
|
367
|
+
/**
|
|
368
|
+
* Trim where field
|
|
369
|
+
*/
|
|
370
|
+
type TrimWhereField = 'Both' | 'Leading' | 'Trailing';
|
|
371
|
+
/**
|
|
372
|
+
* SQL Data types
|
|
373
|
+
*/
|
|
374
|
+
type DataType = 'Boolean' | 'TinyInt' | 'SmallInt' | 'Int' | 'Integer' | 'BigInt' | {
|
|
375
|
+
Float: number | null;
|
|
376
|
+
} | 'Real' | 'Double' | {
|
|
377
|
+
Decimal: [number | null, number | null];
|
|
378
|
+
} | {
|
|
379
|
+
Numeric: [number | null, number | null];
|
|
380
|
+
} | {
|
|
381
|
+
Varchar: number | null;
|
|
382
|
+
} | {
|
|
383
|
+
Char: number | null;
|
|
384
|
+
} | 'Text' | 'Uuid' | 'Date' | {
|
|
385
|
+
Time: [number | null, boolean];
|
|
386
|
+
} | {
|
|
387
|
+
Timestamp: [number | null, boolean];
|
|
388
|
+
} | 'Interval' | 'Binary' | {
|
|
389
|
+
Varbinary: number | null;
|
|
390
|
+
} | 'Blob' | 'Bytes' | 'Json' | 'Jsonb' | {
|
|
391
|
+
Array: DataType;
|
|
392
|
+
} | {
|
|
393
|
+
Custom: [ObjectName, string[]];
|
|
394
|
+
} | 'Regclass' | 'String';
|
|
395
|
+
/**
|
|
396
|
+
* Window specification
|
|
397
|
+
*/
|
|
398
|
+
interface WindowSpec {
|
|
399
|
+
partitionBy: Expr[];
|
|
400
|
+
orderBy: OrderByExpr[];
|
|
401
|
+
windowFrame?: WindowFrame;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Window frame
|
|
405
|
+
*/
|
|
406
|
+
interface WindowFrame {
|
|
407
|
+
units: WindowFrameUnits;
|
|
408
|
+
startBound: WindowFrameBound;
|
|
409
|
+
endBound?: WindowFrameBound;
|
|
410
|
+
}
|
|
411
|
+
type WindowFrameUnits = 'Rows' | 'Range' | 'Groups';
|
|
412
|
+
type WindowFrameBound = 'CurrentRow' | 'UnboundedPreceding' | 'UnboundedFollowing' | {
|
|
413
|
+
Preceding: Expr | null;
|
|
414
|
+
} | {
|
|
415
|
+
Following: Expr | null;
|
|
416
|
+
};
|
|
417
|
+
/**
|
|
418
|
+
* ORDER BY expression
|
|
419
|
+
*/
|
|
420
|
+
interface OrderByExpr {
|
|
421
|
+
expr: Expr;
|
|
422
|
+
asc?: boolean;
|
|
423
|
+
nullsFirst?: boolean;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* SELECT item
|
|
427
|
+
*/
|
|
428
|
+
type SelectItem = 'UnnamedExpr' | {
|
|
429
|
+
UnnamedExpr: Expr;
|
|
430
|
+
} | {
|
|
431
|
+
ExprWithAlias: {
|
|
432
|
+
expr: Expr;
|
|
433
|
+
alias: Ident;
|
|
434
|
+
};
|
|
435
|
+
} | {
|
|
436
|
+
QualifiedWildcard: [ObjectName, WildcardAdditionalOptions];
|
|
437
|
+
} | {
|
|
438
|
+
Wildcard: WildcardAdditionalOptions;
|
|
439
|
+
};
|
|
440
|
+
interface WildcardAdditionalOptions {
|
|
441
|
+
optExclude?: ExcludeSelectItem;
|
|
442
|
+
optExcept?: ExceptSelectItem;
|
|
443
|
+
optRename?: RenameSelectItem;
|
|
444
|
+
optReplace?: ReplaceSelectItem;
|
|
445
|
+
}
|
|
446
|
+
interface ExcludeSelectItem {
|
|
447
|
+
items: Ident[];
|
|
448
|
+
}
|
|
449
|
+
interface ExceptSelectItem {
|
|
450
|
+
firstElement: Ident;
|
|
451
|
+
additionalElements: Ident[];
|
|
452
|
+
}
|
|
453
|
+
interface RenameSelectItem {
|
|
454
|
+
items: IdentWithAlias[];
|
|
455
|
+
}
|
|
456
|
+
interface ReplaceSelectItem {
|
|
457
|
+
items: ReplaceSelectElement[];
|
|
458
|
+
}
|
|
459
|
+
interface IdentWithAlias {
|
|
460
|
+
ident: Ident;
|
|
461
|
+
alias: Ident;
|
|
462
|
+
}
|
|
463
|
+
interface ReplaceSelectElement {
|
|
464
|
+
expr: Expr;
|
|
465
|
+
columnName: Ident;
|
|
466
|
+
asKeyword: boolean;
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* FROM clause table reference
|
|
470
|
+
*/
|
|
471
|
+
type TableFactor = {
|
|
472
|
+
Table: {
|
|
473
|
+
name: ObjectName;
|
|
474
|
+
alias?: TableAlias;
|
|
475
|
+
args?: FunctionArg[];
|
|
476
|
+
withHints: Expr[];
|
|
477
|
+
};
|
|
478
|
+
} | {
|
|
479
|
+
Derived: {
|
|
480
|
+
lateral: boolean;
|
|
481
|
+
subquery: Query;
|
|
482
|
+
alias?: TableAlias;
|
|
483
|
+
};
|
|
484
|
+
} | {
|
|
485
|
+
TableFunction: {
|
|
486
|
+
expr: Expr;
|
|
487
|
+
alias?: TableAlias;
|
|
488
|
+
};
|
|
489
|
+
} | {
|
|
490
|
+
NestedJoin: {
|
|
491
|
+
tableWithJoins: TableWithJoins;
|
|
492
|
+
alias?: TableAlias;
|
|
493
|
+
};
|
|
494
|
+
} | {
|
|
495
|
+
UNNEST: {
|
|
496
|
+
alias?: TableAlias;
|
|
497
|
+
arrayExprs: Expr[];
|
|
498
|
+
withOffset: boolean;
|
|
499
|
+
withOffsetAlias?: Ident;
|
|
500
|
+
};
|
|
501
|
+
};
|
|
502
|
+
/**
|
|
503
|
+
* Table alias
|
|
504
|
+
*/
|
|
505
|
+
interface TableAlias {
|
|
506
|
+
name: Ident;
|
|
507
|
+
columns: Ident[];
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Table with joins
|
|
511
|
+
*/
|
|
512
|
+
interface TableWithJoins {
|
|
513
|
+
relation: TableFactor;
|
|
514
|
+
joins: Join[];
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* JOIN clause
|
|
518
|
+
*/
|
|
519
|
+
interface Join {
|
|
520
|
+
relation: TableFactor;
|
|
521
|
+
joinOperator: JoinOperator;
|
|
522
|
+
}
|
|
523
|
+
type JoinOperator = {
|
|
524
|
+
Inner: JoinConstraint;
|
|
525
|
+
} | {
|
|
526
|
+
LeftOuter: JoinConstraint;
|
|
527
|
+
} | {
|
|
528
|
+
RightOuter: JoinConstraint;
|
|
529
|
+
} | {
|
|
530
|
+
FullOuter: JoinConstraint;
|
|
531
|
+
} | 'CrossJoin' | {
|
|
532
|
+
LeftSemi: JoinConstraint;
|
|
533
|
+
} | {
|
|
534
|
+
RightSemi: JoinConstraint;
|
|
535
|
+
} | {
|
|
536
|
+
LeftAnti: JoinConstraint;
|
|
537
|
+
} | {
|
|
538
|
+
RightAnti: JoinConstraint;
|
|
539
|
+
} | 'CrossApply' | 'OuterApply';
|
|
540
|
+
type JoinConstraint = {
|
|
541
|
+
On: Expr;
|
|
542
|
+
} | {
|
|
543
|
+
Using: Ident[];
|
|
544
|
+
} | 'Natural' | 'None';
|
|
545
|
+
/**
|
|
546
|
+
* SELECT statement
|
|
547
|
+
*/
|
|
548
|
+
interface Select {
|
|
549
|
+
distinct?: Distinct;
|
|
550
|
+
top?: Top;
|
|
551
|
+
projection: SelectItem[];
|
|
552
|
+
into?: SelectInto;
|
|
553
|
+
from: TableWithJoins[];
|
|
554
|
+
lateralViews: LateralView[];
|
|
555
|
+
selection?: Expr;
|
|
556
|
+
groupBy: GroupByExpr;
|
|
557
|
+
clusterBy: Expr[];
|
|
558
|
+
distributeBy: Expr[];
|
|
559
|
+
sortBy: Expr[];
|
|
560
|
+
having?: Expr;
|
|
561
|
+
namedWindow: NamedWindowDefinition[];
|
|
562
|
+
qualify?: Expr;
|
|
563
|
+
}
|
|
564
|
+
type Distinct = boolean | {
|
|
565
|
+
On: Expr[];
|
|
566
|
+
};
|
|
567
|
+
interface Top {
|
|
568
|
+
withTies: boolean;
|
|
569
|
+
percent: boolean;
|
|
570
|
+
quantity?: Expr;
|
|
571
|
+
}
|
|
572
|
+
interface SelectInto {
|
|
573
|
+
temporary: boolean;
|
|
574
|
+
unlogged: boolean;
|
|
575
|
+
table: boolean;
|
|
576
|
+
name: ObjectName;
|
|
577
|
+
}
|
|
578
|
+
interface LateralView {
|
|
579
|
+
lateralViewExpr: Expr;
|
|
580
|
+
lateralViewName: ObjectName;
|
|
581
|
+
lateralColAlias: Ident[];
|
|
582
|
+
outer: boolean;
|
|
583
|
+
}
|
|
584
|
+
type GroupByExpr = {
|
|
585
|
+
Expressions: Expr[];
|
|
586
|
+
} | 'All';
|
|
587
|
+
interface NamedWindowDefinition {
|
|
588
|
+
name: Ident;
|
|
589
|
+
windowSpec: WindowSpec;
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Set expression (UNION, INTERSECT, EXCEPT)
|
|
593
|
+
*/
|
|
594
|
+
type SetExpr = {
|
|
595
|
+
Select: Select;
|
|
596
|
+
} | {
|
|
597
|
+
Query: Query;
|
|
598
|
+
} | {
|
|
599
|
+
SetOperation: {
|
|
600
|
+
op: SetOperator;
|
|
601
|
+
setQuantifier: SetQuantifier;
|
|
602
|
+
left: SetExpr;
|
|
603
|
+
right: SetExpr;
|
|
604
|
+
};
|
|
605
|
+
} | {
|
|
606
|
+
Values: Values;
|
|
607
|
+
} | {
|
|
608
|
+
Insert: Statement;
|
|
609
|
+
};
|
|
610
|
+
type SetOperator = 'Union' | 'Except' | 'Intersect';
|
|
611
|
+
type SetQuantifier = 'All' | 'Distinct' | 'None';
|
|
612
|
+
interface Values {
|
|
613
|
+
explicit_row: boolean;
|
|
614
|
+
rows: Expr[][];
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* WITH clause (CTE)
|
|
618
|
+
*/
|
|
619
|
+
interface With {
|
|
620
|
+
recursive: boolean;
|
|
621
|
+
cteTables: Cte[];
|
|
622
|
+
}
|
|
623
|
+
interface Cte {
|
|
624
|
+
alias: TableAlias;
|
|
625
|
+
query: Query;
|
|
626
|
+
from?: Ident;
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Query (top-level SELECT)
|
|
630
|
+
*/
|
|
631
|
+
interface Query {
|
|
632
|
+
with?: With;
|
|
633
|
+
body: SetExpr;
|
|
634
|
+
orderBy: OrderByExpr[];
|
|
635
|
+
limit?: Expr;
|
|
636
|
+
offset?: Offset;
|
|
637
|
+
fetch?: Fetch;
|
|
638
|
+
locks: LockClause[];
|
|
639
|
+
}
|
|
640
|
+
interface Offset {
|
|
641
|
+
value: Expr;
|
|
642
|
+
rows: OffsetRows;
|
|
643
|
+
}
|
|
644
|
+
type OffsetRows = 'None' | 'Row' | 'Rows';
|
|
645
|
+
interface Fetch {
|
|
646
|
+
withTies: boolean;
|
|
647
|
+
percent: boolean;
|
|
648
|
+
quantity?: Expr;
|
|
649
|
+
}
|
|
650
|
+
interface LockClause {
|
|
651
|
+
lockType: LockType;
|
|
652
|
+
of?: ObjectName;
|
|
653
|
+
nonblock?: NonBlock;
|
|
654
|
+
}
|
|
655
|
+
type LockType = 'Share' | 'Update';
|
|
656
|
+
type NonBlock = 'Wait' | 'Nowait' | 'SkipLocked';
|
|
657
|
+
/**
|
|
658
|
+
* Column definition for CREATE TABLE
|
|
659
|
+
*/
|
|
660
|
+
interface ColumnDef {
|
|
661
|
+
name: Ident;
|
|
662
|
+
dataType: DataType;
|
|
663
|
+
collation?: ObjectName;
|
|
664
|
+
options: ColumnOptionDef[];
|
|
665
|
+
}
|
|
666
|
+
interface ColumnOptionDef {
|
|
667
|
+
name?: Ident;
|
|
668
|
+
option: ColumnOption;
|
|
669
|
+
}
|
|
670
|
+
type ColumnOption = 'Null' | 'NotNull' | {
|
|
671
|
+
Default: Expr;
|
|
672
|
+
} | {
|
|
673
|
+
Unique: {
|
|
674
|
+
isPrimary: boolean;
|
|
675
|
+
};
|
|
676
|
+
} | {
|
|
677
|
+
ForeignKey: ForeignKeyOption;
|
|
678
|
+
} | {
|
|
679
|
+
Check: Expr;
|
|
680
|
+
} | 'AutoIncrement' | {
|
|
681
|
+
OnUpdate: Expr;
|
|
682
|
+
} | {
|
|
683
|
+
Generated: GeneratedAs;
|
|
684
|
+
} | {
|
|
685
|
+
Comment: string;
|
|
686
|
+
};
|
|
687
|
+
interface ForeignKeyOption {
|
|
688
|
+
foreignTable: ObjectName;
|
|
689
|
+
referredColumns: Ident[];
|
|
690
|
+
onDelete?: ReferentialAction;
|
|
691
|
+
onUpdate?: ReferentialAction;
|
|
692
|
+
}
|
|
693
|
+
type ReferentialAction = 'Restrict' | 'Cascade' | 'SetNull' | 'NoAction' | 'SetDefault';
|
|
694
|
+
interface GeneratedAs {
|
|
695
|
+
generationType?: GeneratedExpressionMode;
|
|
696
|
+
expr: Expr;
|
|
697
|
+
}
|
|
698
|
+
type GeneratedExpressionMode = 'Virtual' | 'Stored';
|
|
699
|
+
/**
|
|
700
|
+
* Table constraint
|
|
701
|
+
*/
|
|
702
|
+
type TableConstraint = {
|
|
703
|
+
Unique: {
|
|
704
|
+
name?: Ident;
|
|
705
|
+
columns: Ident[];
|
|
706
|
+
isPrimary: boolean;
|
|
707
|
+
};
|
|
708
|
+
} | {
|
|
709
|
+
ForeignKey: {
|
|
710
|
+
name?: Ident;
|
|
711
|
+
columns: Ident[];
|
|
712
|
+
foreignTable: ObjectName;
|
|
713
|
+
referredColumns: Ident[];
|
|
714
|
+
onDelete?: ReferentialAction;
|
|
715
|
+
onUpdate?: ReferentialAction;
|
|
716
|
+
};
|
|
717
|
+
} | {
|
|
718
|
+
Check: {
|
|
719
|
+
name?: Ident;
|
|
720
|
+
expr: Expr;
|
|
721
|
+
};
|
|
722
|
+
} | {
|
|
723
|
+
Index: {
|
|
724
|
+
displayAsKey: boolean;
|
|
725
|
+
name?: Ident;
|
|
726
|
+
indexType?: IndexType;
|
|
727
|
+
columns: Ident[];
|
|
728
|
+
};
|
|
729
|
+
};
|
|
730
|
+
type IndexType = 'BTree' | 'Hash';
|
|
731
|
+
/**
|
|
732
|
+
* All SQL statement types
|
|
733
|
+
*/
|
|
734
|
+
type Statement = {
|
|
735
|
+
Query: Query;
|
|
736
|
+
} | {
|
|
737
|
+
Insert: {
|
|
738
|
+
orConflict?: SqliteOnConflict;
|
|
739
|
+
into: boolean;
|
|
740
|
+
tableName: ObjectName;
|
|
741
|
+
columns: Ident[];
|
|
742
|
+
overwrite: boolean;
|
|
743
|
+
source: Query;
|
|
744
|
+
partitioned?: Expr[];
|
|
745
|
+
afterColumns: Ident[];
|
|
746
|
+
table: boolean;
|
|
747
|
+
on?: OnInsert;
|
|
748
|
+
returning?: SelectItem[];
|
|
749
|
+
};
|
|
750
|
+
} | {
|
|
751
|
+
Update: {
|
|
752
|
+
table: TableWithJoins;
|
|
753
|
+
assignments: Assignment[];
|
|
754
|
+
from?: TableWithJoins;
|
|
755
|
+
selection?: Expr;
|
|
756
|
+
returning?: SelectItem[];
|
|
757
|
+
};
|
|
758
|
+
} | {
|
|
759
|
+
Delete: {
|
|
760
|
+
tables: ObjectName[];
|
|
761
|
+
from: TableWithJoins[];
|
|
762
|
+
using?: TableWithJoins[];
|
|
763
|
+
selection?: Expr;
|
|
764
|
+
returning?: SelectItem[];
|
|
765
|
+
};
|
|
766
|
+
} | {
|
|
767
|
+
CreateTable: {
|
|
768
|
+
orReplace: boolean;
|
|
769
|
+
temporary: boolean;
|
|
770
|
+
external: boolean;
|
|
771
|
+
global?: boolean;
|
|
772
|
+
ifNotExists: boolean;
|
|
773
|
+
transient: boolean;
|
|
774
|
+
name: ObjectName;
|
|
775
|
+
columns: ColumnDef[];
|
|
776
|
+
constraints: TableConstraint[];
|
|
777
|
+
hiveDistribution: HiveDistributionStyle;
|
|
778
|
+
hiveFormats?: HiveFormat;
|
|
779
|
+
tableProperties: SqlOption[];
|
|
780
|
+
withOptions: SqlOption[];
|
|
781
|
+
fileFormat?: FileFormat;
|
|
782
|
+
location?: string;
|
|
783
|
+
query?: Query;
|
|
784
|
+
withoutRowid: boolean;
|
|
785
|
+
like?: ObjectName;
|
|
786
|
+
cloneClause?: ObjectName;
|
|
787
|
+
engine?: string;
|
|
788
|
+
defaultCharset?: string;
|
|
789
|
+
collation?: string;
|
|
790
|
+
onCommit?: OnCommit;
|
|
791
|
+
onCluster?: string;
|
|
792
|
+
orderBy?: Ident[];
|
|
793
|
+
strict: boolean;
|
|
794
|
+
};
|
|
795
|
+
} | {
|
|
796
|
+
CreateView: {
|
|
797
|
+
orReplace: boolean;
|
|
798
|
+
materialized: boolean;
|
|
799
|
+
name: ObjectName;
|
|
800
|
+
columns: Ident[];
|
|
801
|
+
query: Query;
|
|
802
|
+
withOptions: SqlOption[];
|
|
803
|
+
clusterBy: Ident[];
|
|
804
|
+
};
|
|
805
|
+
} | {
|
|
806
|
+
CreateIndex: {
|
|
807
|
+
name?: ObjectName;
|
|
808
|
+
tableName: ObjectName;
|
|
809
|
+
using?: Ident;
|
|
810
|
+
columns: OrderByExpr[];
|
|
811
|
+
unique: boolean;
|
|
812
|
+
concurrently: boolean;
|
|
813
|
+
ifNotExists: boolean;
|
|
814
|
+
include: Ident[];
|
|
815
|
+
nullsDistinct?: boolean;
|
|
816
|
+
predicate?: Expr;
|
|
817
|
+
};
|
|
818
|
+
} | {
|
|
819
|
+
AlterTable: {
|
|
820
|
+
name: ObjectName;
|
|
821
|
+
ifExists: boolean;
|
|
822
|
+
only: boolean;
|
|
823
|
+
operations: AlterTableOperation[];
|
|
824
|
+
};
|
|
825
|
+
} | {
|
|
826
|
+
Drop: DropStatement;
|
|
827
|
+
} | {
|
|
828
|
+
Truncate: {
|
|
829
|
+
tableName: ObjectName;
|
|
830
|
+
partitions?: Expr[];
|
|
831
|
+
table: boolean;
|
|
832
|
+
};
|
|
833
|
+
} | {
|
|
834
|
+
SetVariable: {
|
|
835
|
+
local: boolean;
|
|
836
|
+
hivevar: boolean;
|
|
837
|
+
variable: ObjectName;
|
|
838
|
+
value: Expr[];
|
|
839
|
+
};
|
|
840
|
+
} | {
|
|
841
|
+
ShowVariable: {
|
|
842
|
+
variable: Ident[];
|
|
843
|
+
};
|
|
844
|
+
} | {
|
|
845
|
+
ShowCreate: {
|
|
846
|
+
objType: ShowCreateObject;
|
|
847
|
+
objName: ObjectName;
|
|
848
|
+
};
|
|
849
|
+
} | {
|
|
850
|
+
ShowTables: {
|
|
851
|
+
extended: boolean;
|
|
852
|
+
full: boolean;
|
|
853
|
+
dbName?: Ident;
|
|
854
|
+
filter?: ShowStatementFilter;
|
|
855
|
+
};
|
|
856
|
+
} | {
|
|
857
|
+
ShowColumns: {
|
|
858
|
+
extended: boolean;
|
|
859
|
+
full: boolean;
|
|
860
|
+
tableName: ObjectName;
|
|
861
|
+
filter?: ShowStatementFilter;
|
|
862
|
+
};
|
|
863
|
+
} | {
|
|
864
|
+
StartTransaction: {
|
|
865
|
+
modes: TransactionMode[];
|
|
866
|
+
begin: boolean;
|
|
867
|
+
};
|
|
868
|
+
} | {
|
|
869
|
+
Commit: {
|
|
870
|
+
chain: boolean;
|
|
871
|
+
};
|
|
872
|
+
} | {
|
|
873
|
+
Rollback: {
|
|
874
|
+
chain: boolean;
|
|
875
|
+
savepoint?: Ident;
|
|
876
|
+
};
|
|
877
|
+
} | {
|
|
878
|
+
Savepoint: {
|
|
879
|
+
name: Ident;
|
|
880
|
+
};
|
|
881
|
+
} | {
|
|
882
|
+
ReleaseSavepoint: {
|
|
883
|
+
name: Ident;
|
|
884
|
+
};
|
|
885
|
+
} | {
|
|
886
|
+
CreateSchema: {
|
|
887
|
+
schemaName: SchemaName;
|
|
888
|
+
ifNotExists: boolean;
|
|
889
|
+
};
|
|
890
|
+
} | {
|
|
891
|
+
CreateDatabase: {
|
|
892
|
+
dbName: ObjectName;
|
|
893
|
+
ifNotExists: boolean;
|
|
894
|
+
location?: string;
|
|
895
|
+
managedLocation?: string;
|
|
896
|
+
};
|
|
897
|
+
} | {
|
|
898
|
+
Grant: {
|
|
899
|
+
privileges: Privileges;
|
|
900
|
+
objects: GrantObjects;
|
|
901
|
+
grantees: Ident[];
|
|
902
|
+
withGrantOption: boolean;
|
|
903
|
+
grantedBy?: Ident;
|
|
904
|
+
};
|
|
905
|
+
} | {
|
|
906
|
+
Revoke: {
|
|
907
|
+
privileges: Privileges;
|
|
908
|
+
objects: GrantObjects;
|
|
909
|
+
grantees: Ident[];
|
|
910
|
+
grantedBy?: Ident;
|
|
911
|
+
cascade: boolean;
|
|
912
|
+
};
|
|
913
|
+
} | {
|
|
914
|
+
Explain: {
|
|
915
|
+
describeAlias: DescribeAlias;
|
|
916
|
+
analyze: boolean;
|
|
917
|
+
verbose: boolean;
|
|
918
|
+
statement: Statement;
|
|
919
|
+
};
|
|
920
|
+
} | {
|
|
921
|
+
Copy: {
|
|
922
|
+
source: CopySource;
|
|
923
|
+
to: boolean;
|
|
924
|
+
target: CopyTarget;
|
|
925
|
+
options: CopyOption[];
|
|
926
|
+
legacyOptions: CopyLegacyOption[];
|
|
927
|
+
values: string[][];
|
|
928
|
+
};
|
|
929
|
+
} | {
|
|
930
|
+
Close: {
|
|
931
|
+
cursor: CloseCursor;
|
|
932
|
+
};
|
|
933
|
+
} | {
|
|
934
|
+
Declare: {
|
|
935
|
+
name: Ident;
|
|
936
|
+
binary: boolean;
|
|
937
|
+
sensitive?: boolean;
|
|
938
|
+
scroll?: boolean;
|
|
939
|
+
hold?: boolean;
|
|
940
|
+
query: Query;
|
|
941
|
+
};
|
|
942
|
+
} | {
|
|
943
|
+
Fetch: {
|
|
944
|
+
name: Ident;
|
|
945
|
+
direction: FetchDirection;
|
|
946
|
+
into?: ObjectName;
|
|
947
|
+
};
|
|
948
|
+
} | {
|
|
949
|
+
Discard: {
|
|
950
|
+
objectType: DiscardObject;
|
|
951
|
+
};
|
|
952
|
+
} | 'ExplainTable' | {
|
|
953
|
+
Analyze: {
|
|
954
|
+
tableName: ObjectName;
|
|
955
|
+
partitions?: Expr[];
|
|
956
|
+
forColumns: boolean;
|
|
957
|
+
columns: Ident[];
|
|
958
|
+
cacheMetadata: boolean;
|
|
959
|
+
noscan: boolean;
|
|
960
|
+
computeStatistics: boolean;
|
|
961
|
+
};
|
|
962
|
+
} | {
|
|
963
|
+
Merge: {
|
|
964
|
+
into: boolean;
|
|
965
|
+
table: TableFactor;
|
|
966
|
+
source: TableFactor;
|
|
967
|
+
on: Expr;
|
|
968
|
+
clauses: MergeClause[];
|
|
969
|
+
};
|
|
970
|
+
} | {
|
|
971
|
+
Execute: {
|
|
972
|
+
name: ObjectName;
|
|
973
|
+
parameters: Expr[];
|
|
974
|
+
};
|
|
975
|
+
} | {
|
|
976
|
+
Prepare: {
|
|
977
|
+
name: Ident;
|
|
978
|
+
dataTypes: DataType[];
|
|
979
|
+
statement: Statement;
|
|
980
|
+
};
|
|
981
|
+
} | {
|
|
982
|
+
Deallocate: {
|
|
983
|
+
name: Ident;
|
|
984
|
+
prepare: boolean;
|
|
985
|
+
};
|
|
986
|
+
} | {
|
|
987
|
+
Comment: {
|
|
988
|
+
objectType: CommentObject;
|
|
989
|
+
objectName: ObjectName;
|
|
990
|
+
comment?: string;
|
|
991
|
+
ifExists: boolean;
|
|
992
|
+
};
|
|
993
|
+
} | {
|
|
994
|
+
Assert: {
|
|
995
|
+
condition: Expr;
|
|
996
|
+
message?: Expr;
|
|
997
|
+
};
|
|
998
|
+
} | 'Kill' | 'Use';
|
|
999
|
+
type SqliteOnConflict = 'Rollback' | 'Abort' | 'Fail' | 'Ignore' | 'Replace';
|
|
1000
|
+
type OnInsert = {
|
|
1001
|
+
DoUpdate: DoUpdate;
|
|
1002
|
+
} | 'DoNothing';
|
|
1003
|
+
interface DoUpdate {
|
|
1004
|
+
assignments: Assignment[];
|
|
1005
|
+
selection?: Expr;
|
|
1006
|
+
}
|
|
1007
|
+
interface Assignment {
|
|
1008
|
+
id: Ident[];
|
|
1009
|
+
value: Expr;
|
|
1010
|
+
}
|
|
1011
|
+
type HiveDistributionStyle = 'PARTITIONED' | 'CLUSTERED' | 'SKEWED' | 'NONE';
|
|
1012
|
+
interface HiveFormat {
|
|
1013
|
+
rowFormat?: HiveRowFormat;
|
|
1014
|
+
storage?: HiveIOFormat;
|
|
1015
|
+
location?: string;
|
|
1016
|
+
}
|
|
1017
|
+
type HiveRowFormat = {
|
|
1018
|
+
Serde: {
|
|
1019
|
+
class: string;
|
|
1020
|
+
};
|
|
1021
|
+
} | {
|
|
1022
|
+
Delimited: null;
|
|
1023
|
+
};
|
|
1024
|
+
interface HiveIOFormat {
|
|
1025
|
+
inputFormat: string;
|
|
1026
|
+
outputFormat: string;
|
|
1027
|
+
}
|
|
1028
|
+
interface SqlOption {
|
|
1029
|
+
name: Ident;
|
|
1030
|
+
value: Value;
|
|
1031
|
+
}
|
|
1032
|
+
type FileFormat = 'TEXTFILE' | 'SEQUENCEFILE' | 'ORC' | 'PARQUET' | 'AVRO' | 'RCFILE' | 'JSONFILE';
|
|
1033
|
+
type OnCommit = 'DeleteRows' | 'PreserveRows' | 'Drop';
|
|
1034
|
+
type AlterTableOperation = {
|
|
1035
|
+
AddConstraint: TableConstraint;
|
|
1036
|
+
} | {
|
|
1037
|
+
AddColumn: {
|
|
1038
|
+
columnKeyword: boolean;
|
|
1039
|
+
ifNotExists: boolean;
|
|
1040
|
+
columnDef: ColumnDef;
|
|
1041
|
+
};
|
|
1042
|
+
} | {
|
|
1043
|
+
DropConstraint: {
|
|
1044
|
+
ifExists: boolean;
|
|
1045
|
+
name: Ident;
|
|
1046
|
+
cascade: boolean;
|
|
1047
|
+
};
|
|
1048
|
+
} | {
|
|
1049
|
+
DropColumn: {
|
|
1050
|
+
columnName: Ident;
|
|
1051
|
+
ifExists: boolean;
|
|
1052
|
+
cascade: boolean;
|
|
1053
|
+
};
|
|
1054
|
+
} | {
|
|
1055
|
+
RenameColumn: {
|
|
1056
|
+
oldColumnName: Ident;
|
|
1057
|
+
newColumnName: Ident;
|
|
1058
|
+
};
|
|
1059
|
+
} | {
|
|
1060
|
+
RenameTable: {
|
|
1061
|
+
tableName: ObjectName;
|
|
1062
|
+
};
|
|
1063
|
+
} | {
|
|
1064
|
+
ChangeColumn: {
|
|
1065
|
+
oldName: Ident;
|
|
1066
|
+
newName: Ident;
|
|
1067
|
+
dataType: DataType;
|
|
1068
|
+
options: ColumnOption[];
|
|
1069
|
+
};
|
|
1070
|
+
} | {
|
|
1071
|
+
AlterColumn: {
|
|
1072
|
+
columnName: Ident;
|
|
1073
|
+
op: AlterColumnOperation;
|
|
1074
|
+
};
|
|
1075
|
+
} | {
|
|
1076
|
+
RenameConstraint: {
|
|
1077
|
+
oldName: Ident;
|
|
1078
|
+
newName: Ident;
|
|
1079
|
+
};
|
|
1080
|
+
};
|
|
1081
|
+
type AlterColumnOperation = {
|
|
1082
|
+
SetNotNull: null;
|
|
1083
|
+
} | {
|
|
1084
|
+
DropNotNull: null;
|
|
1085
|
+
} | {
|
|
1086
|
+
SetDefault: Expr;
|
|
1087
|
+
} | {
|
|
1088
|
+
DropDefault: null;
|
|
1089
|
+
} | {
|
|
1090
|
+
SetDataType: DataType;
|
|
1091
|
+
};
|
|
1092
|
+
interface DropStatement {
|
|
1093
|
+
objectType: ObjectType;
|
|
1094
|
+
ifExists: boolean;
|
|
1095
|
+
names: ObjectName[];
|
|
1096
|
+
cascade: boolean;
|
|
1097
|
+
restrict: boolean;
|
|
1098
|
+
purge: boolean;
|
|
1099
|
+
}
|
|
1100
|
+
type ObjectType = 'Table' | 'View' | 'Index' | 'Schema' | 'Role' | 'Sequence' | 'Stage';
|
|
1101
|
+
type ShowCreateObject = 'Event' | 'Function' | 'Procedure' | 'Table' | 'Trigger' | 'View';
|
|
1102
|
+
type ShowStatementFilter = {
|
|
1103
|
+
Like: string;
|
|
1104
|
+
} | {
|
|
1105
|
+
ILike: string;
|
|
1106
|
+
} | {
|
|
1107
|
+
Where: Expr;
|
|
1108
|
+
};
|
|
1109
|
+
type TransactionMode = {
|
|
1110
|
+
AccessMode: TransactionAccessMode;
|
|
1111
|
+
} | {
|
|
1112
|
+
IsolationLevel: TransactionIsolationLevel;
|
|
1113
|
+
};
|
|
1114
|
+
type TransactionAccessMode = 'ReadOnly' | 'ReadWrite';
|
|
1115
|
+
type TransactionIsolationLevel = 'ReadUncommitted' | 'ReadCommitted' | 'RepeatableRead' | 'Serializable';
|
|
1116
|
+
type SchemaName = {
|
|
1117
|
+
Simple: ObjectName;
|
|
1118
|
+
} | {
|
|
1119
|
+
UnnamedAuthorization: Ident;
|
|
1120
|
+
} | {
|
|
1121
|
+
NamedAuthorization: [ObjectName, Ident];
|
|
1122
|
+
};
|
|
1123
|
+
type Privileges = {
|
|
1124
|
+
Actions: Action[];
|
|
1125
|
+
} | 'All';
|
|
1126
|
+
type Action = 'Select' | {
|
|
1127
|
+
Select: Ident[];
|
|
1128
|
+
} | 'Insert' | {
|
|
1129
|
+
Insert: Ident[];
|
|
1130
|
+
} | 'Update' | {
|
|
1131
|
+
Update: Ident[];
|
|
1132
|
+
} | 'Delete' | 'Truncate' | 'References' | {
|
|
1133
|
+
References: Ident[];
|
|
1134
|
+
} | 'Trigger' | 'Connect' | 'Create' | 'Execute' | 'Temporary' | 'Usage';
|
|
1135
|
+
type GrantObjects = {
|
|
1136
|
+
AllSequencesInSchema: ObjectName[];
|
|
1137
|
+
} | {
|
|
1138
|
+
AllTablesInSchema: ObjectName[];
|
|
1139
|
+
} | {
|
|
1140
|
+
Schemas: ObjectName[];
|
|
1141
|
+
} | {
|
|
1142
|
+
Sequences: ObjectName[];
|
|
1143
|
+
} | {
|
|
1144
|
+
Tables: ObjectName[];
|
|
1145
|
+
};
|
|
1146
|
+
type DescribeAlias = 'Describe' | 'Explain' | 'Desc';
|
|
1147
|
+
type CopySource = {
|
|
1148
|
+
Table: ObjectName;
|
|
1149
|
+
columns: Ident[];
|
|
1150
|
+
} | {
|
|
1151
|
+
Query: Query;
|
|
1152
|
+
};
|
|
1153
|
+
type CopyTarget = {
|
|
1154
|
+
File: {
|
|
1155
|
+
filename: string;
|
|
1156
|
+
};
|
|
1157
|
+
} | {
|
|
1158
|
+
Program: {
|
|
1159
|
+
command: string;
|
|
1160
|
+
};
|
|
1161
|
+
} | 'Stdout' | 'Stdin';
|
|
1162
|
+
interface CopyOption {
|
|
1163
|
+
key: string;
|
|
1164
|
+
value?: string;
|
|
1165
|
+
}
|
|
1166
|
+
interface CopyLegacyOption {
|
|
1167
|
+
key: string;
|
|
1168
|
+
value?: string;
|
|
1169
|
+
}
|
|
1170
|
+
type CloseCursor = 'All' | {
|
|
1171
|
+
Specific: {
|
|
1172
|
+
name: Ident;
|
|
1173
|
+
};
|
|
1174
|
+
};
|
|
1175
|
+
type FetchDirection = {
|
|
1176
|
+
Count: Expr;
|
|
1177
|
+
} | 'Next' | 'Prior' | 'First' | 'Last' | 'Absolute' | 'Relative' | {
|
|
1178
|
+
Absolute: Expr;
|
|
1179
|
+
} | {
|
|
1180
|
+
Relative: Expr;
|
|
1181
|
+
} | 'All' | 'Forward' | {
|
|
1182
|
+
Forward: Expr;
|
|
1183
|
+
} | 'ForwardAll' | 'Backward' | {
|
|
1184
|
+
Backward: Expr;
|
|
1185
|
+
} | 'BackwardAll';
|
|
1186
|
+
type DiscardObject = 'All' | 'Plans' | 'Sequences' | 'Temp';
|
|
1187
|
+
type MergeClause = {
|
|
1188
|
+
MatchedUpdate: {
|
|
1189
|
+
predicate?: Expr;
|
|
1190
|
+
assignments: Assignment[];
|
|
1191
|
+
};
|
|
1192
|
+
} | {
|
|
1193
|
+
MatchedDelete: {
|
|
1194
|
+
predicate?: Expr;
|
|
1195
|
+
};
|
|
1196
|
+
} | {
|
|
1197
|
+
NotMatched: {
|
|
1198
|
+
predicate?: Expr;
|
|
1199
|
+
columns: Ident[];
|
|
1200
|
+
values: Values;
|
|
1201
|
+
};
|
|
1202
|
+
};
|
|
1203
|
+
type CommentObject = 'Column' | 'Table';
|
|
1204
|
+
//#endregion
|
|
1205
|
+
//#region src/wasm.d.ts
|
|
1206
|
+
/**
|
|
1207
|
+
* Wait for WASM module to be ready
|
|
1208
|
+
*/
|
|
1209
|
+
declare function ready(): Promise<void>;
|
|
1210
|
+
/**
|
|
1211
|
+
* Initialize the WASM module explicitly.
|
|
1212
|
+
* Usually not needed - the module auto-initializes on first use.
|
|
1213
|
+
*/
|
|
1214
|
+
declare function initWasm(): Promise<void>;
|
|
1215
|
+
//#endregion
|
|
1216
|
+
//#region src/parser.d.ts
|
|
1217
|
+
/** Dialect can be specified as a Dialect instance or a string name */
|
|
1218
|
+
type DialectInput = Dialect | DialectName;
|
|
1219
|
+
/**
|
|
1220
|
+
* Parser options
|
|
1221
|
+
*/
|
|
1222
|
+
interface ParserOptions {
|
|
1223
|
+
/** Allow trailing commas in SELECT lists */
|
|
1224
|
+
trailingCommas?: boolean;
|
|
1225
|
+
/** Maximum recursion depth for parsing nested expressions */
|
|
1226
|
+
recursionLimit?: number;
|
|
1227
|
+
}
|
|
1228
|
+
/**
|
|
1229
|
+
* SQL Parser - parses SQL statements into AST
|
|
1230
|
+
*
|
|
1231
|
+
* @example
|
|
1232
|
+
* ```typescript
|
|
1233
|
+
* import { Parser, PostgreSqlDialect } from '@guanmingchiu/sqlparser-ts';
|
|
1234
|
+
*
|
|
1235
|
+
* const statements = Parser.parse('SELECT * FROM users', 'postgresql');
|
|
1236
|
+
*
|
|
1237
|
+
* // With options
|
|
1238
|
+
* const parser = new Parser(new PostgreSqlDialect())
|
|
1239
|
+
* .withOptions({ trailingCommas: true });
|
|
1240
|
+
* const ast = parser.parse('SELECT a, b, FROM users');
|
|
1241
|
+
* ```
|
|
1242
|
+
*/
|
|
1243
|
+
declare class Parser {
|
|
1244
|
+
private dialect;
|
|
1245
|
+
private options;
|
|
1246
|
+
constructor(dialect?: Dialect);
|
|
1247
|
+
/** Set recursion limit for parsing nested expressions */
|
|
1248
|
+
withRecursionLimit(limit: number): Parser;
|
|
1249
|
+
/** Set parser options */
|
|
1250
|
+
withOptions(options: ParserOptions): Parser;
|
|
1251
|
+
/** Parse SQL statements */
|
|
1252
|
+
parse(sql: string): Statement[];
|
|
1253
|
+
/** Parse SQL into AST */
|
|
1254
|
+
static parse(sql: string, dialect?: DialectInput): Statement[];
|
|
1255
|
+
/** Parse SQL and return AST as JSON string */
|
|
1256
|
+
static parseToJson(sql: string, dialect?: DialectInput): string;
|
|
1257
|
+
/** Parse SQL and return formatted string representation */
|
|
1258
|
+
static parseToString(sql: string, dialect?: DialectInput): string;
|
|
1259
|
+
/** Format SQL by parsing and regenerating it */
|
|
1260
|
+
static format(sql: string, dialect?: DialectInput): string;
|
|
1261
|
+
/**
|
|
1262
|
+
* Validate SQL syntax
|
|
1263
|
+
* @throws ParserError if SQL is invalid
|
|
1264
|
+
*/
|
|
1265
|
+
static validate(sql: string, dialect?: DialectInput): boolean;
|
|
1266
|
+
/** Get list of supported dialect names */
|
|
1267
|
+
static getSupportedDialects(): string[];
|
|
1268
|
+
}
|
|
1269
|
+
/**
|
|
1270
|
+
* Parse SQL into AST
|
|
1271
|
+
*/
|
|
1272
|
+
declare function parse(sql: string, dialect?: DialectInput): Statement[];
|
|
1273
|
+
/**
|
|
1274
|
+
* Validate SQL syntax
|
|
1275
|
+
* @throws ParserError if SQL is invalid
|
|
1276
|
+
*/
|
|
1277
|
+
declare function validate(sql: string, dialect?: DialectInput): boolean;
|
|
1278
|
+
/**
|
|
1279
|
+
* Format SQL by parsing and regenerating it
|
|
1280
|
+
*/
|
|
1281
|
+
declare function format(sql: string, dialect?: DialectInput): string;
|
|
1282
|
+
//#endregion
|
|
1283
|
+
//#region src/types/errors.d.ts
|
|
1284
|
+
/**
|
|
1285
|
+
* Location information for parser errors
|
|
1286
|
+
*/
|
|
1287
|
+
interface ErrorLocation {
|
|
1288
|
+
line: number;
|
|
1289
|
+
column: number;
|
|
1290
|
+
}
|
|
1291
|
+
/**
|
|
1292
|
+
* Error thrown when SQL parsing fails
|
|
1293
|
+
*/
|
|
1294
|
+
declare class ParserError extends Error {
|
|
1295
|
+
readonly location?: ErrorLocation;
|
|
1296
|
+
constructor(message: string, location?: ErrorLocation);
|
|
1297
|
+
/**
|
|
1298
|
+
* Create a ParserError from a WASM error object
|
|
1299
|
+
*/
|
|
1300
|
+
static fromWasmError(error: unknown): ParserError;
|
|
1301
|
+
}
|
|
1302
|
+
/**
|
|
1303
|
+
* Error thrown when WASM module fails to initialize
|
|
1304
|
+
*/
|
|
1305
|
+
declare class WasmInitError extends Error {
|
|
1306
|
+
constructor(message: string);
|
|
1307
|
+
}
|
|
1308
|
+
//#endregion
|
|
1309
|
+
export { Action, AlterColumnOperation, AlterTableOperation, AnsiDialect, Assignment, BigQueryDialect, BinaryOperator, ClickHouseDialect, CloseCursor, ColumnDef, ColumnOption, ColumnOptionDef, CommentObject, CopyLegacyOption, CopyOption, CopySource, CopyTarget, Cte, DataType, DatabricksDialect, DateTimeField, DescribeAlias, type Dialect, type DialectInput, type DialectName, DiscardObject, Distinct, DoUpdate, DropStatement, DuckDbDialect, ErrorLocation, ExceptSelectItem, ExcludeSelectItem, Expr, Fetch, FetchDirection, FileFormat, ForeignKeyOption, FunctionArg, FunctionArgExpr, FunctionExpr, GeneratedAs, GeneratedExpressionMode, GenericDialect, GrantObjects, GroupByExpr, HiveDialect, HiveDistributionStyle, HiveFormat, HiveIOFormat, HiveRowFormat, Ident, IdentWithAlias, IndexType, IntervalExpr, Join, JoinConstraint, JoinOperator, LateralView, LockClause, LockType, MergeClause, MsSqlDialect, MySqlDialect, NamedWindowDefinition, NonBlock, ObjectName, ObjectType, Offset, OffsetRows, OnCommit, OnInsert, OracleDialect, OrderByExpr, Parser, ParserError, type ParserOptions, PostgreSqlDialect, Privileges, Query, RedshiftDialect, ReferentialAction, RenameSelectItem, ReplaceSelectElement, ReplaceSelectItem, SQLiteDialect, SUPPORTED_DIALECTS, SchemaName, Select, SelectInto, SelectItem, SetExpr, SetOperator, SetQuantifier, ShowCreateObject, ShowStatementFilter, SnowflakeDialect, SqlOption, SqliteOnConflict, Statement, TableAlias, TableConstraint, TableFactor, TableWithJoins, Top, TransactionAccessMode, TransactionIsolationLevel, TransactionMode, TrimWhereField, UnaryOperator, Value, Values, WasmInitError, WildcardAdditionalOptions, WindowFrame, WindowFrameBound, WindowFrameUnits, WindowSpec, With, dialectFromString, format, initWasm, parse, ready, validate };
|