You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+16-28Lines changed: 16 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ English | [简体中文](./README-zh_CN.md)
15
15
16
16
dt-sql-parser is a **SQL Parser** project built with [ANTLR4](https://github.com/antlr/antlr4), and it's mainly for the **BigData** domain. The [ANTLR4](https://github.com/antlr/antlr4) generated the basic Parser, Visitor, and Listener, so it's easy to complete the **syntax validation**, **tokenizer**, **traverse** the AST, and so on features.
17
17
18
-
Besides, it provides some helper methods, like **split**SQL, and **Auto-Complete**.
18
+
Additionally, it provides auxiliary functions such as SQL splitting and Auto-Complete.
19
19
20
20
**Supported SQL**:
21
21
@@ -27,7 +27,7 @@ Besides, it provides some helper methods, like **split** SQL, and **Auto-Complet
27
27
- PostgreSQL
28
28
- Trino SQL
29
29
30
-
**Supported helper methods**
30
+
**Supported auxiliary methods**
31
31
32
32
| SQL Type | SQL Split | Auto-Complete |
33
33
| ----------- | -------- | -------- |
@@ -63,19 +63,18 @@ yarn add dt-sql-parser
63
63
<br/>
64
64
65
65
## Usage
66
-
Before you get started, you need to understand the basics of how to use it. `dt-sql-parser`provides SQL parser classes for different types of supported SQL:
66
+
We recommend learning the Fundamentals usage before continuing. The dt-sql-parser library provides SQL Parser classes for different types of SQL.
Before using syntax validation, autocompletion, and other method, you need to instantiate the Parser of the corresponding SQL type, taking `GenericSQL` as an example:
71
+
Before employing syntax validation, code completion, and other features, it is necessary to instantiate the Parser of the relevant SQL type.
72
+
For instance, one can consider using `GenericSQL` as an example:
72
73
```javascript
73
74
constparser=newGenericSQL();
74
75
```
75
76
76
-
The usage examples below will use `GenericSQL`, and Parser for other SQL types will be used in the same way as `GenericSQL`.
77
-
78
-
<br/>
77
+
The following usage examples will utilize the `GenericSQL`, and the Parser for other SQL types will be employed in a similar manner as `GenericSQL`.
79
78
80
79
### Syntax Validation
81
80
```javascript
@@ -123,8 +122,6 @@ Output:
123
122
We instanced a Parser object, and use the **validate** method to check the SQL syntax, if failed
124
123
returns an array object includes **error** message.
125
124
126
-
<br/>
127
-
128
125
### Tokenizer
129
126
130
127
Get all **tokens** by the Parser:
@@ -154,8 +151,6 @@ console.log(tokens)
154
151
*/
155
152
```
156
153
157
-
<br/>
158
-
159
154
### Visitor
160
155
161
156
Traverse the tree node by the Visitor:
@@ -192,8 +187,6 @@ TableName user1
192
187
193
188
> Tips: The node's method name can be found in the Visitor file under the corresponding SQL directory
194
189
195
-
<br/>
196
-
197
190
### Listener
198
191
199
192
Access the specified node in the AST by the Listener
@@ -228,9 +221,7 @@ TableName user1
228
221
229
222
> Tips: The node's method name can be found in the Listener file under the corresponding SQL directory
230
223
231
-
<br/>
232
-
233
-
### Split sql by statement
224
+
### Splitting SQL statements
234
225
Take `FlinkSQL` as an example:
235
226
```javascript
236
227
import { FlinkSQL } from'dt-sql-parser';
@@ -264,13 +255,12 @@ console.log(sqlSlices)
264
255
265
256
```
266
257
267
-
<br/>
258
+
### Code Completion
259
+
Obtaining autocomplete information at a specified position in SQL.
260
+
We can refer to the example of using `FlinkSQL`.
268
261
269
-
### Auto Complete
270
-
Get the autocomplete information in the specified position of sql, using `FlinkSQL` as an example:
271
-
272
-
Call the `getSuggestionAtCaretPosition` method, passing in the SQL content and the row and column numbers of the position that need to be autocompleted.
273
-
+ Get a list of keyword candidates
262
+
Invoke the `getSuggestionAtCaretPosition` method, pass the SQL content and the row and column numbers indicating the position where auto-completion is desired.
263
+
+ keyword candidates list
274
264
275
265
```javascript
276
266
import { FlinkSQL } from'dt-sql-parser';
@@ -284,7 +274,7 @@ Call the `getSuggestionAtCaretPosition` method, passing in the SQL content and t
+ Obtaining information related to grammar completion
288
278
```javascript
289
279
constparser=newFlinkSQL();
290
280
constsql='SELECT * FROM tb';
@@ -323,14 +313,12 @@ Call the `getSuggestionAtCaretPosition` method, passing in the SQL content and t
323
313
]
324
314
*/
325
315
```
326
-
Syntax-related autocomplete information returns an array, and each item in the array represents what syntax can be filled in at that position, such as the output result in the above example represents that the position can be filled in **table name** or **view name**. The `syntaxContextType` is a syntax type that can be completed, and `wordRanges` is what has been filled in.
327
-
328
-
<br/>
316
+
The grammar-related autocomplete information returns an array, where each item represents what grammar can be filled in at that position. For example, the output in the above example represents that the position can be filled with either a **table name** or **a view name**. In this case, `syntaxContextType` represents the type of grammar that can be completed, and `wordRanges` represents the content that has already been filled.
329
317
330
318
### Other API
331
319
332
-
- `createLexer` Create an instance of Antlr4 Lexer and return;
333
-
- `createParser` Create an instance of Antlr4 parser and return;
320
+
- `createLexer` Create an instance of Antlr4 Lexer and return it;
321
+
- `createParser` Create an instance of Antlr4 parser and return it;
334
322
- `parse` Parses the input SQL and returns the parse tree;
0 commit comments