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
+26-9Lines changed: 26 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,45 +21,62 @@ go get github.com/ajitpratap0/GoSQLX
21
21
22
22
## Usage
23
23
24
+
Below is an example of how to use GoSQLX in your Go application. This demonstrates the basic workflow of tokenizing SQL, parsing it into an AST, and properly managing resources with the object pools.
25
+
24
26
```go
27
+
// Example usage of GoSQLX
25
28
package main
26
29
27
30
import (
31
+
"fmt"
32
+
33
+
// Import the required GoSQLX packages
28
34
"github.com/ajitpratap0/GoSQLX/pkg/sql/ast"
29
35
"github.com/ajitpratap0/GoSQLX/pkg/sql/parser"
30
36
"github.com/ajitpratap0/GoSQLX/pkg/sql/tokenizer"
37
+
"github.com/ajitpratap0/GoSQLX/pkg/sql/token"
38
+
"github.com/ajitpratap0/GoSQLX/pkg/sql/models"
31
39
)
32
40
33
41
funcmain() {
34
-
// Get a tokenizer from the pool
42
+
//1. Get a tokenizer from the pool
35
43
tkz:= tokenizer.GetTokenizer()
36
44
defer tokenizer.PutTokenizer(tkz) // Return to pool when done
37
45
38
-
// Tokenize the SQL query
46
+
//2. Tokenize the SQL query
39
47
sql:= []byte("SELECT id, name FROM users WHERE age > 18")
40
48
tokens, err:= tkz.Tokenize(sql)
41
49
if err != nil {
42
50
panic(err)
43
51
}
52
+
fmt.Printf("Tokenized SQL into %d tokens\n", len(tokens))
44
53
45
-
// Create a parser
54
+
// 3. Convert TokenWithSpan to token.Token for the parser
0 commit comments