sqlparser-rs 0.60.0-rc2 → 0.60.0-rc4

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 ADDED
@@ -0,0 +1,209 @@
1
+ # sqlparser-rs
2
+
3
+ [![npm version](https://img.shields.io/npm/v/sqlparser-rs.svg)](https://www.npmjs.com/package/sqlparser-rs)
4
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)
6
+ [![Node.js](https://img.shields.io/badge/Node.js-16+-green.svg)](https://nodejs.org/)
7
+ [![WebAssembly](https://img.shields.io/badge/WebAssembly-powered-blueviolet.svg)](https://webassembly.org/)
8
+ [![sqlparser](https://img.shields.io/badge/sqlparser--rs-v0.60.0-orange.svg)](https://github.com/apache/datafusion-sqlparser-rs)
9
+
10
+ A SQL parser for JavaScript and TypeScript, powered by [datafusion-sqlparser-rs](https://github.com/apache/datafusion-sqlparser-rs) via WebAssembly.
11
+
12
+ ## Features
13
+
14
+ - Parse SQL into a detailed Abstract Syntax Tree (AST)
15
+ - Support for 13+ SQL dialects (PostgreSQL, MySQL, SQLite, BigQuery, etc.)
16
+ - Full TypeScript type definitions
17
+ - Works in Node.js and browsers
18
+ - Fast and accurate parsing using the battle-tested Rust implementation
19
+ - Zero native dependencies
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ npm install sqlparser-rs
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ ```typescript
30
+ import { Parser, GenericDialect, PostgreSqlDialect } from 'sqlparser-rs';
31
+
32
+ // Simple parsing
33
+ const statements = await Parser.parse('SELECT * FROM users', new GenericDialect());
34
+ console.log(statements);
35
+
36
+ // With specific dialect
37
+ const pgStatements = await Parser.parse(
38
+ 'SELECT * FROM users WHERE id = $1',
39
+ new PostgreSqlDialect()
40
+ );
41
+
42
+ // Format SQL
43
+ const formatted = await Parser.format('select * from users', new GenericDialect());
44
+ console.log(formatted); // "SELECT * FROM users"
45
+
46
+ // Validate SQL
47
+ try {
48
+ await Parser.validate('SELEC * FROM users', new GenericDialect());
49
+ } catch (error) {
50
+ console.log('Invalid SQL:', error.message);
51
+ }
52
+ ```
53
+
54
+ ## API
55
+
56
+ ### Parser
57
+
58
+ The main class for parsing SQL.
59
+
60
+ #### Static Methods
61
+
62
+ ```typescript
63
+ // Parse SQL into statements
64
+ const statements = await Parser.parse(sql: string, dialect: Dialect): Promise<Statement[]>;
65
+
66
+ // Parse and return JSON string
67
+ const json = await Parser.parseToJson(sql: string, dialect: Dialect): Promise<string>;
68
+
69
+ // Parse and return formatted SQL string
70
+ const formatted = await Parser.parseToString(sql: string, dialect: Dialect): Promise<string>;
71
+
72
+ // Format SQL (round-trip through parser)
73
+ const formatted = await Parser.format(sql: string, dialect: Dialect): Promise<string>;
74
+
75
+ // Validate SQL syntax
76
+ const isValid = await Parser.validate(sql: string, dialect: Dialect): Promise<boolean>;
77
+
78
+ // Get list of supported dialects
79
+ const dialects = await Parser.getSupportedDialects(): Promise<string[]>;
80
+ ```
81
+
82
+ #### Instance Methods (Builder Pattern)
83
+
84
+ ```typescript
85
+ import { Parser, PostgreSqlDialect } from 'sqlparser-rs';
86
+
87
+ const parser = new Parser(new PostgreSqlDialect())
88
+ .withRecursionLimit(50) // Set max recursion depth
89
+ .withOptions({ // Set parser options
90
+ trailingCommas: true
91
+ });
92
+
93
+ // Parse asynchronously
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');
100
+ ```
101
+
102
+ ### Dialects
103
+
104
+ All dialects from the upstream Rust crate are supported:
105
+
106
+ ```typescript
107
+ import {
108
+ GenericDialect, // Permissive, accepts most SQL syntax
109
+ AnsiDialect, // ANSI SQL standard
110
+ MySqlDialect, // MySQL
111
+ PostgreSqlDialect, // PostgreSQL
112
+ SQLiteDialect, // SQLite
113
+ SnowflakeDialect, // Snowflake
114
+ RedshiftDialect, // Amazon Redshift
115
+ MsSqlDialect, // Microsoft SQL Server
116
+ ClickHouseDialect, // ClickHouse
117
+ BigQueryDialect, // Google BigQuery
118
+ DuckDbDialect, // DuckDB
119
+ DatabricksDialect, // Databricks
120
+ HiveDialect, // Apache Hive
121
+ } from 'sqlparser-rs';
122
+
123
+ // Create dialect from string
124
+ import { dialectFromString } from 'sqlparser-rs';
125
+ const dialect = dialectFromString('postgresql'); // Returns PostgreSqlDialect instance
126
+ ```
127
+
128
+ ### Error Handling
129
+
130
+ ```typescript
131
+ import { Parser, GenericDialect, ParserError } from 'sqlparser-rs';
132
+
133
+ try {
134
+ await Parser.parse('SELEC * FROM users', new GenericDialect());
135
+ } catch (error) {
136
+ if (error instanceof ParserError) {
137
+ console.log('Parse error:', error.message);
138
+ if (error.location) {
139
+ console.log(`At line ${error.location.line}, column ${error.location.column}`);
140
+ }
141
+ }
142
+ }
143
+ ```
144
+
145
+ ### AST Types
146
+
147
+ Full TypeScript types are provided for the AST:
148
+
149
+ ```typescript
150
+ import type { Statement, Query, Expr, Ident, ObjectName } from 'sqlparser-rs';
151
+
152
+ const statements: Statement[] = await Parser.parse('SELECT 1', new GenericDialect());
153
+
154
+ // Statement is a discriminated union type
155
+ for (const stmt of statements) {
156
+ if ('Query' in stmt) {
157
+ const query: Query = stmt.Query;
158
+ console.log('Found SELECT query');
159
+ } else if ('Insert' in stmt) {
160
+ console.log('Found INSERT statement');
161
+ }
162
+ }
163
+ ```
164
+
165
+ ## Building from Source
166
+
167
+ ### Prerequisites
168
+
169
+ - Rust toolchain (1.70+)
170
+ - wasm-pack (`cargo install wasm-pack`)
171
+ - Node.js (16+)
172
+
173
+ ### Build
174
+
175
+ ```bash
176
+ # Build everything
177
+ ./scripts/build.sh
178
+
179
+ # Or step by step:
180
+ # 1. Build WASM
181
+ wasm-pack build --target nodejs --out-dir ts/wasm
182
+
183
+ # 2. Build TypeScript
184
+ cd ts
185
+ npm install
186
+ npm run build
187
+ ```
188
+
189
+ ### Run Tests
190
+
191
+ ```bash
192
+ cd ts
193
+ npm test
194
+ ```
195
+
196
+ ## Version
197
+
198
+ | This package | sqlparser-rs |
199
+ |--------------|--------------|
200
+ | 0.60.0-x | 0.60.0 |
201
+
202
+ ## License
203
+
204
+ Apache-2.0, matching the upstream Rust crate.
205
+
206
+ ## Related Projects
207
+
208
+ - [datafusion-sqlparser-rs](https://github.com/apache/datafusion-sqlparser-rs) - The Rust SQL parser this package wraps
209
+ - [Apache DataFusion](https://github.com/apache/datafusion) - Query execution framework using sqlparser-rs
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sqlparser-rs",
3
- "version": "0.60.0-rc2",
3
+ "version": "0.60.0-rc4",
4
4
  "description": "A SQL parser for JavaScript and TypeScript, powered by datafusion-sqlparser-rs via WASM",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -19,7 +19,7 @@
19
19
  ],
20
20
  "scripts": {
21
21
  "build": "npm run build:wasm && npm run build:ts",
22
- "build:wasm": "cd .. && wasm-pack build --target nodejs --out-dir ts/wasm",
22
+ "build:wasm": "cd .. && wasm-pack build --target nodejs --out-dir ts/wasm && rm -f ts/wasm/.gitignore",
23
23
  "build:wasm:web": "cd .. && wasm-pack build --target web --out-dir ts/wasm-web",
24
24
  "build:ts": "npm run build:esm && npm run build:cjs",
25
25
  "build:esm": "tsc -p tsconfig.esm.json",
package/wasm/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/wasm/README.md ADDED
@@ -0,0 +1,209 @@
1
+ # sqlparser-rs
2
+
3
+ [![npm version](https://img.shields.io/npm/v/sqlparser-rs.svg)](https://www.npmjs.com/package/sqlparser-rs)
4
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)
6
+ [![Node.js](https://img.shields.io/badge/Node.js-16+-green.svg)](https://nodejs.org/)
7
+ [![WebAssembly](https://img.shields.io/badge/WebAssembly-powered-blueviolet.svg)](https://webassembly.org/)
8
+ [![sqlparser](https://img.shields.io/badge/sqlparser--rs-v0.60.0-orange.svg)](https://github.com/apache/datafusion-sqlparser-rs)
9
+
10
+ A SQL parser for JavaScript and TypeScript, powered by [datafusion-sqlparser-rs](https://github.com/apache/datafusion-sqlparser-rs) via WebAssembly.
11
+
12
+ ## Features
13
+
14
+ - Parse SQL into a detailed Abstract Syntax Tree (AST)
15
+ - Support for 13+ SQL dialects (PostgreSQL, MySQL, SQLite, BigQuery, etc.)
16
+ - Full TypeScript type definitions
17
+ - Works in Node.js and browsers
18
+ - Fast and accurate parsing using the battle-tested Rust implementation
19
+ - Zero native dependencies
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ npm install sqlparser-rs
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ ```typescript
30
+ import { Parser, GenericDialect, PostgreSqlDialect } from 'sqlparser-rs';
31
+
32
+ // Simple parsing
33
+ const statements = await Parser.parse('SELECT * FROM users', new GenericDialect());
34
+ console.log(statements);
35
+
36
+ // With specific dialect
37
+ const pgStatements = await Parser.parse(
38
+ 'SELECT * FROM users WHERE id = $1',
39
+ new PostgreSqlDialect()
40
+ );
41
+
42
+ // Format SQL
43
+ const formatted = await Parser.format('select * from users', new GenericDialect());
44
+ console.log(formatted); // "SELECT * FROM users"
45
+
46
+ // Validate SQL
47
+ try {
48
+ await Parser.validate('SELEC * FROM users', new GenericDialect());
49
+ } catch (error) {
50
+ console.log('Invalid SQL:', error.message);
51
+ }
52
+ ```
53
+
54
+ ## API
55
+
56
+ ### Parser
57
+
58
+ The main class for parsing SQL.
59
+
60
+ #### Static Methods
61
+
62
+ ```typescript
63
+ // Parse SQL into statements
64
+ const statements = await Parser.parse(sql: string, dialect: Dialect): Promise<Statement[]>;
65
+
66
+ // Parse and return JSON string
67
+ const json = await Parser.parseToJson(sql: string, dialect: Dialect): Promise<string>;
68
+
69
+ // Parse and return formatted SQL string
70
+ const formatted = await Parser.parseToString(sql: string, dialect: Dialect): Promise<string>;
71
+
72
+ // Format SQL (round-trip through parser)
73
+ const formatted = await Parser.format(sql: string, dialect: Dialect): Promise<string>;
74
+
75
+ // Validate SQL syntax
76
+ const isValid = await Parser.validate(sql: string, dialect: Dialect): Promise<boolean>;
77
+
78
+ // Get list of supported dialects
79
+ const dialects = await Parser.getSupportedDialects(): Promise<string[]>;
80
+ ```
81
+
82
+ #### Instance Methods (Builder Pattern)
83
+
84
+ ```typescript
85
+ import { Parser, PostgreSqlDialect } from 'sqlparser-rs';
86
+
87
+ const parser = new Parser(new PostgreSqlDialect())
88
+ .withRecursionLimit(50) // Set max recursion depth
89
+ .withOptions({ // Set parser options
90
+ trailingCommas: true
91
+ });
92
+
93
+ // Parse asynchronously
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');
100
+ ```
101
+
102
+ ### Dialects
103
+
104
+ All dialects from the upstream Rust crate are supported:
105
+
106
+ ```typescript
107
+ import {
108
+ GenericDialect, // Permissive, accepts most SQL syntax
109
+ AnsiDialect, // ANSI SQL standard
110
+ MySqlDialect, // MySQL
111
+ PostgreSqlDialect, // PostgreSQL
112
+ SQLiteDialect, // SQLite
113
+ SnowflakeDialect, // Snowflake
114
+ RedshiftDialect, // Amazon Redshift
115
+ MsSqlDialect, // Microsoft SQL Server
116
+ ClickHouseDialect, // ClickHouse
117
+ BigQueryDialect, // Google BigQuery
118
+ DuckDbDialect, // DuckDB
119
+ DatabricksDialect, // Databricks
120
+ HiveDialect, // Apache Hive
121
+ } from 'sqlparser-rs';
122
+
123
+ // Create dialect from string
124
+ import { dialectFromString } from 'sqlparser-rs';
125
+ const dialect = dialectFromString('postgresql'); // Returns PostgreSqlDialect instance
126
+ ```
127
+
128
+ ### Error Handling
129
+
130
+ ```typescript
131
+ import { Parser, GenericDialect, ParserError } from 'sqlparser-rs';
132
+
133
+ try {
134
+ await Parser.parse('SELEC * FROM users', new GenericDialect());
135
+ } catch (error) {
136
+ if (error instanceof ParserError) {
137
+ console.log('Parse error:', error.message);
138
+ if (error.location) {
139
+ console.log(`At line ${error.location.line}, column ${error.location.column}`);
140
+ }
141
+ }
142
+ }
143
+ ```
144
+
145
+ ### AST Types
146
+
147
+ Full TypeScript types are provided for the AST:
148
+
149
+ ```typescript
150
+ import type { Statement, Query, Expr, Ident, ObjectName } from 'sqlparser-rs';
151
+
152
+ const statements: Statement[] = await Parser.parse('SELECT 1', new GenericDialect());
153
+
154
+ // Statement is a discriminated union type
155
+ for (const stmt of statements) {
156
+ if ('Query' in stmt) {
157
+ const query: Query = stmt.Query;
158
+ console.log('Found SELECT query');
159
+ } else if ('Insert' in stmt) {
160
+ console.log('Found INSERT statement');
161
+ }
162
+ }
163
+ ```
164
+
165
+ ## Building from Source
166
+
167
+ ### Prerequisites
168
+
169
+ - Rust toolchain (1.70+)
170
+ - wasm-pack (`cargo install wasm-pack`)
171
+ - Node.js (16+)
172
+
173
+ ### Build
174
+
175
+ ```bash
176
+ # Build everything
177
+ ./scripts/build.sh
178
+
179
+ # Or step by step:
180
+ # 1. Build WASM
181
+ wasm-pack build --target nodejs --out-dir ts/wasm
182
+
183
+ # 2. Build TypeScript
184
+ cd ts
185
+ npm install
186
+ npm run build
187
+ ```
188
+
189
+ ### Run Tests
190
+
191
+ ```bash
192
+ cd ts
193
+ npm test
194
+ ```
195
+
196
+ ## Version
197
+
198
+ | This package | sqlparser-rs |
199
+ |--------------|--------------|
200
+ | 0.60.0-x | 0.60.0 |
201
+
202
+ ## License
203
+
204
+ Apache-2.0, matching the upstream Rust crate.
205
+
206
+ ## Related Projects
207
+
208
+ - [datafusion-sqlparser-rs](https://github.com/apache/datafusion-sqlparser-rs) - The Rust SQL parser this package wraps
209
+ - [Apache DataFusion](https://github.com/apache/datafusion) - Query execution framework using sqlparser-rs
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "sqlparser-rs-wasm",
3
+ "description": "WebAssembly bindings for sqlparser-rs SQL parser",
4
+ "version": "0.60.0-rc4",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/guan404ming/sqlparser-rs"
9
+ },
10
+ "files": [
11
+ "sqlparser_rs_wasm_bg.wasm",
12
+ "sqlparser_rs_wasm.js",
13
+ "sqlparser_rs_wasm.d.ts"
14
+ ],
15
+ "main": "sqlparser_rs_wasm.js",
16
+ "types": "sqlparser_rs_wasm.d.ts"
17
+ }
@@ -0,0 +1,39 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Format SQL by parsing and regenerating it (round-trip)
6
+ */
7
+ export function format_sql(dialect: string, sql: string): string;
8
+
9
+ /**
10
+ * Get a list of all supported dialect names
11
+ */
12
+ export function get_supported_dialects(): any;
13
+
14
+ export function init(): void;
15
+
16
+ /**
17
+ * Parse SQL and return the AST as a JSON value
18
+ */
19
+ export function parse_sql(dialect: string, sql: string): any;
20
+
21
+ /**
22
+ * Parse SQL and return the AST as a JSON string
23
+ */
24
+ export function parse_sql_to_json_string(dialect: string, sql: string): string;
25
+
26
+ /**
27
+ * Parse SQL and return a string representation of the AST
28
+ */
29
+ export function parse_sql_to_string(dialect: string, sql: string): string;
30
+
31
+ /**
32
+ * Parse SQL with options and return the AST as a JSON value
33
+ */
34
+ export function parse_sql_with_options(dialect: string, sql: string, options: any): any;
35
+
36
+ /**
37
+ * Validate SQL syntax without returning the full AST
38
+ */
39
+ export function validate_sql(dialect: string, sql: string): boolean;
@@ -0,0 +1,541 @@
1
+ /* @ts-self-types="./sqlparser_rs_wasm.d.ts" */
2
+
3
+ /**
4
+ * Format SQL by parsing and regenerating it (round-trip)
5
+ * @param {string} dialect
6
+ * @param {string} sql
7
+ * @returns {string}
8
+ */
9
+ function format_sql(dialect, sql) {
10
+ let deferred4_0;
11
+ let deferred4_1;
12
+ try {
13
+ const ptr0 = passStringToWasm0(dialect, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
14
+ const len0 = WASM_VECTOR_LEN;
15
+ const ptr1 = passStringToWasm0(sql, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
16
+ const len1 = WASM_VECTOR_LEN;
17
+ const ret = wasm.format_sql(ptr0, len0, ptr1, len1);
18
+ var ptr3 = ret[0];
19
+ var len3 = ret[1];
20
+ if (ret[3]) {
21
+ ptr3 = 0; len3 = 0;
22
+ throw takeFromExternrefTable0(ret[2]);
23
+ }
24
+ deferred4_0 = ptr3;
25
+ deferred4_1 = len3;
26
+ return getStringFromWasm0(ptr3, len3);
27
+ } finally {
28
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
29
+ }
30
+ }
31
+ exports.format_sql = format_sql;
32
+
33
+ /**
34
+ * Get a list of all supported dialect names
35
+ * @returns {any}
36
+ */
37
+ function get_supported_dialects() {
38
+ const ret = wasm.get_supported_dialects();
39
+ return ret;
40
+ }
41
+ exports.get_supported_dialects = get_supported_dialects;
42
+
43
+ function init() {
44
+ wasm.init();
45
+ }
46
+ exports.init = init;
47
+
48
+ /**
49
+ * Parse SQL and return the AST as a JSON value
50
+ * @param {string} dialect
51
+ * @param {string} sql
52
+ * @returns {any}
53
+ */
54
+ function parse_sql(dialect, sql) {
55
+ const ptr0 = passStringToWasm0(dialect, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
56
+ const len0 = WASM_VECTOR_LEN;
57
+ const ptr1 = passStringToWasm0(sql, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
58
+ const len1 = WASM_VECTOR_LEN;
59
+ const ret = wasm.parse_sql(ptr0, len0, ptr1, len1);
60
+ if (ret[2]) {
61
+ throw takeFromExternrefTable0(ret[1]);
62
+ }
63
+ return takeFromExternrefTable0(ret[0]);
64
+ }
65
+ exports.parse_sql = parse_sql;
66
+
67
+ /**
68
+ * Parse SQL and return the AST as a JSON string
69
+ * @param {string} dialect
70
+ * @param {string} sql
71
+ * @returns {string}
72
+ */
73
+ function parse_sql_to_json_string(dialect, sql) {
74
+ let deferred4_0;
75
+ let deferred4_1;
76
+ try {
77
+ const ptr0 = passStringToWasm0(dialect, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
78
+ const len0 = WASM_VECTOR_LEN;
79
+ const ptr1 = passStringToWasm0(sql, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
80
+ const len1 = WASM_VECTOR_LEN;
81
+ const ret = wasm.parse_sql_to_json_string(ptr0, len0, ptr1, len1);
82
+ var ptr3 = ret[0];
83
+ var len3 = ret[1];
84
+ if (ret[3]) {
85
+ ptr3 = 0; len3 = 0;
86
+ throw takeFromExternrefTable0(ret[2]);
87
+ }
88
+ deferred4_0 = ptr3;
89
+ deferred4_1 = len3;
90
+ return getStringFromWasm0(ptr3, len3);
91
+ } finally {
92
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
93
+ }
94
+ }
95
+ exports.parse_sql_to_json_string = parse_sql_to_json_string;
96
+
97
+ /**
98
+ * Parse SQL and return a string representation of the AST
99
+ * @param {string} dialect
100
+ * @param {string} sql
101
+ * @returns {string}
102
+ */
103
+ function parse_sql_to_string(dialect, sql) {
104
+ let deferred4_0;
105
+ let deferred4_1;
106
+ try {
107
+ const ptr0 = passStringToWasm0(dialect, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
108
+ const len0 = WASM_VECTOR_LEN;
109
+ const ptr1 = passStringToWasm0(sql, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
110
+ const len1 = WASM_VECTOR_LEN;
111
+ const ret = wasm.parse_sql_to_string(ptr0, len0, ptr1, len1);
112
+ var ptr3 = ret[0];
113
+ var len3 = ret[1];
114
+ if (ret[3]) {
115
+ ptr3 = 0; len3 = 0;
116
+ throw takeFromExternrefTable0(ret[2]);
117
+ }
118
+ deferred4_0 = ptr3;
119
+ deferred4_1 = len3;
120
+ return getStringFromWasm0(ptr3, len3);
121
+ } finally {
122
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
123
+ }
124
+ }
125
+ exports.parse_sql_to_string = parse_sql_to_string;
126
+
127
+ /**
128
+ * Parse SQL with options and return the AST as a JSON value
129
+ * @param {string} dialect
130
+ * @param {string} sql
131
+ * @param {any} options
132
+ * @returns {any}
133
+ */
134
+ function parse_sql_with_options(dialect, sql, options) {
135
+ const ptr0 = passStringToWasm0(dialect, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
136
+ const len0 = WASM_VECTOR_LEN;
137
+ const ptr1 = passStringToWasm0(sql, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
138
+ const len1 = WASM_VECTOR_LEN;
139
+ const ret = wasm.parse_sql_with_options(ptr0, len0, ptr1, len1, options);
140
+ if (ret[2]) {
141
+ throw takeFromExternrefTable0(ret[1]);
142
+ }
143
+ return takeFromExternrefTable0(ret[0]);
144
+ }
145
+ exports.parse_sql_with_options = parse_sql_with_options;
146
+
147
+ /**
148
+ * Validate SQL syntax without returning the full AST
149
+ * @param {string} dialect
150
+ * @param {string} sql
151
+ * @returns {boolean}
152
+ */
153
+ function validate_sql(dialect, sql) {
154
+ const ptr0 = passStringToWasm0(dialect, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
155
+ const len0 = WASM_VECTOR_LEN;
156
+ const ptr1 = passStringToWasm0(sql, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
157
+ const len1 = WASM_VECTOR_LEN;
158
+ const ret = wasm.validate_sql(ptr0, len0, ptr1, len1);
159
+ if (ret[2]) {
160
+ throw takeFromExternrefTable0(ret[1]);
161
+ }
162
+ return ret[0] !== 0;
163
+ }
164
+ exports.validate_sql = validate_sql;
165
+
166
+ function __wbg_get_imports() {
167
+ const import0 = {
168
+ __proto__: null,
169
+ __wbg_Error_8c4e43fe74559d73: function(arg0, arg1) {
170
+ const ret = Error(getStringFromWasm0(arg0, arg1));
171
+ return ret;
172
+ },
173
+ __wbg_Number_04624de7d0e8332d: function(arg0) {
174
+ const ret = Number(arg0);
175
+ return ret;
176
+ },
177
+ __wbg_String_8f0eb39a4a4c2f66: function(arg0, arg1) {
178
+ const ret = String(arg1);
179
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
180
+ const len1 = WASM_VECTOR_LEN;
181
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
182
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
183
+ },
184
+ __wbg___wbindgen_bigint_get_as_i64_8fcf4ce7f1ca72a2: function(arg0, arg1) {
185
+ const v = arg1;
186
+ const ret = typeof(v) === 'bigint' ? v : undefined;
187
+ getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
188
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
189
+ },
190
+ __wbg___wbindgen_boolean_get_bbbb1c18aa2f5e25: function(arg0) {
191
+ const v = arg0;
192
+ const ret = typeof(v) === 'boolean' ? v : undefined;
193
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
194
+ },
195
+ __wbg___wbindgen_debug_string_0bc8482c6e3508ae: function(arg0, arg1) {
196
+ const ret = debugString(arg1);
197
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
198
+ const len1 = WASM_VECTOR_LEN;
199
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
200
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
201
+ },
202
+ __wbg___wbindgen_in_47fa6863be6f2f25: function(arg0, arg1) {
203
+ const ret = arg0 in arg1;
204
+ return ret;
205
+ },
206
+ __wbg___wbindgen_is_bigint_31b12575b56f32fc: function(arg0) {
207
+ const ret = typeof(arg0) === 'bigint';
208
+ return ret;
209
+ },
210
+ __wbg___wbindgen_is_null_ac34f5003991759a: function(arg0) {
211
+ const ret = arg0 === null;
212
+ return ret;
213
+ },
214
+ __wbg___wbindgen_is_object_5ae8e5880f2c1fbd: function(arg0) {
215
+ const val = arg0;
216
+ const ret = typeof(val) === 'object' && val !== null;
217
+ return ret;
218
+ },
219
+ __wbg___wbindgen_is_undefined_9e4d92534c42d778: function(arg0) {
220
+ const ret = arg0 === undefined;
221
+ return ret;
222
+ },
223
+ __wbg___wbindgen_jsval_eq_11888390b0186270: function(arg0, arg1) {
224
+ const ret = arg0 === arg1;
225
+ return ret;
226
+ },
227
+ __wbg___wbindgen_jsval_loose_eq_9dd77d8cd6671811: function(arg0, arg1) {
228
+ const ret = arg0 == arg1;
229
+ return ret;
230
+ },
231
+ __wbg___wbindgen_number_get_8ff4255516ccad3e: function(arg0, arg1) {
232
+ const obj = arg1;
233
+ const ret = typeof(obj) === 'number' ? obj : undefined;
234
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
235
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
236
+ },
237
+ __wbg___wbindgen_string_get_72fb696202c56729: function(arg0, arg1) {
238
+ const obj = arg1;
239
+ const ret = typeof(obj) === 'string' ? obj : undefined;
240
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
241
+ var len1 = WASM_VECTOR_LEN;
242
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
243
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
244
+ },
245
+ __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
246
+ throw new Error(getStringFromWasm0(arg0, arg1));
247
+ },
248
+ __wbg_error_7534b8e9a36f1ab4: function(arg0, arg1) {
249
+ let deferred0_0;
250
+ let deferred0_1;
251
+ try {
252
+ deferred0_0 = arg0;
253
+ deferred0_1 = arg1;
254
+ console.error(getStringFromWasm0(arg0, arg1));
255
+ } finally {
256
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
257
+ }
258
+ },
259
+ __wbg_fromCodePoint_22365db7b7d6ac39: function() { return handleError(function (arg0) {
260
+ const ret = String.fromCodePoint(arg0 >>> 0);
261
+ return ret;
262
+ }, arguments); },
263
+ __wbg_get_with_ref_key_1dc361bd10053bfe: function(arg0, arg1) {
264
+ const ret = arg0[arg1];
265
+ return ret;
266
+ },
267
+ __wbg_instanceof_ArrayBuffer_c367199e2fa2aa04: function(arg0) {
268
+ let result;
269
+ try {
270
+ result = arg0 instanceof ArrayBuffer;
271
+ } catch (_) {
272
+ result = false;
273
+ }
274
+ const ret = result;
275
+ return ret;
276
+ },
277
+ __wbg_instanceof_Uint8Array_9b9075935c74707c: function(arg0) {
278
+ let result;
279
+ try {
280
+ result = arg0 instanceof Uint8Array;
281
+ } catch (_) {
282
+ result = false;
283
+ }
284
+ const ret = result;
285
+ return ret;
286
+ },
287
+ __wbg_isSafeInteger_bfbc7332a9768d2a: function(arg0) {
288
+ const ret = Number.isSafeInteger(arg0);
289
+ return ret;
290
+ },
291
+ __wbg_length_32ed9a279acd054c: function(arg0) {
292
+ const ret = arg0.length;
293
+ return ret;
294
+ },
295
+ __wbg_new_361308b2356cecd0: function() {
296
+ const ret = new Object();
297
+ return ret;
298
+ },
299
+ __wbg_new_3eb36ae241fe6f44: function() {
300
+ const ret = new Array();
301
+ return ret;
302
+ },
303
+ __wbg_new_8a6f238a6ece86ea: function() {
304
+ const ret = new Error();
305
+ return ret;
306
+ },
307
+ __wbg_new_dd2b680c8bf6ae29: function(arg0) {
308
+ const ret = new Uint8Array(arg0);
309
+ return ret;
310
+ },
311
+ __wbg_prototypesetcall_bdcdcc5842e4d77d: function(arg0, arg1, arg2) {
312
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
313
+ },
314
+ __wbg_set_3f1d0b984ed272ed: function(arg0, arg1, arg2) {
315
+ arg0[arg1] = arg2;
316
+ },
317
+ __wbg_set_f43e577aea94465b: function(arg0, arg1, arg2) {
318
+ arg0[arg1 >>> 0] = arg2;
319
+ },
320
+ __wbg_stack_0ed75d68575b0f3c: function(arg0, arg1) {
321
+ const ret = arg1.stack;
322
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
323
+ const len1 = WASM_VECTOR_LEN;
324
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
325
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
326
+ },
327
+ __wbindgen_cast_0000000000000001: function(arg0) {
328
+ // Cast intrinsic for `F64 -> Externref`.
329
+ const ret = arg0;
330
+ return ret;
331
+ },
332
+ __wbindgen_cast_0000000000000002: function(arg0) {
333
+ // Cast intrinsic for `I64 -> Externref`.
334
+ const ret = arg0;
335
+ return ret;
336
+ },
337
+ __wbindgen_cast_0000000000000003: function(arg0, arg1) {
338
+ // Cast intrinsic for `Ref(String) -> Externref`.
339
+ const ret = getStringFromWasm0(arg0, arg1);
340
+ return ret;
341
+ },
342
+ __wbindgen_cast_0000000000000004: function(arg0) {
343
+ // Cast intrinsic for `U64 -> Externref`.
344
+ const ret = BigInt.asUintN(64, arg0);
345
+ return ret;
346
+ },
347
+ __wbindgen_init_externref_table: function() {
348
+ const table = wasm.__wbindgen_externrefs;
349
+ const offset = table.grow(4);
350
+ table.set(0, undefined);
351
+ table.set(offset + 0, undefined);
352
+ table.set(offset + 1, null);
353
+ table.set(offset + 2, true);
354
+ table.set(offset + 3, false);
355
+ },
356
+ };
357
+ return {
358
+ __proto__: null,
359
+ "./sqlparser_rs_wasm_bg.js": import0,
360
+ };
361
+ }
362
+
363
+ function addToExternrefTable0(obj) {
364
+ const idx = wasm.__externref_table_alloc();
365
+ wasm.__wbindgen_externrefs.set(idx, obj);
366
+ return idx;
367
+ }
368
+
369
+ function debugString(val) {
370
+ // primitive types
371
+ const type = typeof val;
372
+ if (type == 'number' || type == 'boolean' || val == null) {
373
+ return `${val}`;
374
+ }
375
+ if (type == 'string') {
376
+ return `"${val}"`;
377
+ }
378
+ if (type == 'symbol') {
379
+ const description = val.description;
380
+ if (description == null) {
381
+ return 'Symbol';
382
+ } else {
383
+ return `Symbol(${description})`;
384
+ }
385
+ }
386
+ if (type == 'function') {
387
+ const name = val.name;
388
+ if (typeof name == 'string' && name.length > 0) {
389
+ return `Function(${name})`;
390
+ } else {
391
+ return 'Function';
392
+ }
393
+ }
394
+ // objects
395
+ if (Array.isArray(val)) {
396
+ const length = val.length;
397
+ let debug = '[';
398
+ if (length > 0) {
399
+ debug += debugString(val[0]);
400
+ }
401
+ for(let i = 1; i < length; i++) {
402
+ debug += ', ' + debugString(val[i]);
403
+ }
404
+ debug += ']';
405
+ return debug;
406
+ }
407
+ // Test for built-in
408
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
409
+ let className;
410
+ if (builtInMatches && builtInMatches.length > 1) {
411
+ className = builtInMatches[1];
412
+ } else {
413
+ // Failed to match the standard '[object ClassName]'
414
+ return toString.call(val);
415
+ }
416
+ if (className == 'Object') {
417
+ // we're a user defined class or Object
418
+ // JSON.stringify avoids problems with cycles, and is generally much
419
+ // easier than looping through ownProperties of `val`.
420
+ try {
421
+ return 'Object(' + JSON.stringify(val) + ')';
422
+ } catch (_) {
423
+ return 'Object';
424
+ }
425
+ }
426
+ // errors
427
+ if (val instanceof Error) {
428
+ return `${val.name}: ${val.message}\n${val.stack}`;
429
+ }
430
+ // TODO we could test for more things here, like `Set`s and `Map`s.
431
+ return className;
432
+ }
433
+
434
+ function getArrayU8FromWasm0(ptr, len) {
435
+ ptr = ptr >>> 0;
436
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
437
+ }
438
+
439
+ let cachedDataViewMemory0 = null;
440
+ function getDataViewMemory0() {
441
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
442
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
443
+ }
444
+ return cachedDataViewMemory0;
445
+ }
446
+
447
+ function getStringFromWasm0(ptr, len) {
448
+ ptr = ptr >>> 0;
449
+ return decodeText(ptr, len);
450
+ }
451
+
452
+ let cachedUint8ArrayMemory0 = null;
453
+ function getUint8ArrayMemory0() {
454
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
455
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
456
+ }
457
+ return cachedUint8ArrayMemory0;
458
+ }
459
+
460
+ function handleError(f, args) {
461
+ try {
462
+ return f.apply(this, args);
463
+ } catch (e) {
464
+ const idx = addToExternrefTable0(e);
465
+ wasm.__wbindgen_exn_store(idx);
466
+ }
467
+ }
468
+
469
+ function isLikeNone(x) {
470
+ return x === undefined || x === null;
471
+ }
472
+
473
+ function passStringToWasm0(arg, malloc, realloc) {
474
+ if (realloc === undefined) {
475
+ const buf = cachedTextEncoder.encode(arg);
476
+ const ptr = malloc(buf.length, 1) >>> 0;
477
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
478
+ WASM_VECTOR_LEN = buf.length;
479
+ return ptr;
480
+ }
481
+
482
+ let len = arg.length;
483
+ let ptr = malloc(len, 1) >>> 0;
484
+
485
+ const mem = getUint8ArrayMemory0();
486
+
487
+ let offset = 0;
488
+
489
+ for (; offset < len; offset++) {
490
+ const code = arg.charCodeAt(offset);
491
+ if (code > 0x7F) break;
492
+ mem[ptr + offset] = code;
493
+ }
494
+ if (offset !== len) {
495
+ if (offset !== 0) {
496
+ arg = arg.slice(offset);
497
+ }
498
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
499
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
500
+ const ret = cachedTextEncoder.encodeInto(arg, view);
501
+
502
+ offset += ret.written;
503
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
504
+ }
505
+
506
+ WASM_VECTOR_LEN = offset;
507
+ return ptr;
508
+ }
509
+
510
+ function takeFromExternrefTable0(idx) {
511
+ const value = wasm.__wbindgen_externrefs.get(idx);
512
+ wasm.__externref_table_dealloc(idx);
513
+ return value;
514
+ }
515
+
516
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
517
+ cachedTextDecoder.decode();
518
+ function decodeText(ptr, len) {
519
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
520
+ }
521
+
522
+ const cachedTextEncoder = new TextEncoder();
523
+
524
+ if (!('encodeInto' in cachedTextEncoder)) {
525
+ cachedTextEncoder.encodeInto = function (arg, view) {
526
+ const buf = cachedTextEncoder.encode(arg);
527
+ view.set(buf);
528
+ return {
529
+ read: arg.length,
530
+ written: buf.length
531
+ };
532
+ };
533
+ }
534
+
535
+ let WASM_VECTOR_LEN = 0;
536
+
537
+ const wasmPath = `${__dirname}/sqlparser_rs_wasm_bg.wasm`;
538
+ const wasmBytes = require('fs').readFileSync(wasmPath);
539
+ const wasmModule = new WebAssembly.Module(wasmBytes);
540
+ const wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;
541
+ wasm.__wbindgen_start();
Binary file
@@ -0,0 +1,19 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const format_sql: (a: number, b: number, c: number, d: number) => [number, number, number, number];
5
+ export const get_supported_dialects: () => any;
6
+ export const init: () => void;
7
+ export const parse_sql: (a: number, b: number, c: number, d: number) => [number, number, number];
8
+ export const parse_sql_to_json_string: (a: number, b: number, c: number, d: number) => [number, number, number, number];
9
+ export const parse_sql_to_string: (a: number, b: number, c: number, d: number) => [number, number, number, number];
10
+ export const parse_sql_with_options: (a: number, b: number, c: number, d: number, e: any) => [number, number, number];
11
+ export const validate_sql: (a: number, b: number, c: number, d: number) => [number, number, number];
12
+ export const __wbindgen_malloc: (a: number, b: number) => number;
13
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
14
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
15
+ export const __wbindgen_exn_store: (a: number) => void;
16
+ export const __externref_table_alloc: () => number;
17
+ export const __wbindgen_externrefs: WebAssembly.Table;
18
+ export const __externref_table_dealloc: (a: number) => void;
19
+ export const __wbindgen_start: () => void;