Skip to content
simply SQL Parser for Go ( powered by vitess and TiDB )
Branch: develop
Clone or download
Latest commit 1003c43 Nov 20, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bytes2 ports from vitess/go/vt/sqlparser Aug 9, 2017
hack ports from vitess/go/vt/sqlparser Aug 9, 2017
sqlparser
sqltypes remove dependency of query.pb.go Nov 1, 2017
tidbparser remove unused code Mar 12, 2018
vendor delete github.com/cznic/mathutil from vendor Mar 12, 2018
.gitignore update glide.lock Mar 10, 2018
LICENSE
README.md
glide.lock update glide.yaml (remove github.com/cznic/mathutil) Mar 12, 2018
glide.yaml update glide.yaml (remove github.com/cznic/mathutil) Mar 12, 2018

README.md

vitess-sqlparser

Simply SQL and DDL parser for Go (powered by vitess and TiDB ) this library inspired by https://github.com/xwb1989/sqlparser

(original source : https://github.com/youtube/vitess/tree/master/go/vt/sqlparser)

Why

xwb1989/sqlparser is famous sql parser in Go.
But it cannot parse some query (like offset or bulk insert...) because it customizes vitess's sql parser.

Also, some libraries use from vitess sql parser directly. But vitess's sql parser only partial supports DDL parsing.

We want to perfectly support parsing for SQL and DDL.
Therefore we use vitess sql parser directly and also use TiDB parser for DDL parsing.

Compare SQL parser libraries in Go

library supports offset (or other complexity) query supports DDL
xwb1989/sqlparser
zhenjl/sqlparser
knocknote/vitess-sqlparser

Installation

[NOTE] Required Go version more than 1.9

go get -u github.com/knocknote/vitess-sqlparser

Examples

package main

import (
 	"fmt"
	"github.com/knocknote/vitess-sqlparser/sqlparser"
)

func main() {
	stmt, err := sqlparser.Parse("select * from user_items where user_id=1 order by created_at limit 3 offset 10")
	if err != nil {
		panic(err)
	}
	fmt.Printf("stmt = %+v\n", stmt)
}
You can’t perform that action at this time.
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.