sqlparser-rs 0.60.0-rc4 → 0.60.2
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 +25 -25
- package/dist/cjs/dialects.js +12 -1
- package/dist/cjs/dialects.js.map +1 -1
- package/dist/cjs/index.js +26 -26
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/parser.js +40 -113
- package/dist/cjs/parser.js.map +1 -1
- package/dist/cjs/types/index.js +2 -2
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/esm/dialects.js +10 -0
- package/dist/esm/dialects.js.map +1 -1
- package/dist/esm/index.js +8 -8
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/package.json +1 -0
- package/dist/esm/parser.js +34 -73
- package/dist/esm/parser.js.map +1 -1
- package/dist/esm/types/index.js +2 -2
- package/dist/esm/types/index.js.map +1 -1
- package/dist/types/dialects.d.ts +7 -1
- package/dist/types/dialects.d.ts.map +1 -1
- package/dist/types/index.d.ts +10 -10
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/parser.d.ts +16 -30
- package/dist/types/parser.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +2 -2
- package/dist/types/types/index.d.ts.map +1 -1
- package/package.json +15 -15
- package/wasm/README.md +25 -25
- package/wasm/package.json +1 -1
- package/wasm/sqlparser_rs_wasm_bg.wasm +0 -0
package/wasm/README.md
CHANGED
|
@@ -14,7 +14,6 @@ A SQL parser for JavaScript and TypeScript, powered by [datafusion-sqlparser-rs]
|
|
|
14
14
|
- Parse SQL into a detailed Abstract Syntax Tree (AST)
|
|
15
15
|
- Support for 13+ SQL dialects (PostgreSQL, MySQL, SQLite, BigQuery, etc.)
|
|
16
16
|
- Full TypeScript type definitions
|
|
17
|
-
- Works in Node.js and browsers
|
|
18
17
|
- Fast and accurate parsing using the battle-tested Rust implementation
|
|
19
18
|
- Zero native dependencies
|
|
20
19
|
|
|
@@ -30,22 +29,22 @@ npm install sqlparser-rs
|
|
|
30
29
|
import { Parser, GenericDialect, PostgreSqlDialect } from 'sqlparser-rs';
|
|
31
30
|
|
|
32
31
|
// Simple parsing
|
|
33
|
-
const statements =
|
|
32
|
+
const statements = Parser.parse('SELECT * FROM users', new GenericDialect());
|
|
34
33
|
console.log(statements);
|
|
35
34
|
|
|
36
35
|
// With specific dialect
|
|
37
|
-
const pgStatements =
|
|
36
|
+
const pgStatements = Parser.parse(
|
|
38
37
|
'SELECT * FROM users WHERE id = $1',
|
|
39
38
|
new PostgreSqlDialect()
|
|
40
39
|
);
|
|
41
40
|
|
|
42
41
|
// Format SQL
|
|
43
|
-
const formatted =
|
|
42
|
+
const formatted = Parser.format('select * from users', new GenericDialect());
|
|
44
43
|
console.log(formatted); // "SELECT * FROM users"
|
|
45
44
|
|
|
46
45
|
// Validate SQL
|
|
47
46
|
try {
|
|
48
|
-
|
|
47
|
+
Parser.validate('SELEC * FROM users', new GenericDialect());
|
|
49
48
|
} catch (error) {
|
|
50
49
|
console.log('Invalid SQL:', error.message);
|
|
51
50
|
}
|
|
@@ -61,22 +60,22 @@ The main class for parsing SQL.
|
|
|
61
60
|
|
|
62
61
|
```typescript
|
|
63
62
|
// Parse SQL into statements
|
|
64
|
-
const statements =
|
|
63
|
+
const statements = Parser.parse(sql: string, dialect: Dialect): Statement[];
|
|
65
64
|
|
|
66
65
|
// Parse and return JSON string
|
|
67
|
-
const json =
|
|
66
|
+
const json = Parser.parseToJson(sql: string, dialect: Dialect): string;
|
|
68
67
|
|
|
69
68
|
// Parse and return formatted SQL string
|
|
70
|
-
const formatted =
|
|
69
|
+
const formatted = Parser.parseToString(sql: string, dialect: Dialect): string;
|
|
71
70
|
|
|
72
71
|
// Format SQL (round-trip through parser)
|
|
73
|
-
const formatted =
|
|
72
|
+
const formatted = Parser.format(sql: string, dialect: Dialect): string;
|
|
74
73
|
|
|
75
74
|
// Validate SQL syntax
|
|
76
|
-
const isValid =
|
|
75
|
+
const isValid = Parser.validate(sql: string, dialect: Dialect): boolean;
|
|
77
76
|
|
|
78
77
|
// Get list of supported dialects
|
|
79
|
-
const dialects =
|
|
78
|
+
const dialects = Parser.getSupportedDialects(): string[];
|
|
80
79
|
```
|
|
81
80
|
|
|
82
81
|
#### Instance Methods (Builder Pattern)
|
|
@@ -90,13 +89,7 @@ const parser = new Parser(new PostgreSqlDialect())
|
|
|
90
89
|
trailingCommas: true
|
|
91
90
|
});
|
|
92
91
|
|
|
93
|
-
|
|
94
|
-
const statements = await parser.parseAsync('SELECT * FROM users');
|
|
95
|
-
|
|
96
|
-
// Parse synchronously (requires initWasm() first)
|
|
97
|
-
import { initWasm } from 'sqlparser-rs';
|
|
98
|
-
await initWasm();
|
|
99
|
-
const statements = parser.parseSync('SELECT * FROM users');
|
|
92
|
+
const statements = parser.parse('SELECT * FROM users');
|
|
100
93
|
```
|
|
101
94
|
|
|
102
95
|
### Dialects
|
|
@@ -131,7 +124,7 @@ const dialect = dialectFromString('postgresql'); // Returns PostgreSqlDialect in
|
|
|
131
124
|
import { Parser, GenericDialect, ParserError } from 'sqlparser-rs';
|
|
132
125
|
|
|
133
126
|
try {
|
|
134
|
-
|
|
127
|
+
Parser.parse('SELEC * FROM users', new GenericDialect());
|
|
135
128
|
} catch (error) {
|
|
136
129
|
if (error instanceof ParserError) {
|
|
137
130
|
console.log('Parse error:', error.message);
|
|
@@ -149,7 +142,7 @@ Full TypeScript types are provided for the AST:
|
|
|
149
142
|
```typescript
|
|
150
143
|
import type { Statement, Query, Expr, Ident, ObjectName } from 'sqlparser-rs';
|
|
151
144
|
|
|
152
|
-
const statements: Statement[] =
|
|
145
|
+
const statements: Statement[] = Parser.parse('SELECT 1', new GenericDialect());
|
|
153
146
|
|
|
154
147
|
// Statement is a discriminated union type
|
|
155
148
|
for (const stmt of statements) {
|
|
@@ -162,7 +155,7 @@ for (const stmt of statements) {
|
|
|
162
155
|
}
|
|
163
156
|
```
|
|
164
157
|
|
|
165
|
-
##
|
|
158
|
+
## Development
|
|
166
159
|
|
|
167
160
|
### Prerequisites
|
|
168
161
|
|
|
@@ -186,22 +179,29 @@ npm install
|
|
|
186
179
|
npm run build
|
|
187
180
|
```
|
|
188
181
|
|
|
189
|
-
###
|
|
182
|
+
### Tests
|
|
190
183
|
|
|
191
184
|
```bash
|
|
192
185
|
cd ts
|
|
193
186
|
npm test
|
|
194
187
|
```
|
|
195
188
|
|
|
196
|
-
##
|
|
189
|
+
## Versioning
|
|
190
|
+
|
|
191
|
+
This package follows the upstream [sqlparser-rs](https://github.com/apache/datafusion-sqlparser-rs) version:
|
|
192
|
+
|
|
193
|
+
- **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)
|
|
197
195
|
|
|
198
196
|
| This package | sqlparser-rs |
|
|
199
197
|
|--------------|--------------|
|
|
200
|
-
| 0.60.
|
|
198
|
+
| 0.60.x | 0.60.0 |
|
|
199
|
+
|
|
200
|
+
This approach is similar to [esbuild-wasm](https://github.com/evanw/esbuild) and [duckdb-wasm](https://github.com/duckdb/duckdb-wasm).
|
|
201
201
|
|
|
202
202
|
## License
|
|
203
203
|
|
|
204
|
-
Apache-2.0
|
|
204
|
+
Apache-2.0
|
|
205
205
|
|
|
206
206
|
## Related Projects
|
|
207
207
|
|
package/wasm/package.json
CHANGED
|
Binary file
|