From e0175b2d56feae3238c05ad86c343895e89aef87 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 22 Dec 2025 23:23:45 +0000 Subject: [PATCH 1/3] Add README with usage example Document the teesql T-SQL parser with installation instructions and a complete code example showing parsing and JSON output. --- README.md | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..f9c87a9f --- /dev/null +++ b/README.md @@ -0,0 +1,76 @@ +# teesql + +A T-SQL parser for Go that produces JSON AST output compatible with Microsoft's SqlScriptDOM. + +## Installation + +```bash +go get github.com/kyleconroy/teesql +``` + +## Usage + +```go +package main + +import ( + "context" + "fmt" + "strings" + + "github.com/kyleconroy/teesql/parser" +) + +func main() { + sql := "SELECT id, name FROM users WHERE active = 1" + + script, err := parser.Parse(context.Background(), strings.NewReader(sql)) + if err != nil { + panic(err) + } + + json, err := parser.MarshalScript(script) + if err != nil { + panic(err) + } + + fmt.Println(string(json)) +} +``` + +Output: + +```json +{ + "Batches": [ + { + "Statements": [ + { + "QueryExpression": { + "SelectElements": [ + {"ColumnType": 2, "Identifier": {"Value": "id"}}, + {"ColumnType": 2, "Identifier": {"Value": "name"}} + ], + "FromClause": { + "TableReferences": [ + {"SchemaObject": {"BaseIdentifier": {"Value": "users"}}} + ] + }, + "WhereClause": { + "SearchCondition": { + "FirstExpression": {"ColumnType": 2, "Identifier": {"Value": "active"}}, + "ComparisonType": 0, + "SecondExpression": {"Value": "1"} + } + } + } + } + ] + } + ] +} +``` + +## License + +MIT From 9b1219a0817307c9eba09a04c9360e9f972fc08d Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 22 Dec 2025 23:30:36 +0000 Subject: [PATCH 2/3] Fix README: add SqlScriptDOM link and correct org name --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f9c87a9f..aa89b003 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ # teesql -A T-SQL parser for Go that produces JSON AST output compatible with Microsoft's SqlScriptDOM. +A T-SQL parser for Go that produces JSON AST output compatible with Microsoft's [SqlScriptDOM](https://learn.microsoft.com/en-us/dotnet/api/microsoft.sqlserver.transactsql.scriptdom). ## Installation ```bash -go get github.com/kyleconroy/teesql +go get github.com/sqlc-dev/teesql ``` ## Usage @@ -18,7 +18,7 @@ import ( "fmt" "strings" - "github.com/kyleconroy/teesql/parser" + "github.com/sqlc-dev/teesql/parser" ) func main() { From 380afba65728df04be09974288e946a600327495 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 22 Dec 2025 23:32:16 +0000 Subject: [PATCH 3/3] Add encoding/json example, remove license section --- README.md | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aa89b003..4e3e9f20 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,35 @@ Output: } ``` -## License +## Using encoding/json -MIT +You can also use the standard library directly: + +```go +package main + +import ( + "context" + "encoding/json" + "fmt" + "strings" + + "github.com/sqlc-dev/teesql/parser" +) + +func main() { + sql := "SELECT 1" + + script, err := parser.Parse(context.Background(), strings.NewReader(sql)) + if err != nil { + panic(err) + } + + out, err := json.MarshalIndent(script, "", " ") + if err != nil { + panic(err) + } + + fmt.Println(string(out)) +} +```