The Wayback Machine - https://web.archive.org/web/20200906062758/https://github.com/CovenantSQL/sqlparser/
Skip to content
master
Go to file
Code
This branch is 32 commits ahead of xwb1989:master.

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time

README.md

sqlparser Report card GoDoc

Go package for parsing SQLite or SQL-92 queries.

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

Topics

Resources

License

Releases

No releases published

Packages

No packages published
You can’t perform that action at this time.