Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.14-alpine3.11 as builder
FROM golang:1.23-alpine as builder

WORKDIR /go/src/github.com/nktks/spanner-er

Expand All @@ -7,6 +7,6 @@ RUN apk add --no-cache git graphviz ttf-freefont &&\
go mod download

COPY . .
RUN go build -i -o /bin/spanner-er ./
RUN go build -o /bin/spanner-er ./

ENTRYPOINT ["/bin/spanner-er"]
54 changes: 41 additions & 13 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"os/exec"
"strings"

"cloud.google.com/go/spanner/spansql"
"github.com/cloudspannerecosystem/memefish"
"github.com/cloudspannerecosystem/memefish/ast"
"github.com/cloudspannerecosystem/memefish/token"
)

const (
Expand Down Expand Up @@ -86,19 +88,45 @@ func (cli *cli) read(file string) (string, error) {

}

func parse(sqls string) ([]*spansql.CreateTable, error) {
// spansql not allow backquote
sqls = strings.Replace(sqls, "`", "", -1)
d, err := spansql.ParseDDL("", sqls)
if err != nil {
return nil, err
}
tables := []*spansql.CreateTable{}
for _, e := range d.List {
switch v := e.(type) {
case *spansql.CreateTable:
tables = append(tables, v)
func parse(sqls string) ([]*ast.CreateTable, error) {
// Split the SQL by semicolons to get individual statements
statements := strings.Split(sqls, ";")

var tables []*ast.CreateTable
for _, stmt := range statements {
// Skip empty statements
stmt = strings.TrimSpace(stmt)
if stmt == "" {
continue
}

// Create a new Parser instance for each statement
file := &token.File{
Buffer: stmt,
}
p := &memefish.Parser{
Lexer: &memefish.Lexer{File: file},
}

// Parse the statement
parsedStmt, err := p.ParseStatement()
if err != nil {
continue
}

// If it's a CREATE TABLE statement, add it to our list
if createTable, ok := parsedStmt.(*ast.CreateTable); ok {
tables = append(tables, createTable)
}
}

return tables, nil
}

// Helper function to get the name from a CreateTable
func getTableName(t *ast.CreateTable) string {
if t.Name != nil && len(t.Name.Idents) > 0 {
return t.Name.Idents[len(t.Name.Idents)-1].Name
}
return ""
}
19 changes: 4 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
module github.com/nktks/spanner-er

go 1.14
go 1.23.0

toolchain go1.23.5

require (
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/spanner v1.42.0
github.com/awalterschulze/gographviz v0.0.0-20190522210029-fa59802746ab
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe // indirect
github.com/cncf/xds/go v0.0.0-20221128185840-c261a164b73d // indirect
github.com/envoyproxy/go-control-plane v0.10.3 // indirect
github.com/envoyproxy/protoc-gen-validate v0.9.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.1 // indirect
golang.org/x/net v0.4.0 // indirect
golang.org/x/oauth2 v0.3.0 // indirect
google.golang.org/api v0.105.0 // indirect
google.golang.org/genproto v0.0.0-20221227171554-f9683d7f8bef // indirect
github.com/cloudspannerecosystem/memefish v0.4.0
)
Loading