https://github.com/tablelandnetwork/go-sqlparser
This is a Go library for parsing a Tableland SQL statement.
https://github.com/tablelandnetwork/go-sqlparser
sql tableland
Last synced: 12 months ago
JSON representation
This is a Go library for parsing a Tableland SQL statement.
- Host: GitHub
- URL: https://github.com/tablelandnetwork/go-sqlparser
- Owner: tablelandnetwork
- License: mit
- Created: 2022-06-08T22:02:22.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-01-14T06:20:09.000Z (about 1 year ago)
- Last Synced: 2025-03-25T17:03:25.581Z (about 1 year ago)
- Topics: sql, tableland
- Language: HTML
- Homepage: https://tableland.xyz/
- Size: 12.4 MB
- Stars: 9
- Watchers: 6
- Forks: 3
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Tableland SQL Parser
[](https://github.com/tablelandnetwork/sqlparser/actions/workflows/review.yml)
[](https://github.com/tablelandnetwork/sqlparser/actions/workflows/test.yml)
[](https://github.com/tablelandnetwork/sqlparser/releases/latest)
[](https://github.com/RichardLitt/standard-readme)
> Go library for parsing Tableland-compliant SQL
# Table of Contents
- [Tableland SQL Parser](#tableland-sql-parser)
- [Table of Contents](#table-of-contents)
- [Background](#background)
- [Usage](#usage)
- [Feedback](#feedback)
- [Contributing](#contributing)
- [License](#license)
# Background
This is a Go library for parsing a Tableland SQL statement as defined by [Tableland SQL Specification](https://textile.notion.site/Tableland-SQL-Specification-9493b88eac8b4dd9ad5dc76323f7f087).
It uses `goyacc` to generate a parser based on a given [grammar](./grammar.y) and a given [lexer](lexer.go).
With the parser, you can generate an AST from a SQL statement.
This is inspired on the [xwb1989/sqlparser](https://github.com/xwb1989/sqlparser), with eyes on SQLite's [grammar](https://repo.or.cz/sqlite.git/blob/HEAD:/src/parse.y) and [spec](https://www.sqlite.org/lang.html).
## Usage
```go
ast, err := sqlparser.Parse("SELECT * FROM table WHERE c1 > c2")
if err != nil {
panic(err)
}
ast.PrettyPrint()
```
Resulting AST:
```bash
(*sqlparser.AST)({
Root: (*sqlparser.Select)({
SelectColumnList: (sqlparser.SelectColumnList) (len=1 cap=1) {
(*sqlparser.StarSelectColumn)({
TableRef: (*sqlparser.Table)()
})
},
From: (*sqlparser.Table)({
Name: (string) (len=5) "table"
}),
Where: (*sqlparser.Where)({
Type: (string) (len=5) "where",
Expr: (*sqlparser.CmpExpr)({
Operator: (string) (len=1) ">",
Left: (*sqlparser.Column)({
Name: (string) (len=2) "c1",
TableRef: (*sqlparser.Table)()
}),
Right: (*sqlparser.Column)({
Name: (string) (len=2) "c2",
TableRef: (*sqlparser.Table)()
}),
Escape: (sqlparser.Expr)
})
})
})
})
```
# Contributing
To get started clone this repo.
## Generating the parser
```bash
go run golang.org/x/tools/cmd/goyacc@master -l -o yy_parser.go grammar.y
```
## Generating syntax diagrams
```bash
make generate-diagrams
```
Requires Java 8 (or higher).
# Feedback
Reach out with feedback and ideas:
- [twitter.com/tableland\_\_](https://twitter.com/tableland__)
- [Create a new issue](https://github.com/tablelandnetwork/sqlparser/issues)
# License
MIT AND Apache-2.0, © 2021-2022 Tableland Network Contributors