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 +96 -38
- package/dist/index.cjs +128 -43
- package/dist/index.d.cts +78 -15
- package/dist/index.d.mts +78 -15
- package/dist/index.mjs +124 -43
- package/package.json +15 -16
- package/wasm/README.md +96 -38
- package/wasm/package.json +1 -1
- package/wasm/sqlparser_rs_wasm_bg.wasm +0 -0
- package/wasm/sqlparser_rs_wasm_web_bg.wasm +0 -0
package/dist/index.d.mts
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
|
-
*
|
|
1234
|
-
|
|
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
|
-
* //
|
|
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
|
-
*
|
|
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?:
|
|
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?:
|
|
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?:
|
|
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?:
|
|
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?:
|
|
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 };
|
package/dist/index.mjs
CHANGED
|
@@ -214,33 +214,45 @@ var WasmInitError = class WasmInitError extends Error {
|
|
|
214
214
|
|
|
215
215
|
//#endregion
|
|
216
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
|
+
}
|
|
217
225
|
let wasmModule = null;
|
|
218
|
-
|
|
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();
|
|
219
235
|
function getWasmModule() {
|
|
220
236
|
if (wasmModule) return wasmModule;
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
wasmModule = nodeModule.createRequire(import.meta.url)(wasmPath);
|
|
230
|
-
return wasmModule;
|
|
231
|
-
} catch (error) {
|
|
232
|
-
throw new WasmInitError(`Failed to load WASM module: ${error instanceof Error ? error.message : String(error)}`);
|
|
233
|
-
}
|
|
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;
|
|
234
245
|
}
|
|
235
246
|
/**
|
|
236
|
-
* Initialize the WASM module
|
|
237
|
-
* This must be called before using the Parser in browsers.
|
|
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.
|
|
238
250
|
*
|
|
239
251
|
* @example
|
|
240
252
|
* ```typescript
|
|
241
253
|
* import { initWasm, Parser, GenericDialect } from 'sqlparser-rs';
|
|
242
254
|
*
|
|
243
|
-
* //
|
|
255
|
+
* // Initialize first
|
|
244
256
|
* await initWasm();
|
|
245
257
|
*
|
|
246
258
|
* // Then use the parser
|
|
@@ -249,21 +261,28 @@ function getWasmModule() {
|
|
|
249
261
|
*/
|
|
250
262
|
async function initWasm() {
|
|
251
263
|
if (wasmModule) return;
|
|
252
|
-
if (
|
|
253
|
-
|
|
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
|
+
}
|
|
254
277
|
return;
|
|
255
278
|
}
|
|
256
279
|
try {
|
|
257
|
-
|
|
258
|
-
const wasmBinaryUrl = new URL("../wasm/sqlparser_rs_wasm_web_bg.wasm", import.meta.url);
|
|
259
|
-
const wasm = await import(
|
|
280
|
+
wasmModule = await import(
|
|
260
281
|
/* @vite-ignore */
|
|
261
|
-
|
|
282
|
+
new URL("../wasm/sqlparser_rs_wasm.js", import.meta.url).href
|
|
262
283
|
);
|
|
263
|
-
if (typeof wasm.default === "function") await wasm.default(wasmBinaryUrl);
|
|
264
|
-
wasmModule = wasm;
|
|
265
284
|
} catch (error) {
|
|
266
|
-
throw new WasmInitError(`Failed to load WASM module
|
|
285
|
+
throw new WasmInitError(`Failed to load WASM module: ${error instanceof Error ? error.message : String(error)}`);
|
|
267
286
|
}
|
|
268
287
|
}
|
|
269
288
|
/**
|
|
@@ -338,28 +357,35 @@ var Parser = class Parser {
|
|
|
338
357
|
* Parse SQL statements
|
|
339
358
|
*
|
|
340
359
|
* @param sql - SQL string to parse
|
|
341
|
-
* @param dialect - SQL dialect to use
|
|
360
|
+
* @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
|
|
342
361
|
* @returns Array of parsed statements
|
|
343
362
|
*
|
|
344
363
|
* @example
|
|
345
364
|
* ```typescript
|
|
346
|
-
*
|
|
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());
|
|
347
373
|
* ```
|
|
348
374
|
*/
|
|
349
|
-
static parse(sql, dialect =
|
|
350
|
-
return new Parser(dialect).parse(sql);
|
|
375
|
+
static parse(sql, dialect = "generic") {
|
|
376
|
+
return new Parser(resolveDialect(dialect)).parse(sql);
|
|
351
377
|
}
|
|
352
378
|
/**
|
|
353
379
|
* Parse SQL and return the AST as a JSON string
|
|
354
380
|
*
|
|
355
381
|
* @param sql - SQL string to parse
|
|
356
|
-
* @param dialect - SQL dialect to use
|
|
382
|
+
* @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
|
|
357
383
|
* @returns JSON string representation of the AST
|
|
358
384
|
*/
|
|
359
|
-
static parseToJson(sql, dialect =
|
|
385
|
+
static parseToJson(sql, dialect = "generic") {
|
|
360
386
|
const wasm = getWasmModule();
|
|
361
387
|
try {
|
|
362
|
-
return wasm.parse_sql_to_json_string(dialect.name, sql);
|
|
388
|
+
return wasm.parse_sql_to_json_string(resolveDialect(dialect).name, sql);
|
|
363
389
|
} catch (error) {
|
|
364
390
|
throw ParserError.fromWasmError(error);
|
|
365
391
|
}
|
|
@@ -368,13 +394,13 @@ var Parser = class Parser {
|
|
|
368
394
|
* Parse SQL and return a formatted string representation
|
|
369
395
|
*
|
|
370
396
|
* @param sql - SQL string to parse
|
|
371
|
-
* @param dialect - SQL dialect to use
|
|
397
|
+
* @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
|
|
372
398
|
* @returns String representation of the parsed SQL
|
|
373
399
|
*/
|
|
374
|
-
static parseToString(sql, dialect =
|
|
400
|
+
static parseToString(sql, dialect = "generic") {
|
|
375
401
|
const wasm = getWasmModule();
|
|
376
402
|
try {
|
|
377
|
-
return wasm.parse_sql_to_string(dialect.name, sql);
|
|
403
|
+
return wasm.parse_sql_to_string(resolveDialect(dialect).name, sql);
|
|
378
404
|
} catch (error) {
|
|
379
405
|
throw ParserError.fromWasmError(error);
|
|
380
406
|
}
|
|
@@ -383,13 +409,13 @@ var Parser = class Parser {
|
|
|
383
409
|
* Format SQL by parsing and regenerating it (round-trip)
|
|
384
410
|
*
|
|
385
411
|
* @param sql - SQL string to format
|
|
386
|
-
* @param dialect - SQL dialect to use
|
|
412
|
+
* @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
|
|
387
413
|
* @returns Formatted SQL string
|
|
388
414
|
*/
|
|
389
|
-
static format(sql, dialect =
|
|
415
|
+
static format(sql, dialect = "generic") {
|
|
390
416
|
const wasm = getWasmModule();
|
|
391
417
|
try {
|
|
392
|
-
return wasm.format_sql(dialect.name, sql);
|
|
418
|
+
return wasm.format_sql(resolveDialect(dialect).name, sql);
|
|
393
419
|
} catch (error) {
|
|
394
420
|
throw ParserError.fromWasmError(error);
|
|
395
421
|
}
|
|
@@ -398,13 +424,13 @@ var Parser = class Parser {
|
|
|
398
424
|
* Validate SQL syntax without returning the full AST
|
|
399
425
|
*
|
|
400
426
|
* @param sql - SQL string to validate
|
|
401
|
-
* @param dialect - SQL dialect to use
|
|
427
|
+
* @param dialect - SQL dialect to use (string name or Dialect instance, defaults to 'generic')
|
|
402
428
|
* @returns true if valid, throws ParserError if invalid
|
|
403
429
|
*/
|
|
404
|
-
static validate(sql, dialect =
|
|
430
|
+
static validate(sql, dialect = "generic") {
|
|
405
431
|
const wasm = getWasmModule();
|
|
406
432
|
try {
|
|
407
|
-
return wasm.validate_sql(dialect.name, sql);
|
|
433
|
+
return wasm.validate_sql(resolveDialect(dialect).name, sql);
|
|
408
434
|
} catch (error) {
|
|
409
435
|
throw ParserError.fromWasmError(error);
|
|
410
436
|
}
|
|
@@ -416,6 +442,61 @@ var Parser = class Parser {
|
|
|
416
442
|
return getWasmModule().get_supported_dialects();
|
|
417
443
|
}
|
|
418
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
|
+
}
|
|
419
500
|
|
|
420
501
|
//#endregion
|
|
421
|
-
export { AnsiDialect, BigQueryDialect, ClickHouseDialect, DatabricksDialect, DuckDbDialect, GenericDialect, HiveDialect, MsSqlDialect, MySqlDialect, OracleDialect, Parser, ParserError, PostgreSqlDialect, RedshiftDialect, SQLiteDialect, SUPPORTED_DIALECTS, SnowflakeDialect, WasmInitError, dialectFromString, initWasm };
|
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sqlparser-rs",
|
|
3
|
-
"version": "0.60.3-
|
|
3
|
+
"version": "0.60.3-rc3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A SQL parser for JavaScript and TypeScript, powered by datafusion-sqlparser-rs via WASM",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -18,19 +18,6 @@
|
|
|
18
18
|
"wasm",
|
|
19
19
|
"README.md"
|
|
20
20
|
],
|
|
21
|
-
"scripts": {
|
|
22
|
-
"build": "npm run build:wasm && npm run build:ts",
|
|
23
|
-
"build:wasm": "cd .. && wasm-pack build --target nodejs --out-dir ts/wasm && rm -f ts/wasm/.gitignore",
|
|
24
|
-
"build:wasm:web": "cd .. && wasm-pack build --target web --out-dir ts/wasm-web",
|
|
25
|
-
"build:ts": "tsdown",
|
|
26
|
-
"test": "vitest run",
|
|
27
|
-
"test:watch": "vitest",
|
|
28
|
-
"lint": "eslint src tests",
|
|
29
|
-
"lint:fix": "eslint src tests --fix",
|
|
30
|
-
"prepublishOnly": "npm run build",
|
|
31
|
-
"local:pack": "npm run build:ts && npm pack",
|
|
32
|
-
"local:link": "npm run build:ts && npm link"
|
|
33
|
-
},
|
|
34
21
|
"keywords": [
|
|
35
22
|
"sql",
|
|
36
23
|
"parser",
|
|
@@ -44,7 +31,7 @@
|
|
|
44
31
|
"license": "Apache-2.0",
|
|
45
32
|
"repository": {
|
|
46
33
|
"type": "git",
|
|
47
|
-
"url": "https://github.com/guan404ming/sqlparser-rs"
|
|
34
|
+
"url": "git+https://github.com/guan404ming/sqlparser-rs.git"
|
|
48
35
|
},
|
|
49
36
|
"devDependencies": {
|
|
50
37
|
"@types/node": "^25.0.10",
|
|
@@ -58,5 +45,17 @@
|
|
|
58
45
|
},
|
|
59
46
|
"engines": {
|
|
60
47
|
"node": ">=16.0.0"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "npm run build:wasm && npm run build:ts",
|
|
51
|
+
"build:wasm": "cd .. && wasm-pack build --target nodejs --out-dir ts/wasm && rm -f ts/wasm/.gitignore",
|
|
52
|
+
"build:wasm:web": "cd .. && wasm-pack build --target web --out-dir ts/wasm-web",
|
|
53
|
+
"build:ts": "tsdown",
|
|
54
|
+
"test": "vitest run",
|
|
55
|
+
"test:watch": "vitest",
|
|
56
|
+
"lint": "eslint src tests",
|
|
57
|
+
"lint:fix": "eslint src tests --fix",
|
|
58
|
+
"local:pack": "npm run build:ts && npm pack",
|
|
59
|
+
"local:link": "npm run build:ts && npm link"
|
|
61
60
|
}
|
|
62
|
-
}
|
|
61
|
+
}
|