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.
Files changed (46) hide show
  1. package/README.md +1 -1
  2. package/dist/index.cjs +402 -0
  3. package/dist/index.d.cts +1359 -0
  4. package/dist/index.d.mts +1359 -0
  5. package/dist/index.mjs +384 -0
  6. package/package.json +10 -10
  7. package/wasm/README.md +1 -1
  8. package/wasm/package.json +1 -1
  9. package/wasm/sqlparser_rs_wasm_bg.wasm +0 -0
  10. package/dist/cjs/dialects.js +0 -202
  11. package/dist/cjs/dialects.js.map +0 -1
  12. package/dist/cjs/index.js +0 -81
  13. package/dist/cjs/index.js.map +0 -1
  14. package/dist/cjs/parser.js +0 -191
  15. package/dist/cjs/parser.js.map +0 -1
  16. package/dist/cjs/types/ast.js +0 -10
  17. package/dist/cjs/types/ast.js.map +0 -1
  18. package/dist/cjs/types/errors.js +0 -49
  19. package/dist/cjs/types/errors.js.map +0 -1
  20. package/dist/cjs/types/index.js +0 -19
  21. package/dist/cjs/types/index.js.map +0 -1
  22. package/dist/esm/dialects.js +0 -184
  23. package/dist/esm/dialects.js.map +0 -1
  24. package/dist/esm/index.js +0 -47
  25. package/dist/esm/index.js.map +0 -1
  26. package/dist/esm/package.json +0 -1
  27. package/dist/esm/parser.js +0 -187
  28. package/dist/esm/parser.js.map +0 -1
  29. package/dist/esm/types/ast.js +0 -9
  30. package/dist/esm/types/ast.js.map +0 -1
  31. package/dist/esm/types/errors.js +0 -44
  32. package/dist/esm/types/errors.js.map +0 -1
  33. package/dist/esm/types/index.js +0 -3
  34. package/dist/esm/types/index.js.map +0 -1
  35. package/dist/types/dialects.d.ts +0 -118
  36. package/dist/types/dialects.d.ts.map +0 -1
  37. package/dist/types/index.d.ts +0 -46
  38. package/dist/types/index.d.ts.map +0 -1
  39. package/dist/types/parser.d.ts +0 -116
  40. package/dist/types/parser.d.ts.map +0 -1
  41. package/dist/types/types/ast.d.ts +0 -1097
  42. package/dist/types/types/ast.d.ts.map +0 -1
  43. package/dist/types/types/errors.d.ts +0 -25
  44. package/dist/types/types/errors.d.ts.map +0 -1
  45. package/dist/types/types/index.d.ts +0 -3
  46. package/dist/types/types/index.d.ts.map +0 -1
@@ -1,187 +0,0 @@
1
- import { GenericDialect } from './dialects.js';
2
- import { ParserError, WasmInitError } from './types/errors.js';
3
- // Lazily loaded WASM module - loaded synchronously on first access
4
- let wasmModule = null;
5
- /**
6
- * Get the WASM module (loads synchronously on first access)
7
- */
8
- function getWasmModule() {
9
- if (wasmModule) {
10
- return wasmModule;
11
- }
12
- try {
13
- // Use require() for synchronous loading
14
- // The path is relative to the compiled output in dist/cjs or dist/esm
15
- // eslint-disable-next-line @typescript-eslint/no-require-imports
16
- wasmModule = require('../../wasm/sqlparser_rs_wasm.js');
17
- return wasmModule;
18
- }
19
- catch (error) {
20
- throw new WasmInitError(`Failed to load WASM module: ${error instanceof Error ? error.message : String(error)}`);
21
- }
22
- }
23
- /**
24
- * SQL Parser
25
- *
26
- * Parses SQL statements into an Abstract Syntax Tree (AST).
27
- *
28
- * @example
29
- * ```typescript
30
- * import { Parser, PostgreSqlDialect } from 'sqlparser-rs';
31
- *
32
- * // Simple parsing
33
- * const statements = Parser.parse('SELECT * FROM users', new PostgreSqlDialect());
34
- *
35
- * // With builder pattern
36
- * const parser = new Parser(new PostgreSqlDialect())
37
- * .withRecursionLimit(50)
38
- * .withOptions({ trailingCommas: true });
39
- *
40
- * const ast = parser.parse('SELECT * FROM users');
41
- * ```
42
- */
43
- export class Parser {
44
- /**
45
- * Create a new parser instance
46
- *
47
- * @param dialect - The SQL dialect to use (defaults to GenericDialect)
48
- */
49
- constructor(dialect = new GenericDialect()) {
50
- this.dialect = dialect;
51
- this.options = {};
52
- }
53
- /**
54
- * Set the recursion limit for parsing nested expressions
55
- *
56
- * @param limit - Maximum recursion depth
57
- * @returns This parser instance for chaining
58
- */
59
- withRecursionLimit(limit) {
60
- this.options.recursionLimit = limit;
61
- return this;
62
- }
63
- /**
64
- * Set parser options
65
- *
66
- * @param options - Parser options
67
- * @returns This parser instance for chaining
68
- */
69
- withOptions(options) {
70
- this.options = { ...this.options, ...options };
71
- return this;
72
- }
73
- /**
74
- * Parse SQL statements
75
- *
76
- * @param sql - SQL string to parse
77
- * @returns Array of parsed statements
78
- */
79
- parse(sql) {
80
- const wasm = getWasmModule();
81
- try {
82
- const hasOptions = Object.keys(this.options).length > 0;
83
- if (hasOptions) {
84
- const result = wasm.parse_sql_with_options(this.dialect.name, sql, this.options);
85
- return result;
86
- }
87
- else {
88
- const result = wasm.parse_sql(this.dialect.name, sql);
89
- return result;
90
- }
91
- }
92
- catch (error) {
93
- throw ParserError.fromWasmError(error);
94
- }
95
- }
96
- // ============================================================================
97
- // Static methods for simple one-off parsing
98
- // ============================================================================
99
- /**
100
- * Parse SQL statements
101
- *
102
- * @param sql - SQL string to parse
103
- * @param dialect - SQL dialect to use
104
- * @returns Array of parsed statements
105
- *
106
- * @example
107
- * ```typescript
108
- * const statements = Parser.parse('SELECT 1', new GenericDialect());
109
- * ```
110
- */
111
- static parse(sql, dialect = new GenericDialect()) {
112
- const parser = new Parser(dialect);
113
- return parser.parse(sql);
114
- }
115
- /**
116
- * Parse SQL and return the AST as a JSON string
117
- *
118
- * @param sql - SQL string to parse
119
- * @param dialect - SQL dialect to use
120
- * @returns JSON string representation of the AST
121
- */
122
- static parseToJson(sql, dialect = new GenericDialect()) {
123
- const wasm = getWasmModule();
124
- try {
125
- return wasm.parse_sql_to_json_string(dialect.name, sql);
126
- }
127
- catch (error) {
128
- throw ParserError.fromWasmError(error);
129
- }
130
- }
131
- /**
132
- * Parse SQL and return a formatted string representation
133
- *
134
- * @param sql - SQL string to parse
135
- * @param dialect - SQL dialect to use
136
- * @returns String representation of the parsed SQL
137
- */
138
- static parseToString(sql, dialect = new GenericDialect()) {
139
- const wasm = getWasmModule();
140
- try {
141
- return wasm.parse_sql_to_string(dialect.name, sql);
142
- }
143
- catch (error) {
144
- throw ParserError.fromWasmError(error);
145
- }
146
- }
147
- /**
148
- * Format SQL by parsing and regenerating it (round-trip)
149
- *
150
- * @param sql - SQL string to format
151
- * @param dialect - SQL dialect to use
152
- * @returns Formatted SQL string
153
- */
154
- static format(sql, dialect = new GenericDialect()) {
155
- const wasm = getWasmModule();
156
- try {
157
- return wasm.format_sql(dialect.name, sql);
158
- }
159
- catch (error) {
160
- throw ParserError.fromWasmError(error);
161
- }
162
- }
163
- /**
164
- * Validate SQL syntax without returning the full AST
165
- *
166
- * @param sql - SQL string to validate
167
- * @param dialect - SQL dialect to use
168
- * @returns true if valid, throws ParserError if invalid
169
- */
170
- static validate(sql, dialect = new GenericDialect()) {
171
- const wasm = getWasmModule();
172
- try {
173
- return wasm.validate_sql(dialect.name, sql);
174
- }
175
- catch (error) {
176
- throw ParserError.fromWasmError(error);
177
- }
178
- }
179
- /**
180
- * Get the list of supported dialect names
181
- */
182
- static getSupportedDialects() {
183
- const wasm = getWasmModule();
184
- return wasm.get_supported_dialects();
185
- }
186
- }
187
- //# sourceMappingURL=parser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AA6B/D,mEAAmE;AACnE,IAAI,UAAU,GAAsB,IAAI,CAAC;AAEzC;;GAEG;AACH,SAAS,aAAa;IACpB,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,IAAI,CAAC;QACH,wCAAwC;QACxC,sEAAsE;QACtE,iEAAiE;QACjE,UAAU,GAAG,OAAO,CAAC,iCAAiC,CAAe,CAAC;QACtE,OAAO,UAAU,CAAC;IACpB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,aAAa,CACrB,+BAA+B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G,CAAC,CAAC;QAC5C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,QAAQ,CAAC,GAAW,EAAE,UAAmB,IAAI,cAAc,EAAE;QAClE,MAAM,IAAI,GAAG,aAAa,EAAE,CAAC;QAC7B,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAC9C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,oBAAoB;QACzB,MAAM,IAAI,GAAG,aAAa,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC,sBAAsB,EAAE,CAAC;IACvC,CAAC;CACF"}
@@ -1,9 +0,0 @@
1
- /**
2
- * TypeScript type definitions for sqlparser-rs AST
3
- *
4
- * These types mirror the Rust AST structure from the sqlparser crate.
5
- * The AST is serialized as JSON from Rust, so these types represent
6
- * the JSON structure.
7
- */
8
- export {};
9
- //# sourceMappingURL=ast.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ast.js","sourceRoot":"","sources":["../../../src/types/ast.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
@@ -1,44 +0,0 @@
1
- /**
2
- * Error thrown when SQL parsing fails
3
- */
4
- export class ParserError extends Error {
5
- constructor(message, location) {
6
- super(message);
7
- this.name = 'ParserError';
8
- this.location = location;
9
- // Maintain proper stack trace in V8 environments
10
- if (Error.captureStackTrace) {
11
- Error.captureStackTrace(this, ParserError);
12
- }
13
- }
14
- /**
15
- * Create a ParserError from a WASM error object
16
- */
17
- static fromWasmError(error) {
18
- if (typeof error === 'string') {
19
- return new ParserError(error);
20
- }
21
- if (error && typeof error === 'object') {
22
- const err = error;
23
- const message = typeof err.message === 'string' ? err.message : String(error);
24
- const location = typeof err.line === 'number' && typeof err.column === 'number'
25
- ? { line: err.line, column: err.column }
26
- : undefined;
27
- return new ParserError(message, location);
28
- }
29
- return new ParserError(String(error));
30
- }
31
- }
32
- /**
33
- * Error thrown when WASM module fails to initialize
34
- */
35
- export class WasmInitError extends Error {
36
- constructor(message) {
37
- super(message);
38
- this.name = 'WasmInitError';
39
- if (Error.captureStackTrace) {
40
- Error.captureStackTrace(this, WasmInitError);
41
- }
42
- }
43
- }
44
- //# sourceMappingURL=errors.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/types/errors.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IAGpC,YAAY,OAAe,EAAE,QAAwB;QACnD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,iDAAiD;QACjD,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,KAAc;QACjC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC;QAChC,CAAC;QAED,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACvC,MAAM,GAAG,GAAG,KAAgC,CAAC;YAC7C,MAAM,OAAO,GAAG,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC9E,MAAM,QAAQ,GACZ,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,GAAG,CAAC,MAAM,KAAK,QAAQ;gBAC5D,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE;gBACxC,CAAC,CAAC,SAAS,CAAC;YAChB,OAAO,IAAI,WAAW,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QAC5C,CAAC;QAED,OAAO,IAAI,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACxC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAE5B,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;CACF"}
@@ -1,3 +0,0 @@
1
- export * from './ast.js';
2
- export * from './errors.js';
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC"}
@@ -1,118 +0,0 @@
1
- /**
2
- * SQL Dialects
3
- *
4
- * Each dialect class represents a specific SQL dialect supported by the parser.
5
- * These are thin wrappers that provide type safety and a clean API.
6
- */
7
- /**
8
- * Base interface for all dialects
9
- */
10
- export interface Dialect {
11
- /** The name of the dialect as recognized by the WASM module */
12
- readonly name: string;
13
- }
14
- /**
15
- * Generic SQL dialect - accepts most SQL syntax
16
- */
17
- export declare class GenericDialect implements Dialect {
18
- readonly name = "generic";
19
- }
20
- /**
21
- * ANSI SQL standard dialect
22
- */
23
- export declare class AnsiDialect implements Dialect {
24
- readonly name = "ansi";
25
- }
26
- /**
27
- * MySQL dialect
28
- */
29
- export declare class MySqlDialect implements Dialect {
30
- readonly name = "mysql";
31
- }
32
- /**
33
- * PostgreSQL dialect
34
- */
35
- export declare class PostgreSqlDialect implements Dialect {
36
- readonly name = "postgresql";
37
- }
38
- /**
39
- * SQLite dialect
40
- */
41
- export declare class SQLiteDialect implements Dialect {
42
- readonly name = "sqlite";
43
- }
44
- /**
45
- * Snowflake dialect
46
- */
47
- export declare class SnowflakeDialect implements Dialect {
48
- readonly name = "snowflake";
49
- }
50
- /**
51
- * Amazon Redshift dialect
52
- */
53
- export declare class RedshiftDialect implements Dialect {
54
- readonly name = "redshift";
55
- }
56
- /**
57
- * Microsoft SQL Server dialect
58
- */
59
- export declare class MsSqlDialect implements Dialect {
60
- readonly name = "mssql";
61
- }
62
- /**
63
- * ClickHouse dialect
64
- */
65
- export declare class ClickHouseDialect implements Dialect {
66
- readonly name = "clickhouse";
67
- }
68
- /**
69
- * Google BigQuery dialect
70
- */
71
- export declare class BigQueryDialect implements Dialect {
72
- readonly name = "bigquery";
73
- }
74
- /**
75
- * DuckDB dialect
76
- */
77
- export declare class DuckDbDialect implements Dialect {
78
- readonly name = "duckdb";
79
- }
80
- /**
81
- * Databricks dialect
82
- */
83
- export declare class DatabricksDialect implements Dialect {
84
- readonly name = "databricks";
85
- }
86
- /**
87
- * Apache Hive dialect
88
- */
89
- export declare class HiveDialect implements Dialect {
90
- readonly name = "hive";
91
- }
92
- /**
93
- * Oracle dialect
94
- */
95
- export declare class OracleDialect implements Dialect {
96
- readonly name = "oracle";
97
- }
98
- /**
99
- * All supported dialect names
100
- */
101
- export declare const SUPPORTED_DIALECTS: readonly ["generic", "ansi", "mysql", "postgresql", "sqlite", "snowflake", "redshift", "mssql", "clickhouse", "bigquery", "duckdb", "databricks", "hive", "oracle"];
102
- export type DialectName = (typeof SUPPORTED_DIALECTS)[number];
103
- /**
104
- * Create a dialect instance from a string name
105
- *
106
- * @param name - The name of the dialect (case-insensitive)
107
- * @returns A dialect instance, or undefined if the dialect is not recognized
108
- *
109
- * @example
110
- * ```typescript
111
- * const dialect = dialectFromString('postgresql');
112
- * if (dialect) {
113
- * const ast = Parser.parse('SELECT 1', dialect);
114
- * }
115
- * ```
116
- */
117
- export declare function dialectFromString(name: string): Dialect | undefined;
118
- //# sourceMappingURL=dialects.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dialects.d.ts","sourceRoot":"","sources":["../../src/dialects.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,+DAA+D;IAC/D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,qBAAa,cAAe,YAAW,OAAO;IAC5C,QAAQ,CAAC,IAAI,aAAa;CAC3B;AAED;;GAEG;AACH,qBAAa,WAAY,YAAW,OAAO;IACzC,QAAQ,CAAC,IAAI,UAAU;CACxB;AAED;;GAEG;AACH,qBAAa,YAAa,YAAW,OAAO;IAC1C,QAAQ,CAAC,IAAI,WAAW;CACzB;AAED;;GAEG;AACH,qBAAa,iBAAkB,YAAW,OAAO;IAC/C,QAAQ,CAAC,IAAI,gBAAgB;CAC9B;AAED;;GAEG;AACH,qBAAa,aAAc,YAAW,OAAO;IAC3C,QAAQ,CAAC,IAAI,YAAY;CAC1B;AAED;;GAEG;AACH,qBAAa,gBAAiB,YAAW,OAAO;IAC9C,QAAQ,CAAC,IAAI,eAAe;CAC7B;AAED;;GAEG;AACH,qBAAa,eAAgB,YAAW,OAAO;IAC7C,QAAQ,CAAC,IAAI,cAAc;CAC5B;AAED;;GAEG;AACH,qBAAa,YAAa,YAAW,OAAO;IAC1C,QAAQ,CAAC,IAAI,WAAW;CACzB;AAED;;GAEG;AACH,qBAAa,iBAAkB,YAAW,OAAO;IAC/C,QAAQ,CAAC,IAAI,gBAAgB;CAC9B;AAED;;GAEG;AACH,qBAAa,eAAgB,YAAW,OAAO;IAC7C,QAAQ,CAAC,IAAI,cAAc;CAC5B;AAED;;GAEG;AACH,qBAAa,aAAc,YAAW,OAAO;IAC3C,QAAQ,CAAC,IAAI,YAAY;CAC1B;AAED;;GAEG;AACH,qBAAa,iBAAkB,YAAW,OAAO;IAC/C,QAAQ,CAAC,IAAI,gBAAgB;CAC9B;AAED;;GAEG;AACH,qBAAa,WAAY,YAAW,OAAO;IACzC,QAAQ,CAAC,IAAI,UAAU;CACxB;AAED;;GAEG;AACH,qBAAa,aAAc,YAAW,OAAO;IAC3C,QAAQ,CAAC,IAAI,YAAY;CAC1B;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,qKAerB,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAsB9D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAenE"}
@@ -1,46 +0,0 @@
1
- /**
2
- * sqlparser-rs - SQL Parser for JavaScript/TypeScript
3
- *
4
- * This package wraps the Rust sqlparser crate via WebAssembly, providing
5
- * a fast and accurate SQL parser for JavaScript and TypeScript.
6
- *
7
- * @example
8
- * ```typescript
9
- * import { Parser, GenericDialect, PostgreSqlDialect } from 'sqlparser-rs';
10
- *
11
- * // Simple parsing
12
- * const statements = Parser.parse('SELECT * FROM users', new GenericDialect());
13
- *
14
- * // With specific dialect
15
- * const pgStatements = Parser.parse(
16
- * 'SELECT * FROM users WHERE id = $1',
17
- * new PostgreSqlDialect()
18
- * );
19
- *
20
- * // Builder pattern with options
21
- * const parser = new Parser(new PostgreSqlDialect())
22
- * .withRecursionLimit(50)
23
- * .withOptions({ trailingCommas: true });
24
- *
25
- * const ast = parser.parse('SELECT * FROM users');
26
- *
27
- * // Format SQL
28
- * const formatted = Parser.format('select * from users', new GenericDialect());
29
- * // Returns: "SELECT * FROM users"
30
- *
31
- * // Validate SQL
32
- * try {
33
- * Parser.validate('SELECT * FRO users', new GenericDialect());
34
- * } catch (e) {
35
- * console.log('Invalid SQL:', e.message);
36
- * }
37
- * ```
38
- *
39
- * @packageDocumentation
40
- */
41
- export { Parser } from './parser.js';
42
- export type { ParserOptions } from './parser.js';
43
- export { GenericDialect, AnsiDialect, MySqlDialect, PostgreSqlDialect, SQLiteDialect, SnowflakeDialect, RedshiftDialect, MsSqlDialect, ClickHouseDialect, BigQueryDialect, DuckDbDialect, DatabricksDialect, HiveDialect, OracleDialect, dialectFromString, SUPPORTED_DIALECTS, } from './dialects.js';
44
- export type { Dialect, DialectName } from './dialects.js';
45
- export * from './types/index.js';
46
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,OAAO,EACL,cAAc,EACd,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG1D,cAAc,kBAAkB,CAAC"}
@@ -1,116 +0,0 @@
1
- import type { Dialect } from './dialects.js';
2
- import type { Statement } from './types/ast.js';
3
- /**
4
- * Parser options
5
- */
6
- export interface ParserOptions {
7
- /**
8
- * Allow trailing commas in SELECT lists
9
- */
10
- trailingCommas?: boolean;
11
- /**
12
- * Maximum recursion depth for parsing nested expressions
13
- */
14
- recursionLimit?: number;
15
- }
16
- /**
17
- * SQL Parser
18
- *
19
- * Parses SQL statements into an Abstract Syntax Tree (AST).
20
- *
21
- * @example
22
- * ```typescript
23
- * import { Parser, PostgreSqlDialect } from 'sqlparser-rs';
24
- *
25
- * // Simple parsing
26
- * const statements = Parser.parse('SELECT * FROM users', new PostgreSqlDialect());
27
- *
28
- * // With builder pattern
29
- * const parser = new Parser(new PostgreSqlDialect())
30
- * .withRecursionLimit(50)
31
- * .withOptions({ trailingCommas: true });
32
- *
33
- * const ast = parser.parse('SELECT * FROM users');
34
- * ```
35
- */
36
- export declare class Parser {
37
- private dialect;
38
- private options;
39
- /**
40
- * Create a new parser instance
41
- *
42
- * @param dialect - The SQL dialect to use (defaults to GenericDialect)
43
- */
44
- constructor(dialect?: Dialect);
45
- /**
46
- * Set the recursion limit for parsing nested expressions
47
- *
48
- * @param limit - Maximum recursion depth
49
- * @returns This parser instance for chaining
50
- */
51
- withRecursionLimit(limit: number): Parser;
52
- /**
53
- * Set parser options
54
- *
55
- * @param options - Parser options
56
- * @returns This parser instance for chaining
57
- */
58
- withOptions(options: ParserOptions): Parser;
59
- /**
60
- * Parse SQL statements
61
- *
62
- * @param sql - SQL string to parse
63
- * @returns Array of parsed statements
64
- */
65
- parse(sql: string): Statement[];
66
- /**
67
- * Parse SQL statements
68
- *
69
- * @param sql - SQL string to parse
70
- * @param dialect - SQL dialect to use
71
- * @returns Array of parsed statements
72
- *
73
- * @example
74
- * ```typescript
75
- * const statements = Parser.parse('SELECT 1', new GenericDialect());
76
- * ```
77
- */
78
- static parse(sql: string, dialect?: Dialect): Statement[];
79
- /**
80
- * Parse SQL and return the AST as a JSON string
81
- *
82
- * @param sql - SQL string to parse
83
- * @param dialect - SQL dialect to use
84
- * @returns JSON string representation of the AST
85
- */
86
- static parseToJson(sql: string, dialect?: Dialect): string;
87
- /**
88
- * Parse SQL and return a formatted string representation
89
- *
90
- * @param sql - SQL string to parse
91
- * @param dialect - SQL dialect to use
92
- * @returns String representation of the parsed SQL
93
- */
94
- static parseToString(sql: string, dialect?: Dialect): string;
95
- /**
96
- * Format SQL by parsing and regenerating it (round-trip)
97
- *
98
- * @param sql - SQL string to format
99
- * @param dialect - SQL dialect to use
100
- * @returns Formatted SQL string
101
- */
102
- static format(sql: string, dialect?: Dialect): string;
103
- /**
104
- * Validate SQL syntax without returning the full AST
105
- *
106
- * @param sql - SQL string to validate
107
- * @param dialect - SQL dialect to use
108
- * @returns true if valid, throws ParserError if invalid
109
- */
110
- static validate(sql: string, dialect?: Dialect): boolean;
111
- /**
112
- * Get the list of supported dialect names
113
- */
114
- static getSupportedDialects(): string[];
115
- }
116
- //# sourceMappingURL=parser.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAG7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAqCD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,OAAO,CAAgB;IAE/B;;;;OAIG;gBACS,OAAO,GAAE,OAA8B;IAKnD;;;;;OAKG;IACH,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAKzC;;;;;OAKG;IACH,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM;IAK3C;;;;;OAKG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE;IAyB/B;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,OAA8B,GAAG,SAAS,EAAE;IAK/E;;;;;;OAMG;IACH,MA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