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