github.com/bingoohuang/gg@v0.0.0-20240325092523-45da7dee9335/pkg/sqlparse/README.md (about) 1 # sqlparse 2 3 Simply SQL and DDL parser for Go (powered by vitess and TiDB ) 4 this library inspired by https://github.com/xwb1989/sqlparser 5 6 forked from https://github.com/youtube/vitess/tree/master/go/vt/sqlparser 7 8 # Why 9 10 [xwb1989/sqlparser](https://github.com/xwb1989/sqlparser) is famous sql parser in Go. 11 But it cannot parse some query (like offset or bulk insert...) because it customizes vitess's sql parser. 12 13 Also, some libraries use from vitess sql parser directly. But vitess's sql parser only partial supports DDL parsing. 14 15 We want to perfectly support parsing for SQL and DDL. 16 Therefore we use vitess sql parser directly and also use TiDB parser for DDL parsing. 17 18 # Compare SQL parser libraries in Go 19 20 | library | supports offset (or other complexity) query | supports DDL | 21 |:---:|:---:|:---:| 22 |xwb1989/sqlparser |✗ | △| 23 |zhenjl/sqlparser | ○|△ | 24 |knocknote/sqlparser|○|○| 25 26 # Installation 27 28 ``` 29 go get github.com/bingoohuang/gg/pkg/sqlparse 30 ``` 31 32 # Examples 33 34 ```go 35 package main 36 37 import ( 38 "fmt" 39 "github.com/bingoohuang/gg/pkg/sqlparse/sqlparser" 40 ) 41 42 func main() { 43 stmt, err := sqlparser.Parse("select * from user_items where user_id=1 order by created_at limit 3 offset 10") 44 if err != nil { 45 panic(err) 46 } 47 fmt.Printf("stmt = %+v\n", stmt) 48 } 49 ```