File tree Expand file tree Collapse file tree 1 file changed +76
-0
lines changed
Expand file tree Collapse file tree 1 file changed +76
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments