GitHub - CovenantSQL/sqlparser: SQLite or SQL-92 Parser implemented in Go
Repository navigation
sqlparserPublic
forked from xwb1989/sqlparser
About
SQLite or SQL-92 Parser implemented in Go
Topics
sql-92 sql-parser sqlite3Resources
Readme Apache-2.0 license Activity Custom propertiesStars
18 starsWatchers
1 watchingForks
2 forks Report repositoryBranches
Tags
Go to Branches page Go to Tags page
Latest commit
History
224 Commits
View commit history for this file.
Folders and files
Repository files navigation
sqlparser
Go package for parsing SQLite or SQL-92 queries.
The module builds with Go 1.11 and later. Regenerating sql.go with
make -B sql.go requires Go 1.17 or later for versioned go run support.
The Makefile pins the generator that reproduces the committed parser byte
for byte.
Notice
The backbone of this repo is extracted from vitessio/vitess .
Inside vitessio/vitess there is a very nicely written sql parser. However as it's not a self-contained application, I created this one. It applies the same LICENSE as vitessio/vitess.
Usage
import (
"github.com/CovenantSQL/sqlparser"
)
Then use:
sql := "SELECT * FROM table WHERE a = 'abc'"
stmt, err := sqlparser.Parse(sql)
if err != nil {
// Do something with the err
}
// Otherwise do something with stmt
switch stmt := stmt.(type) {
case *sqlparser.Select:
_ = stmt
case *sqlparser.Insert:
}
Alternative to read many queries from a io.Reader:
r := strings.NewReader("INSERT INTO table1 VALUES (1, 'a'); INSERT INTO table2 VALUES (3, 4);")
tokens := sqlparser.NewTokenizer(r)
for {
stmt, err := sqlparser.ParseNext(tokens)
if err == io.EOF {
break
}
// Do something with stmt or err.
}
About
SQLite or SQL-92 Parser implemented in Go