← Winnitude! Search  ·  Reader Mode (1009 ms)
Links: Stay in Reader Retro Site Converter Retro Mode: OFF Original Page ↗
GITHUB · 92 LINKS

GitHub - CovenantSQL/sqlparser: SQLite or SQL-92 Parser implemented in Go

Repository navigation

sqlparser
Public
forked from xwb1989/sqlparser

About

SQLite or SQL-92 Parser implemented in Go

Topics

sql-92 sql-parser sqlite3

Resources

Readme Apache-2.0 license Activity Custom properties

Stars

18 stars

Watchers

1 watching

Forks

2 forks Report repository
Branches

Tags
Go to Branches page Go to Tags page    

Latest commit

 

History


224 Commits
View commit history for this file.

Folders and files

Name Name Last commit message Last commit date
.github/ workflows .github/ workflows    
dependency dependency    
.gitignore .gitignore    
CONTRIBUTORS.md CONTRIBUTORS.md    
LICENSE.md LICENSE.md    
Makefile Makefile    
README.md README.md    
analyzer.go analyzer.go    
analyzer_test.go analyzer_test.go    
ast.go ast.go    
ast_test.go ast_test.go    
comments.go comments.go    
comments_test.go comments_test.go    
encodable.go encodable.go    
encodable_test.go encodable_test.go    
go.mod go.mod    
impossible_query.go impossible_query.go    
normalizer.go normalizer.go    
normalizer_test.go normalizer_test.go    
parse_next_test.go parse_next_test.go    
parse_test.go parse_test.go    
parsed_query.go parsed_query.go    
parsed_query_test.go parsed_query_test.go    
precedence_test.go precedence_test.go    
redact_query.go redact_query.go    
redact_query_test.go redact_query_test.go    
sql.go sql.go    
sql.y sql.y    
token.go token.go    
token_test.go token_test.go    
tracked_buffer.go tracked_buffer.go    

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

Topics

sql-92 sql-parser sqlite3

Resources

Readme Apache-2.0 license Activity Custom properties

Stars

18 stars

Watchers

1 watching

Forks

2 forks Report repository

Releases

Packages

Contributors

Languages