Skip to content

Commit e0175b2

Browse files
committed
Add README with usage example
Document the teesql T-SQL parser with installation instructions and a complete code example showing parsing and JSON output.
1 parent 8fa9ff9 commit e0175b2

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# teesql
2+
3+
A T-SQL parser for Go that produces JSON AST output compatible with Microsoft's SqlScriptDOM.
4+
5+
## Installation
6+
7+
```bash
8+
go get github.com/kyleconroy/teesql
9+
```
10+
11+
## Usage
12+
13+
```go
14+
package main
15+
16+
import (
17+
"context"
18+
"fmt"
19+
"strings"
20+
21+
"github.com/kyleconroy/teesql/parser"
22+
)
23+
24+
func main() {
25+
sql := "SELECT id, name FROM users WHERE active = 1"
26+
27+
script, err := parser.Parse(context.Background(), strings.NewReader(sql))
28+
if err != nil {
29+
panic(err)
30+
}
31+
32+
json, err := parser.MarshalScript(script)
33+
if err != nil {
34+
panic(err)
35+
}
36+
37+
fmt.Println(string(json))
38+
}
39+
```
40+
41+
Output:
42+
43+
```json
44+
{
45+
"Batches": [
46+
{
47+
"Statements": [
48+
{
49+
"QueryExpression": {
50+
"SelectElements": [
51+
{"ColumnType": 2, "Identifier": {"Value": "id"}},
52+
{"ColumnType": 2, "Identifier": {"Value": "name"}}
53+
],
54+
"FromClause": {
55+
"TableReferences": [
56+
{"SchemaObject": {"BaseIdentifier": {"Value": "users"}}}
57+
]
58+
},
59+
"WhereClause": {
60+
"SearchCondition": {
61+
"FirstExpression": {"ColumnType": 2, "Identifier": {"Value": "active"}},
62+
"ComparisonType": 0,
63+
"SecondExpression": {"Value": "1"}
64+
}
65+
}
66+
}
67+
}
68+
]
69+
}
70+
]
71+
}
72+
```
73+
74+
## License
75+
76+
MIT

0 commit comments

Comments
 (0)