GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - sqlc-dev/teesql

BranchesTags
Open more actions menu

Latest commit

 

History

60 Commits
60 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
TsqlAstParser
TsqlAstParser
 
 
ast
ast
 
 
cmd/next-test
cmd/next-test
 
 
parser
parser
 
 
.gitignore
.gitignore
 
 
CLAUDE.md
CLAUDE.md
 
 
LICENSE
LICENSE
 
 
PLAN.md
PLAN.md
 
 
README.md
README.md
 
 
find_tests.sh
find_tests.sh
 
 
go.mod
go.mod
 
 

Repository files navigation

teesql

Go Reference

A T-SQL parser for Go that produces JSON AST output compatible with Microsoft's SqlScriptDOM.

Installation

go get github.com/sqlc-dev/teesql

Usage

package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/sqlc-dev/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:

{
  "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"}
              }
            }
          }
        }
      ]
    }
  ]
}

Using encoding/json

You can also use the standard library directly:

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))
}

About

No description, website, or topics provided.

Resources

Readme
MIT license
Activity
Custom properties

Stars

3 stars

Watchers

2 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.