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

  • Why Go
  • Case Studies
  • Use Cases
  • Security
  • Learn
  • Effective Go
  • Go User Manual
  • Standard library
  • Release Notes
  • API
  • Packages
  • Recorded Talks
  • Meetups
  • Conferences

This view

  • Original page
  • New address

GeezerVison is showing pkg.go.dev — teesql module - github.com/sqlc-dev/teesql - Go Packages

Details

  • checked Valid go.mod file

    The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.

  • checked Redistributable license

    Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.

  • checked Tagged version

    Modules with tagged versions give importers more predictable builds.

  • checked Stable version

    When a project reaches major version v1 it is considered stable.

  • Learn more about best practices

Repository

github.com/sqlc-dev/teesql

Links

  • Open Source Insights Logo Open Source Insights

README ¶

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

Directories ¶

Path Synopsis
ast
Package ast provides AST types for T-SQL parsing.
Package ast provides AST types for T-SQL parsing.
cmd
next-test command
parser
Package parser provides T-SQL parsing functionality.
Package parser provides T-SQL parsing functionality.
Click to show internal directories.
Click to hide internal directories.
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.