sqlparser-rs 0.60.2 → 0.60.3-rc2

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.
Files changed (48) hide show
  1. package/README.md +65 -32
  2. package/dist/index.cjs +526 -0
  3. package/dist/index.d.cts +1438 -0
  4. package/dist/index.d.mts +1438 -0
  5. package/dist/index.mjs +502 -0
  6. package/package.json +11 -11
  7. package/wasm/README.md +65 -32
  8. package/wasm/package.json +1 -1
  9. package/wasm/sqlparser_rs_wasm_bg.wasm +0 -0
  10. package/wasm/sqlparser_rs_wasm_web.js +628 -0
  11. package/wasm/sqlparser_rs_wasm_web_bg.wasm +0 -0
  12. package/dist/cjs/dialects.js +0 -202
  13. package/dist/cjs/dialects.js.map +0 -1
  14. package/dist/cjs/index.js +0 -81
  15. package/dist/cjs/index.js.map +0 -1
  16. package/dist/cjs/parser.js +0 -191
  17. package/dist/cjs/parser.js.map +0 -1
  18. package/dist/cjs/types/ast.js +0 -10
  19. package/dist/cjs/types/ast.js.map +0 -1
  20. package/dist/cjs/types/errors.js +0 -49
  21. package/dist/cjs/types/errors.js.map +0 -1
  22. package/dist/cjs/types/index.js +0 -19
  23. package/dist/cjs/types/index.js.map +0 -1
  24. package/dist/esm/dialects.js +0 -184
  25. package/dist/esm/dialects.js.map +0 -1
  26. package/dist/esm/index.js +0 -47
  27. package/dist/esm/index.js.map +0 -1
  28. package/dist/esm/package.json +0 -1
  29. package/dist/esm/parser.js +0 -187
  30. package/dist/esm/parser.js.map +0 -1
  31. package/dist/esm/types/ast.js +0 -9
  32. package/dist/esm/types/ast.js.map +0 -1
  33. package/dist/esm/types/errors.js +0 -44
  34. package/dist/esm/types/errors.js.map +0 -1
  35. package/dist/esm/types/index.js +0 -3
  36. package/dist/esm/types/index.js.map +0 -1
  37. package/dist/types/dialects.d.ts +0 -118
  38. package/dist/types/dialects.d.ts.map +0 -1
  39. package/dist/types/index.d.ts +0 -46
  40. package/dist/types/index.d.ts.map +0 -1
  41. package/dist/types/parser.d.ts +0 -116
  42. package/dist/types/parser.d.ts.map +0 -1
  43. package/dist/types/types/ast.d.ts +0 -1097
  44. package/dist/types/types/ast.d.ts.map +0 -1
  45. package/dist/types/types/errors.d.ts +0 -25
  46. package/dist/types/types/errors.d.ts.map +0 -1
  47. package/dist/types/types/index.d.ts +0 -3
  48. package/dist/types/types/index.d.ts.map +0 -1
package/dist/index.mjs ADDED
@@ -0,0 +1,502 @@
1
+ //#region src/dialects.ts
2
+ /**
3
+ * Generic SQL dialect - accepts most SQL syntax
4
+ */
5
+ var GenericDialect = class {
6
+ constructor() {
7
+ this.name = "generic";
8
+ }
9
+ };
10
+ /**
11
+ * ANSI SQL standard dialect
12
+ */
13
+ var AnsiDialect = class {
14
+ constructor() {
15
+ this.name = "ansi";
16
+ }
17
+ };
18
+ /**
19
+ * MySQL dialect
20
+ */
21
+ var MySqlDialect = class {
22
+ constructor() {
23
+ this.name = "mysql";
24
+ }
25
+ };
26
+ /**
27
+ * PostgreSQL dialect
28
+ */
29
+ var PostgreSqlDialect = class {
30
+ constructor() {
31
+ this.name = "postgresql";
32
+ }
33
+ };
34
+ /**
35
+ * SQLite dialect
36
+ */
37
+ var SQLiteDialect = class {
38
+ constructor() {
39
+ this.name = "sqlite";
40
+ }
41
+ };
42
+ /**
43
+ * Snowflake dialect
44
+ */
45
+ var SnowflakeDialect = class {
46
+ constructor() {
47
+ this.name = "snowflake";
48
+ }
49
+ };
50
+ /**
51
+ * Amazon Redshift dialect
52
+ */
53
+ var RedshiftDialect = class {
54
+ constructor() {
55
+ this.name = "redshift";
56
+ }
57
+ };
58
+ /**
59
+ * Microsoft SQL Server dialect
60
+ */
61
+ var MsSqlDialect = class {
62
+ constructor() {
63
+ this.name = "mssql";
64
+ }
65
+ };
66
+ /**
67
+ * ClickHouse dialect
68
+ */
69
+ var ClickHouseDialect = class {
70
+ constructor() {
71
+ this.name = "clickhouse";
72
+ }
73
+ };
74
+ /**
75
+ * Google BigQuery dialect
76
+ */
77
+ var BigQueryDialect = class {
78
+ constructor() {
79
+ this.name = "bigquery";
80
+ }
81
+ };
82
+ /**
83
+ * DuckDB dialect
84
+ */
85
+ var DuckDbDialect = class {
86
+ constructor() {
87
+ this.name = "duckdb";
88
+ }
89
+ };
90
+ /**
91
+ * Databricks dialect
92
+ */
93
+ var DatabricksDialect = class {
94
+ constructor() {
95
+ this.name = "databricks";
96
+ }
97
+ };
98
+ /**
99
+ * Apache Hive dialect
100
+ */
101
+ var HiveDialect = class {
102
+ constructor() {
103
+ this.name = "hive";
104
+ }
105
+ };
106
+ /**
107
+ * Oracle dialect
108
+ */
109
+ var OracleDialect = class {
110
+ constructor() {
111
+ this.name = "oracle";
112
+ }
113
+ };
114
+ /**
115
+ * All supported dialect names
116
+ */
117
+ const SUPPORTED_DIALECTS = [
118
+ "generic",
119
+ "ansi",
120
+ "mysql",
121
+ "postgresql",
122
+ "sqlite",
123
+ "snowflake",
124
+ "redshift",
125
+ "mssql",
126
+ "clickhouse",
127
+ "bigquery",
128
+ "duckdb",
129
+ "databricks",
130
+ "hive",
131
+ "oracle"
132
+ ];
133
+ /**
134
+ * Map of dialect names to dialect classes
135
+ */
136
+ const DIALECT_MAP = {
137
+ generic: GenericDialect,
138
+ ansi: AnsiDialect,
139
+ mysql: MySqlDialect,
140
+ postgresql: PostgreSqlDialect,
141
+ sqlite: SQLiteDialect,
142
+ snowflake: SnowflakeDialect,
143
+ redshift: RedshiftDialect,
144
+ mssql: MsSqlDialect,
145
+ clickhouse: ClickHouseDialect,
146
+ bigquery: BigQueryDialect,
147
+ duckdb: DuckDbDialect,
148
+ databricks: DatabricksDialect,
149
+ hive: HiveDialect,
150
+ oracle: OracleDialect
151
+ };
152
+ /**
153
+ * Create a dialect instance from a string name
154
+ *
155
+ * @param name - The name of the dialect (case-insensitive)
156
+ * @returns A dialect instance, or undefined if the dialect is not recognized
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * const dialect = dialectFromString('postgresql');
161
+ * if (dialect) {
162
+ * const ast = Parser.parse('SELECT 1', dialect);
163
+ * }
164
+ * ```
165
+ */
166
+ function dialectFromString(name) {
167
+ const normalized = name.toLowerCase();
168
+ const DialectClass = DIALECT_MAP[{
169
+ postgres: "postgresql",
170
+ pg: "postgresql",
171
+ sqlserver: "mssql",
172
+ duck: "duckdb"
173
+ }[normalized] ?? normalized];
174
+ return DialectClass ? new DialectClass() : void 0;
175
+ }
176
+
177
+ //#endregion
178
+ //#region src/types/errors.ts
179
+ /**
180
+ * Error thrown when SQL parsing fails
181
+ */
182
+ var ParserError = class ParserError extends Error {
183
+ constructor(message, location) {
184
+ super(message);
185
+ this.name = "ParserError";
186
+ this.location = location;
187
+ if (Error.captureStackTrace) Error.captureStackTrace(this, ParserError);
188
+ }
189
+ /**
190
+ * Create a ParserError from a WASM error object
191
+ */
192
+ static fromWasmError(error) {
193
+ if (typeof error === "string") return new ParserError(error);
194
+ if (error && typeof error === "object") {
195
+ const err = error;
196
+ return new ParserError(typeof err.message === "string" ? err.message : String(error), typeof err.line === "number" && typeof err.column === "number" ? {
197
+ line: err.line,
198
+ column: err.column
199
+ } : void 0);
200
+ }
201
+ return new ParserError(String(error));
202
+ }
203
+ };
204
+ /**
205
+ * Error thrown when WASM module fails to initialize
206
+ */
207
+ var WasmInitError = class WasmInitError extends Error {
208
+ constructor(message) {
209
+ super(message);
210
+ this.name = "WasmInitError";
211
+ if (Error.captureStackTrace) Error.captureStackTrace(this, WasmInitError);
212
+ }
213
+ };
214
+
215
+ //#endregion
216
+ //#region src/parser.ts
217
+ function resolveDialect(dialect = "generic") {
218
+ if (typeof dialect === "string") {
219
+ const resolved = dialectFromString(dialect);
220
+ if (!resolved) throw new Error(`Unknown dialect: ${dialect}`);
221
+ return resolved;
222
+ }
223
+ return dialect;
224
+ }
225
+ let wasmModule = null;
226
+ let initPromise = null;
227
+ let initStarted = false;
228
+ const isBrowser = typeof window !== "undefined" && typeof process === "undefined";
229
+ function startInit() {
230
+ if (initStarted) return;
231
+ initStarted = true;
232
+ initPromise = initWasm().catch(() => {});
233
+ }
234
+ startInit();
235
+ function getWasmModule() {
236
+ if (wasmModule) return wasmModule;
237
+ 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))");
238
+ }
239
+ /**
240
+ * Wait for WASM to be ready (useful for ensuring sync APIs work)
241
+ */
242
+ async function ready() {
243
+ startInit();
244
+ await initPromise;
245
+ }
246
+ /**
247
+ * Initialize the WASM module.
248
+ * This must be called before using the Parser in browsers and Node.js ESM.
249
+ * In Node.js CommonJS, the module is loaded automatically.
250
+ *
251
+ * @example
252
+ * ```typescript
253
+ * import { initWasm, Parser, GenericDialect } from 'sqlparser-rs';
254
+ *
255
+ * // Initialize first
256
+ * await initWasm();
257
+ *
258
+ * // Then use the parser
259
+ * const ast = Parser.parse('SELECT 1', new GenericDialect());
260
+ * ```
261
+ */
262
+ async function initWasm() {
263
+ if (wasmModule) return;
264
+ if (isBrowser) {
265
+ try {
266
+ const wasmJsUrl = new URL("../wasm/sqlparser_rs_wasm_web.js", import.meta.url);
267
+ const wasmBinaryUrl = new URL("../wasm/sqlparser_rs_wasm_web_bg.wasm", import.meta.url);
268
+ const wasm = await import(
269
+ /* @vite-ignore */
270
+ wasmJsUrl.href
271
+ );
272
+ if (typeof wasm.default === "function") await wasm.default(wasmBinaryUrl);
273
+ wasmModule = wasm;
274
+ } catch (error) {
275
+ throw new WasmInitError(`Failed to load WASM module in browser: ${error instanceof Error ? error.message : String(error)}`);
276
+ }
277
+ return;
278
+ }
279
+ try {
280
+ wasmModule = await import(
281
+ /* @vite-ignore */
282
+ new URL("../wasm/sqlparser_rs_wasm.js", import.meta.url).href
283
+ );
284
+ } catch (error) {
285
+ throw new WasmInitError(`Failed to load WASM module: ${error instanceof Error ? error.message : String(error)}`);
286
+ }
287
+ }
288
+ /**
289
+ * SQL Parser
290
+ *
291
+ * Parses SQL statements into an Abstract Syntax Tree (AST).
292
+ *
293
+ * @example
294
+ * ```typescript
295
+ * import { Parser, PostgreSqlDialect } from 'sqlparser-rs';
296
+ *
297
+ * // Simple parsing
298
+ * const statements = Parser.parse('SELECT * FROM users', new PostgreSqlDialect());
299
+ *
300
+ * // With builder pattern
301
+ * const parser = new Parser(new PostgreSqlDialect())
302
+ * .withRecursionLimit(50)
303
+ * .withOptions({ trailingCommas: true });
304
+ *
305
+ * const ast = parser.parse('SELECT * FROM users');
306
+ * ```
307
+ */
308
+ var Parser = class Parser {
309
+ /**
310
+ * Create a new parser instance
311
+ *
312
+ * @param dialect - The SQL dialect to use (defaults to GenericDialect)
313
+ */
314
+ constructor(dialect = new GenericDialect()) {
315
+ this.dialect = dialect;
316
+ this.options = {};
317
+ }
318
+ /**
319
+ * Set the recursion limit for parsing nested expressions
320
+ *
321
+ * @param limit - Maximum recursion depth
322
+ * @returns This parser instance for chaining
323
+ */
324
+ withRecursionLimit(limit) {
325
+ this.options.recursionLimit = limit;
326
+ return this;
327
+ }
328
+ /**
329
+ * Set parser options
330
+ *
331
+ * @param options - Parser options
332
+ * @returns This parser instance for chaining
333
+ */
334
+ withOptions(options) {
335
+ this.options = {
336
+ ...this.options,
337
+ ...options
338
+ };
339
+ return this;
340
+ }
341
+ /**
342
+ * Parse SQL statements
343
+ *
344
+ * @param sql - SQL string to parse
345
+ * @returns Array of parsed statements
346
+ */
347
+ parse(sql) {
348
+ const wasm = getWasmModule();
349
+ try {
350
+ if (Object.keys(this.options).length > 0) return wasm.parse_sql_with_options(this.dialect.name, sql, this.options);
351
+ else return wasm.parse_sql(this.dialect.name, sql);
352
+ } catch (error) {
353
+ throw ParserError.fromWasmError(error);
354
+ }
355
+ }
356
+ /**
357
+ * Parse SQL statements
358
+ *
359
+ * @param sql - SQL string to parse
360
+ * @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
361
+ * @returns Array of parsed statements
362
+ *
363
+ * @example
364
+ * ```typescript
365
+ * // Using default dialect
366
+ * const statements = Parser.parse('SELECT 1');
367
+ *
368
+ * // Using string dialect name
369
+ * const pgStatements = Parser.parse('SELECT $1', 'postgresql');
370
+ *
371
+ * // Using dialect instance
372
+ * const mysqlStatements = Parser.parse('SELECT 1', new MySqlDialect());
373
+ * ```
374
+ */
375
+ static parse(sql, dialect = "generic") {
376
+ return new Parser(resolveDialect(dialect)).parse(sql);
377
+ }
378
+ /**
379
+ * Parse SQL and return the AST as a JSON string
380
+ *
381
+ * @param sql - SQL string to parse
382
+ * @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
383
+ * @returns JSON string representation of the AST
384
+ */
385
+ static parseToJson(sql, dialect = "generic") {
386
+ const wasm = getWasmModule();
387
+ try {
388
+ return wasm.parse_sql_to_json_string(resolveDialect(dialect).name, sql);
389
+ } catch (error) {
390
+ throw ParserError.fromWasmError(error);
391
+ }
392
+ }
393
+ /**
394
+ * Parse SQL and return a formatted string representation
395
+ *
396
+ * @param sql - SQL string to parse
397
+ * @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
398
+ * @returns String representation of the parsed SQL
399
+ */
400
+ static parseToString(sql, dialect = "generic") {
401
+ const wasm = getWasmModule();
402
+ try {
403
+ return wasm.parse_sql_to_string(resolveDialect(dialect).name, sql);
404
+ } catch (error) {
405
+ throw ParserError.fromWasmError(error);
406
+ }
407
+ }
408
+ /**
409
+ * Format SQL by parsing and regenerating it (round-trip)
410
+ *
411
+ * @param sql - SQL string to format
412
+ * @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
413
+ * @returns Formatted SQL string
414
+ */
415
+ static format(sql, dialect = "generic") {
416
+ const wasm = getWasmModule();
417
+ try {
418
+ return wasm.format_sql(resolveDialect(dialect).name, sql);
419
+ } catch (error) {
420
+ throw ParserError.fromWasmError(error);
421
+ }
422
+ }
423
+ /**
424
+ * Validate SQL syntax without returning the full AST
425
+ *
426
+ * @param sql - SQL string to validate
427
+ * @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
428
+ * @returns true if valid, throws ParserError if invalid
429
+ */
430
+ static validate(sql, dialect = "generic") {
431
+ const wasm = getWasmModule();
432
+ try {
433
+ return wasm.validate_sql(resolveDialect(dialect).name, sql);
434
+ } catch (error) {
435
+ throw ParserError.fromWasmError(error);
436
+ }
437
+ }
438
+ /**
439
+ * Get the list of supported dialect names
440
+ */
441
+ static getSupportedDialects() {
442
+ return getWasmModule().get_supported_dialects();
443
+ }
444
+ };
445
+ /**
446
+ * Parse SQL statements (convenience function)
447
+ *
448
+ * @param sql - SQL string to parse
449
+ * @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
450
+ * @returns Array of parsed statements
451
+ *
452
+ * @example
453
+ * ```typescript
454
+ * import { parse } from 'sqlparser-rs';
455
+ *
456
+ * const statements = parse('SELECT * FROM users');
457
+ * const pgStatements = parse('SELECT $1', 'postgresql');
458
+ * ```
459
+ */
460
+ function parse(sql, dialect = "generic") {
461
+ return Parser.parse(sql, dialect);
462
+ }
463
+ /**
464
+ * Validate SQL syntax (convenience function)
465
+ *
466
+ * @param sql - SQL string to validate
467
+ * @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
468
+ * @returns true if valid, throws ParserError if invalid
469
+ *
470
+ * @example
471
+ * ```typescript
472
+ * import { validate } from 'sqlparser-rs';
473
+ *
474
+ * if (validate('SELECT * FROM users')) {
475
+ * console.log('Valid SQL!');
476
+ * }
477
+ * ```
478
+ */
479
+ function validate(sql, dialect = "generic") {
480
+ return Parser.validate(sql, dialect);
481
+ }
482
+ /**
483
+ * Format SQL by parsing and regenerating it (convenience function)
484
+ *
485
+ * @param sql - SQL string to format
486
+ * @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
487
+ * @returns Formatted SQL string
488
+ *
489
+ * @example
490
+ * ```typescript
491
+ * import { format } from 'sqlparser-rs';
492
+ *
493
+ * const formatted = format('select * from users');
494
+ * // Returns: "SELECT * FROM users"
495
+ * ```
496
+ */
497
+ function format(sql, dialect = "generic") {
498
+ return Parser.format(sql, dialect);
499
+ }
500
+
501
+ //#endregion
502
+ export { AnsiDialect, BigQueryDialect, ClickHouseDialect, DatabricksDialect, DuckDbDialect, GenericDialect, HiveDialect, MsSqlDialect, MySqlDialect, OracleDialect, Parser, ParserError, PostgreSqlDialect, RedshiftDialect, SQLiteDialect, SUPPORTED_DIALECTS, SnowflakeDialect, WasmInitError, dialectFromString, format, initWasm, parse, ready, validate };
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "sqlparser-rs",
3
- "version": "0.60.2",
3
+ "version": "0.60.3-rc2",
4
+ "type": "module",
4
5
  "description": "A SQL parser for JavaScript and TypeScript, powered by datafusion-sqlparser-rs via WASM",
5
- "main": "dist/cjs/index.js",
6
- "module": "dist/esm/index.js",
7
- "types": "dist/types/index.d.ts",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.mjs",
8
+ "types": "dist/index.d.mts",
8
9
  "exports": {
9
10
  ".": {
10
- "types": "./dist/types/index.d.ts",
11
- "import": "./dist/esm/index.js",
12
- "require": "./dist/cjs/index.js"
11
+ "types": "./dist/index.d.mts",
12
+ "import": "./dist/index.mjs",
13
+ "require": "./dist/index.cjs"
13
14
  }
14
15
  },
15
16
  "files": [
@@ -21,9 +22,7 @@
21
22
  "build": "npm run build:wasm && npm run build:ts",
22
23
  "build:wasm": "cd .. && wasm-pack build --target nodejs --out-dir ts/wasm && rm -f ts/wasm/.gitignore",
23
24
  "build:wasm:web": "cd .. && wasm-pack build --target web --out-dir ts/wasm-web",
24
- "build:ts": "npm run build:esm && npm run build:cjs && echo '{\"type\":\"module\"}' > dist/esm/package.json",
25
- "build:esm": "tsc -p tsconfig.esm.json",
26
- "build:cjs": "tsc -p tsconfig.cjs.json",
25
+ "build:ts": "tsdown",
27
26
  "test": "vitest run",
28
27
  "test:watch": "vitest",
29
28
  "lint": "eslint src tests",
@@ -45,13 +44,14 @@
45
44
  "license": "Apache-2.0",
46
45
  "repository": {
47
46
  "type": "git",
48
- "url": "https://github.com/guan404ming/sqlparser-rs"
47
+ "url": "git+https://github.com/guan404ming/sqlparser-rs.git"
49
48
  },
50
49
  "devDependencies": {
51
50
  "@types/node": "^25.0.10",
52
51
  "@vitest/ui": "^4.0.18",
53
52
  "eslint": "^9.18.0",
54
53
  "eslint-plugin-unused-imports": "^4.3.0",
54
+ "tsdown": "^0.20.1",
55
55
  "typescript": "^5.7.0",
56
56
  "typescript-eslint": "^8.21.0",
57
57
  "vitest": "^4.0.18"
package/wasm/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,46 +49,82 @@ 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
73
72
 
74
- // Validate SQL syntax
75
- const isValid = Parser.validate(sql: string, dialect: Dialect): boolean;
73
+ Dialects can be specified as strings or class instances:
76
74
 
77
- // Get list of supported dialects
78
- const dialects = Parser.getSupportedDialects(): string[];
75
+ ```typescript
76
+ import { parse, PostgreSqlDialect } from 'sqlparser-rs';
77
+
78
+ // String dialect names (recommended)
79
+ parse('SELECT $1', 'postgresql');
80
+ parse('SELECT `col` FROM t', 'mysql');
81
+
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
130
  All dialects from the upstream Rust crate are supported:
@@ -191,7 +224,7 @@ npm test
191
224
  This package follows the upstream [sqlparser-rs](https://github.com/apache/datafusion-sqlparser-rs) version:
192
225
 
193
226
  - **Major.Minor** matches the upstream Rust crate version
194
- - **Patch** is for TypeScript binding fixes (e.g., `0.60.2` = upstream `0.60.0` + binding fix)
227
+ - **Patch** is for TypeScript binding fixes (e.g., `0.60.3-rc2` = upstream `0.60.0` + binding fix)
195
228
 
196
229
  | This package | sqlparser-rs |
197
230
  |--------------|--------------|
package/wasm/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "sqlparser-rs-wasm",
3
3
  "description": "WebAssembly bindings for sqlparser-rs SQL parser",
4
- "version": "0.60.2",
4
+ "version": "0.60.3-rc2",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
7
7
  "type": "git",
Binary file