sqlparser-rs 0.60.3-rc1 → 0.60.3-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 CHANGED
@@ -26,25 +26,22 @@ npm install sqlparser-rs
26
26
  ## Quick Start
27
27
 
28
28
  ```typescript
29
- import { Parser, GenericDialect, PostgreSqlDialect } from 'sqlparser-rs';
29
+ import { parse, format, validate } from 'sqlparser-rs';
30
30
 
31
- // Simple parsing
32
- const statements = Parser.parse('SELECT * FROM users', new GenericDialect());
31
+ // Simple parsing (uses generic dialect by default)
32
+ const statements = parse('SELECT * FROM users');
33
33
  console.log(statements);
34
34
 
35
- // With specific dialect
36
- const pgStatements = Parser.parse(
37
- 'SELECT * FROM users WHERE id = $1',
38
- new PostgreSqlDialect()
39
- );
35
+ // With specific dialect (string name)
36
+ const pgStatements = parse('SELECT * FROM users WHERE id = $1', 'postgresql');
40
37
 
41
38
  // Format SQL
42
- const formatted = Parser.format('select * from users', new GenericDialect());
39
+ const formatted = format('select * from users');
43
40
  console.log(formatted); // "SELECT * FROM users"
44
41
 
45
42
  // Validate SQL
46
43
  try {
47
- Parser.validate('SELEC * FROM users', new GenericDialect());
44
+ validate('SELEC * FROM users');
48
45
  } catch (error) {
49
46
  console.log('Invalid SQL:', error.message);
50
47
  }
@@ -52,51 +49,93 @@ try {
52
49
 
53
50
  ## API
54
51
 
55
- ### Parser
52
+ ### Top-Level Functions
56
53
 
57
- The main class for parsing SQL.
58
-
59
- #### Static Methods
54
+ The simplest way to use the parser:
60
55
 
61
56
  ```typescript
62
- // Parse SQL into statements
63
- const statements = Parser.parse(sql: string, dialect: Dialect): Statement[];
64
-
65
- // Parse and return JSON string
66
- const json = Parser.parseToJson(sql: string, dialect: Dialect): string;
57
+ import { parse, format, validate } from 'sqlparser-rs';
67
58
 
68
- // Parse and return formatted SQL string
69
- const formatted = Parser.parseToString(sql: string, dialect: Dialect): string;
59
+ // Parse SQL - dialect defaults to 'generic'
60
+ parse('SELECT * FROM users');
61
+ parse('SELECT * FROM users', 'postgresql');
62
+ parse('SELECT * FROM users', 'mysql');
70
63
 
71
64
  // Format SQL (round-trip through parser)
72
- const formatted = Parser.format(sql: string, dialect: Dialect): string;
65
+ format('select * from users'); // "SELECT * FROM users"
66
+
67
+ // Validate SQL syntax (throws ParserError if invalid)
68
+ validate('SELECT * FROM users'); // true
69
+ ```
70
+
71
+ ### Dialect Options
72
+
73
+ Dialects can be specified as strings or class instances:
74
+
75
+ ```typescript
76
+ import { parse, PostgreSqlDialect } from 'sqlparser-rs';
73
77
 
74
- // Validate SQL syntax
75
- const isValid = Parser.validate(sql: string, dialect: Dialect): boolean;
78
+ // String dialect names (recommended)
79
+ parse('SELECT $1', 'postgresql');
80
+ parse('SELECT `col` FROM t', 'mysql');
76
81
 
77
- // Get list of supported dialects
78
- const dialects = Parser.getSupportedDialects(): string[];
82
+ // Or dialect instances
83
+ parse('SELECT $1', new PostgreSqlDialect());
79
84
  ```
80
85
 
81
- #### Instance Methods (Builder Pattern)
86
+ Supported dialect strings: `'generic'`, `'ansi'`, `'mysql'`, `'postgresql'`, `'sqlite'`, `'snowflake'`, `'redshift'`, `'mssql'`, `'clickhouse'`, `'bigquery'`, `'duckdb'`, `'databricks'`, `'hive'`, `'oracle'`
87
+
88
+ ### Parser Class
89
+
90
+ For advanced use cases with options:
82
91
 
83
92
  ```typescript
84
93
  import { Parser, PostgreSqlDialect } from 'sqlparser-rs';
85
94
 
95
+ // Static methods (same as top-level functions)
96
+ Parser.parse('SELECT 1');
97
+ Parser.parse('SELECT 1', 'postgresql');
98
+ Parser.format('select 1');
99
+ Parser.validate('SELECT 1');
100
+ Parser.parseToJson('SELECT 1'); // Returns JSON string
101
+ Parser.parseToString('SELECT 1'); // Returns formatted string
102
+ Parser.getSupportedDialects(); // Returns dialect names
103
+
104
+ // Builder pattern for custom options
86
105
  const parser = new Parser(new PostgreSqlDialect())
87
- .withRecursionLimit(50) // Set max recursion depth
88
- .withOptions({ // Set parser options
89
- trailingCommas: true
90
- });
106
+ .withRecursionLimit(50)
107
+ .withOptions({ trailingCommas: true });
91
108
 
92
109
  const statements = parser.parse('SELECT * FROM users');
93
110
  ```
94
111
 
112
+ ### WASM Initialization
113
+
114
+ The WASM module auto-initializes on import. For most use cases, no action is needed.
115
+
116
+ If you need to ensure WASM is ready before calling sync APIs (e.g., in tests):
117
+
118
+ ```typescript
119
+ import { ready, parse } from 'sqlparser-rs';
120
+
121
+ // Wait for WASM to be ready
122
+ await ready();
123
+
124
+ // Now sync APIs are guaranteed to work
125
+ const ast = parse('SELECT 1');
126
+ ```
127
+
95
128
  ### Dialects
96
129
 
97
- All dialects from the upstream Rust crate are supported:
130
+ All dialects from the upstream Rust crate are supported. You can use string names directly with `parse()`, `format()`, and `validate()`:
98
131
 
99
132
  ```typescript
133
+ // String names (recommended)
134
+ parse('SELECT 1', 'postgresql');
135
+ parse('SELECT 1', 'mysql');
136
+ parse('SELECT 1', 'bigquery');
137
+
138
+ // Or import dialect classes for type safety
100
139
  import {
101
140
  GenericDialect, // Permissive, accepts most SQL syntax
102
141
  AnsiDialect, // ANSI SQL standard
@@ -111,9 +150,10 @@ import {
111
150
  DuckDbDialect, // DuckDB
112
151
  DatabricksDialect, // Databricks
113
152
  HiveDialect, // Apache Hive
153
+ OracleDialect, // Oracle
114
154
  } from 'sqlparser-rs';
115
155
 
116
- // Create dialect from string
156
+ // Create dialect from string programmatically
117
157
  import { dialectFromString } from 'sqlparser-rs';
118
158
  const dialect = dialectFromString('postgresql'); // Returns PostgreSqlDialect instance
119
159
  ```
@@ -121,10 +161,10 @@ const dialect = dialectFromString('postgresql'); // Returns PostgreSqlDialect in
121
161
  ### Error Handling
122
162
 
123
163
  ```typescript
124
- import { Parser, GenericDialect, ParserError } from 'sqlparser-rs';
164
+ import { parse, ParserError } from 'sqlparser-rs';
125
165
 
126
166
  try {
127
- Parser.parse('SELEC * FROM users', new GenericDialect());
167
+ parse('SELEC * FROM users');
128
168
  } catch (error) {
129
169
  if (error instanceof ParserError) {
130
170
  console.log('Parse error:', error.message);
@@ -140,9 +180,10 @@ try {
140
180
  Full TypeScript types are provided for the AST:
141
181
 
142
182
  ```typescript
143
- import type { Statement, Query, Expr, Ident, ObjectName } from 'sqlparser-rs';
183
+ import { parse } from 'sqlparser-rs';
184
+ import type { Statement, Query } from 'sqlparser-rs';
144
185
 
145
- const statements: Statement[] = Parser.parse('SELECT 1', new GenericDialect());
186
+ const statements: Statement[] = parse('SELECT 1');
146
187
 
147
188
  // Statement is a discriminated union type
148
189
  for (const stmt of statements) {
@@ -155,6 +196,23 @@ for (const stmt of statements) {
155
196
  }
156
197
  ```
157
198
 
199
+ ## Bundler Configuration
200
+
201
+ ### Vite
202
+
203
+ Exclude `sqlparser-rs` from dependency optimization to ensure WASM files load correctly:
204
+
205
+ ```typescript
206
+ // vite.config.ts
207
+ export default defineConfig({
208
+ optimizeDeps: {
209
+ exclude: ["sqlparser-rs"],
210
+ },
211
+ });
212
+ ```
213
+
214
+ This is required because Vite's pre-bundling breaks the WASM file path resolution.
215
+
158
216
  ## Development
159
217
 
160
218
  ### Prerequisites
@@ -191,7 +249,7 @@ npm test
191
249
  This package follows the upstream [sqlparser-rs](https://github.com/apache/datafusion-sqlparser-rs) version:
192
250
 
193
251
  - **Major.Minor** matches the upstream Rust crate version
194
- - **Patch** is for TypeScript binding fixes (e.g., `0.60.3-rc1` = upstream `0.60.0` + binding fix)
252
+ - **Patch** is for TypeScript binding fixes (e.g., `0.60.3-rc3` = upstream `0.60.0` + binding fix)
195
253
 
196
254
  | This package | sqlparser-rs |
197
255
  |--------------|--------------|
package/dist/index.cjs CHANGED
@@ -215,33 +215,45 @@ var WasmInitError = class WasmInitError extends Error {
215
215
 
216
216
  //#endregion
217
217
  //#region src/parser.ts
218
+ function resolveDialect(dialect = "generic") {
219
+ if (typeof dialect === "string") {
220
+ const resolved = dialectFromString(dialect);
221
+ if (!resolved) throw new Error(`Unknown dialect: ${dialect}`);
222
+ return resolved;
223
+ }
224
+ return dialect;
225
+ }
218
226
  let wasmModule = null;
219
- const isBrowser = typeof window !== "undefined" || typeof self !== "undefined";
227
+ let initPromise = null;
228
+ let initStarted = false;
229
+ const isBrowser = typeof window !== "undefined" && typeof process === "undefined";
230
+ function startInit() {
231
+ if (initStarted) return;
232
+ initStarted = true;
233
+ initPromise = initWasm().catch(() => {});
234
+ }
235
+ startInit();
220
236
  function getWasmModule() {
221
237
  if (wasmModule) return wasmModule;
222
- if (isBrowser) throw new WasmInitError("WASM module not initialized. Call initWasm() first in browser environments.");
223
- try {
224
- const nodeRequire = (0, eval)("require");
225
- const nodeModule = nodeRequire("node:module");
226
- const nodeUrl = nodeRequire("node:url");
227
- const nodePath = nodeRequire("node:path");
228
- const currentDir = nodePath.dirname(nodeUrl.fileURLToPath(require("url").pathToFileURL(__filename).href));
229
- const wasmPath = nodePath.join(currentDir, "../wasm/sqlparser_rs_wasm.js");
230
- wasmModule = nodeModule.createRequire(require("url").pathToFileURL(__filename).href)(wasmPath);
231
- return wasmModule;
232
- } catch (error) {
233
- throw new WasmInitError(`Failed to load WASM module: ${error instanceof Error ? error.message : String(error)}`);
234
- }
238
+ throw new WasmInitError("WASM module not yet initialized. Use the async import or wait for module to load: import(\"sqlparser-rs\").then(({ parse }) => parse(sql))");
239
+ }
240
+ /**
241
+ * Wait for WASM to be ready (useful for ensuring sync APIs work)
242
+ */
243
+ async function ready() {
244
+ startInit();
245
+ await initPromise;
235
246
  }
236
247
  /**
237
- * Initialize the WASM module for browser environments.
238
- * This must be called before using the Parser in browsers.
248
+ * Initialize the WASM module.
249
+ * This must be called before using the Parser in browsers and Node.js ESM.
250
+ * In Node.js CommonJS, the module is loaded automatically.
239
251
  *
240
252
  * @example
241
253
  * ```typescript
242
254
  * import { initWasm, Parser, GenericDialect } from 'sqlparser-rs';
243
255
  *
244
- * // In browser, initialize first
256
+ * // Initialize first
245
257
  * await initWasm();
246
258
  *
247
259
  * // Then use the parser
@@ -250,21 +262,28 @@ function getWasmModule() {
250
262
  */
251
263
  async function initWasm() {
252
264
  if (wasmModule) return;
253
- if (!isBrowser) {
254
- getWasmModule();
265
+ if (isBrowser) {
266
+ try {
267
+ const wasmJsUrl = new URL("../wasm/sqlparser_rs_wasm_web.js", require("url").pathToFileURL(__filename).href);
268
+ const wasmBinaryUrl = new URL("../wasm/sqlparser_rs_wasm_web_bg.wasm", require("url").pathToFileURL(__filename).href);
269
+ const wasm = await import(
270
+ /* @vite-ignore */
271
+ wasmJsUrl.href
272
+ );
273
+ if (typeof wasm.default === "function") await wasm.default(wasmBinaryUrl);
274
+ wasmModule = wasm;
275
+ } catch (error) {
276
+ throw new WasmInitError(`Failed to load WASM module in browser: ${error instanceof Error ? error.message : String(error)}`);
277
+ }
255
278
  return;
256
279
  }
257
280
  try {
258
- const wasmJsUrl = new URL("../wasm/sqlparser_rs_wasm_web.js", require("url").pathToFileURL(__filename).href);
259
- const wasmBinaryUrl = new URL("../wasm/sqlparser_rs_wasm_web_bg.wasm", require("url").pathToFileURL(__filename).href);
260
- const wasm = await import(
281
+ wasmModule = await import(
261
282
  /* @vite-ignore */
262
- wasmJsUrl.href
283
+ new URL("../wasm/sqlparser_rs_wasm.js", require("url").pathToFileURL(__filename).href).href
263
284
  );
264
- if (typeof wasm.default === "function") await wasm.default(wasmBinaryUrl);
265
- wasmModule = wasm;
266
285
  } catch (error) {
267
- throw new WasmInitError(`Failed to load WASM module in browser: ${error instanceof Error ? error.message : String(error)}`);
286
+ throw new WasmInitError(`Failed to load WASM module: ${error instanceof Error ? error.message : String(error)}`);
268
287
  }
269
288
  }
270
289
  /**
@@ -339,28 +358,35 @@ var Parser = class Parser {
339
358
  * Parse SQL statements
340
359
  *
341
360
  * @param sql - SQL string to parse
342
- * @param dialect - SQL dialect to use
361
+ * @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
343
362
  * @returns Array of parsed statements
344
363
  *
345
364
  * @example
346
365
  * ```typescript
347
- * const statements = Parser.parse('SELECT 1', new GenericDialect());
366
+ * // Using default dialect
367
+ * const statements = Parser.parse('SELECT 1');
368
+ *
369
+ * // Using string dialect name
370
+ * const pgStatements = Parser.parse('SELECT $1', 'postgresql');
371
+ *
372
+ * // Using dialect instance
373
+ * const mysqlStatements = Parser.parse('SELECT 1', new MySqlDialect());
348
374
  * ```
349
375
  */
350
- static parse(sql, dialect = new GenericDialect()) {
351
- return new Parser(dialect).parse(sql);
376
+ static parse(sql, dialect = "generic") {
377
+ return new Parser(resolveDialect(dialect)).parse(sql);
352
378
  }
353
379
  /**
354
380
  * Parse SQL and return the AST as a JSON string
355
381
  *
356
382
  * @param sql - SQL string to parse
357
- * @param dialect - SQL dialect to use
383
+ * @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
358
384
  * @returns JSON string representation of the AST
359
385
  */
360
- static parseToJson(sql, dialect = new GenericDialect()) {
386
+ static parseToJson(sql, dialect = "generic") {
361
387
  const wasm = getWasmModule();
362
388
  try {
363
- return wasm.parse_sql_to_json_string(dialect.name, sql);
389
+ return wasm.parse_sql_to_json_string(resolveDialect(dialect).name, sql);
364
390
  } catch (error) {
365
391
  throw ParserError.fromWasmError(error);
366
392
  }
@@ -369,13 +395,13 @@ var Parser = class Parser {
369
395
  * Parse SQL and return a formatted string representation
370
396
  *
371
397
  * @param sql - SQL string to parse
372
- * @param dialect - SQL dialect to use
398
+ * @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
373
399
  * @returns String representation of the parsed SQL
374
400
  */
375
- static parseToString(sql, dialect = new GenericDialect()) {
401
+ static parseToString(sql, dialect = "generic") {
376
402
  const wasm = getWasmModule();
377
403
  try {
378
- return wasm.parse_sql_to_string(dialect.name, sql);
404
+ return wasm.parse_sql_to_string(resolveDialect(dialect).name, sql);
379
405
  } catch (error) {
380
406
  throw ParserError.fromWasmError(error);
381
407
  }
@@ -384,13 +410,13 @@ var Parser = class Parser {
384
410
  * Format SQL by parsing and regenerating it (round-trip)
385
411
  *
386
412
  * @param sql - SQL string to format
387
- * @param dialect - SQL dialect to use
413
+ * @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
388
414
  * @returns Formatted SQL string
389
415
  */
390
- static format(sql, dialect = new GenericDialect()) {
416
+ static format(sql, dialect = "generic") {
391
417
  const wasm = getWasmModule();
392
418
  try {
393
- return wasm.format_sql(dialect.name, sql);
419
+ return wasm.format_sql(resolveDialect(dialect).name, sql);
394
420
  } catch (error) {
395
421
  throw ParserError.fromWasmError(error);
396
422
  }
@@ -399,13 +425,13 @@ var Parser = class Parser {
399
425
  * Validate SQL syntax without returning the full AST
400
426
  *
401
427
  * @param sql - SQL string to validate
402
- * @param dialect - SQL dialect to use
428
+ * @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
403
429
  * @returns true if valid, throws ParserError if invalid
404
430
  */
405
- static validate(sql, dialect = new GenericDialect()) {
431
+ static validate(sql, dialect = "generic") {
406
432
  const wasm = getWasmModule();
407
433
  try {
408
- return wasm.validate_sql(dialect.name, sql);
434
+ return wasm.validate_sql(resolveDialect(dialect).name, sql);
409
435
  } catch (error) {
410
436
  throw ParserError.fromWasmError(error);
411
437
  }
@@ -417,6 +443,61 @@ var Parser = class Parser {
417
443
  return getWasmModule().get_supported_dialects();
418
444
  }
419
445
  };
446
+ /**
447
+ * Parse SQL statements (convenience function)
448
+ *
449
+ * @param sql - SQL string to parse
450
+ * @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
451
+ * @returns Array of parsed statements
452
+ *
453
+ * @example
454
+ * ```typescript
455
+ * import { parse } from 'sqlparser-rs';
456
+ *
457
+ * const statements = parse('SELECT * FROM users');
458
+ * const pgStatements = parse('SELECT $1', 'postgresql');
459
+ * ```
460
+ */
461
+ function parse(sql, dialect = "generic") {
462
+ return Parser.parse(sql, dialect);
463
+ }
464
+ /**
465
+ * Validate SQL syntax (convenience function)
466
+ *
467
+ * @param sql - SQL string to validate
468
+ * @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
469
+ * @returns true if valid, throws ParserError if invalid
470
+ *
471
+ * @example
472
+ * ```typescript
473
+ * import { validate } from 'sqlparser-rs';
474
+ *
475
+ * if (validate('SELECT * FROM users')) {
476
+ * console.log('Valid SQL!');
477
+ * }
478
+ * ```
479
+ */
480
+ function validate(sql, dialect = "generic") {
481
+ return Parser.validate(sql, dialect);
482
+ }
483
+ /**
484
+ * Format SQL by parsing and regenerating it (convenience function)
485
+ *
486
+ * @param sql - SQL string to format
487
+ * @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
488
+ * @returns Formatted SQL string
489
+ *
490
+ * @example
491
+ * ```typescript
492
+ * import { format } from 'sqlparser-rs';
493
+ *
494
+ * const formatted = format('select * from users');
495
+ * // Returns: "SELECT * FROM users"
496
+ * ```
497
+ */
498
+ function format(sql, dialect = "generic") {
499
+ return Parser.format(sql, dialect);
500
+ }
420
501
 
421
502
  //#endregion
422
503
  exports.AnsiDialect = AnsiDialect;
@@ -438,4 +519,8 @@ exports.SUPPORTED_DIALECTS = SUPPORTED_DIALECTS;
438
519
  exports.SnowflakeDialect = SnowflakeDialect;
439
520
  exports.WasmInitError = WasmInitError;
440
521
  exports.dialectFromString = dialectFromString;
441
- exports.initWasm = initWasm;
522
+ exports.format = format;
523
+ exports.initWasm = initWasm;
524
+ exports.parse = parse;
525
+ exports.ready = ready;
526
+ exports.validate = validate;
package/dist/index.d.cts CHANGED
@@ -1216,6 +1216,8 @@ type MergeClause = {
1216
1216
  type CommentObject = 'Column' | 'Table';
1217
1217
  //#endregion
1218
1218
  //#region src/parser.d.ts
1219
+ /** Dialect can be specified as a Dialect instance or a string name */
1220
+ type DialectInput = Dialect | DialectName;
1219
1221
  /**
1220
1222
  * Parser options
1221
1223
  */
@@ -1230,14 +1232,19 @@ interface ParserOptions {
1230
1232
  recursionLimit?: number;
1231
1233
  }
1232
1234
  /**
1233
- * Initialize the WASM module for browser environments.
1234
- * This must be called before using the Parser in browsers.
1235
+ * Wait for WASM to be ready (useful for ensuring sync APIs work)
1236
+ */
1237
+ declare function ready(): Promise<void>;
1238
+ /**
1239
+ * Initialize the WASM module.
1240
+ * This must be called before using the Parser in browsers and Node.js ESM.
1241
+ * In Node.js CommonJS, the module is loaded automatically.
1235
1242
  *
1236
1243
  * @example
1237
1244
  * ```typescript
1238
1245
  * import { initWasm, Parser, GenericDialect } from 'sqlparser-rs';
1239
1246
  *
1240
- * // In browser, initialize first
1247
+ * // Initialize first
1241
1248
  * await initWasm();
1242
1249
  *
1243
1250
  * // Then use the parser
@@ -1299,52 +1306,108 @@ declare class Parser {
1299
1306
  * Parse SQL statements
1300
1307
  *
1301
1308
  * @param sql - SQL string to parse
1302
- * @param dialect - SQL dialect to use
1309
+ * @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
1303
1310
  * @returns Array of parsed statements
1304
1311
  *
1305
1312
  * @example
1306
1313
  * ```typescript
1307
- * const statements = Parser.parse('SELECT 1', new GenericDialect());
1314
+ * // Using default dialect
1315
+ * const statements = Parser.parse('SELECT 1');
1316
+ *
1317
+ * // Using string dialect name
1318
+ * const pgStatements = Parser.parse('SELECT $1', 'postgresql');
1319
+ *
1320
+ * // Using dialect instance
1321
+ * const mysqlStatements = Parser.parse('SELECT 1', new MySqlDialect());
1308
1322
  * ```
1309
1323
  */
1310
- static parse(sql: string, dialect?: Dialect): Statement[];
1324
+ static parse(sql: string, dialect?: DialectInput): Statement[];
1311
1325
  /**
1312
1326
  * Parse SQL and return the AST as a JSON string
1313
1327
  *
1314
1328
  * @param sql - SQL string to parse
1315
- * @param dialect - SQL dialect to use
1329
+ * @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
1316
1330
  * @returns JSON string representation of the AST
1317
1331
  */
1318
- static parseToJson(sql: string, dialect?: Dialect): string;
1332
+ static parseToJson(sql: string, dialect?: DialectInput): string;
1319
1333
  /**
1320
1334
  * Parse SQL and return a formatted string representation
1321
1335
  *
1322
1336
  * @param sql - SQL string to parse
1323
- * @param dialect - SQL dialect to use
1337
+ * @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
1324
1338
  * @returns String representation of the parsed SQL
1325
1339
  */
1326
- static parseToString(sql: string, dialect?: Dialect): string;
1340
+ static parseToString(sql: string, dialect?: DialectInput): string;
1327
1341
  /**
1328
1342
  * Format SQL by parsing and regenerating it (round-trip)
1329
1343
  *
1330
1344
  * @param sql - SQL string to format
1331
- * @param dialect - SQL dialect to use
1345
+ * @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
1332
1346
  * @returns Formatted SQL string
1333
1347
  */
1334
- static format(sql: string, dialect?: Dialect): string;
1348
+ static format(sql: string, dialect?: DialectInput): string;
1335
1349
  /**
1336
1350
  * Validate SQL syntax without returning the full AST
1337
1351
  *
1338
1352
  * @param sql - SQL string to validate
1339
- * @param dialect - SQL dialect to use
1353
+ * @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
1340
1354
  * @returns true if valid, throws ParserError if invalid
1341
1355
  */
1342
- static validate(sql: string, dialect?: Dialect): boolean;
1356
+ static validate(sql: string, dialect?: DialectInput): boolean;
1343
1357
  /**
1344
1358
  * Get the list of supported dialect names
1345
1359
  */
1346
1360
  static getSupportedDialects(): string[];
1347
1361
  }
1362
+ /**
1363
+ * Parse SQL statements (convenience function)
1364
+ *
1365
+ * @param sql - SQL string to parse
1366
+ * @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
1367
+ * @returns Array of parsed statements
1368
+ *
1369
+ * @example
1370
+ * ```typescript
1371
+ * import { parse } from 'sqlparser-rs';
1372
+ *
1373
+ * const statements = parse('SELECT * FROM users');
1374
+ * const pgStatements = parse('SELECT $1', 'postgresql');
1375
+ * ```
1376
+ */
1377
+ declare function parse(sql: string, dialect?: DialectInput): Statement[];
1378
+ /**
1379
+ * Validate SQL syntax (convenience function)
1380
+ *
1381
+ * @param sql - SQL string to validate
1382
+ * @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
1383
+ * @returns true if valid, throws ParserError if invalid
1384
+ *
1385
+ * @example
1386
+ * ```typescript
1387
+ * import { validate } from 'sqlparser-rs';
1388
+ *
1389
+ * if (validate('SELECT * FROM users')) {
1390
+ * console.log('Valid SQL!');
1391
+ * }
1392
+ * ```
1393
+ */
1394
+ declare function validate(sql: string, dialect?: DialectInput): boolean;
1395
+ /**
1396
+ * Format SQL by parsing and regenerating it (convenience function)
1397
+ *
1398
+ * @param sql - SQL string to format
1399
+ * @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
1400
+ * @returns Formatted SQL string
1401
+ *
1402
+ * @example
1403
+ * ```typescript
1404
+ * import { format } from 'sqlparser-rs';
1405
+ *
1406
+ * const formatted = format('select * from users');
1407
+ * // Returns: "SELECT * FROM users"
1408
+ * ```
1409
+ */
1410
+ declare function format(sql: string, dialect?: DialectInput): string;
1348
1411
  //#endregion
1349
1412
  //#region src/types/errors.d.ts
1350
1413
  /**
@@ -1372,4 +1435,4 @@ declare class WasmInitError extends Error {
1372
1435
  constructor(message: string);
1373
1436
  }
1374
1437
  //#endregion
1375
- 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, initWasm };
1438
+ 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 };