Skip to content

Commit e36acce

Browse files
authored
Add internal, generic AST for SQL (#456)
The AST is based on pg_query_go, but does not share structs
1 parent 4b7238e commit e36acce

File tree

288 files changed

+10249
-15
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

288 files changed

+10249
-15
lines changed

internal/compiler/compile.go

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@ package compiler
55
import (
66
"fmt"
77
"io"
8-
"os"
8+
"io/ioutil"
99
"regexp"
1010
"sort"
1111
"strings"
1212

1313
"github.com/kyleconroy/sqlc/internal/config"
1414
"github.com/kyleconroy/sqlc/internal/dinosql"
1515
"github.com/kyleconroy/sqlc/internal/dolphin"
16+
"github.com/kyleconroy/sqlc/internal/migrations"
1617
"github.com/kyleconroy/sqlc/internal/pg"
1718
"github.com/kyleconroy/sqlc/internal/postgresql"
1819
"github.com/kyleconroy/sqlc/internal/sql/ast"
1920
"github.com/kyleconroy/sqlc/internal/sql/catalog"
21+
"github.com/kyleconroy/sqlc/internal/sql/sqlpath"
2022
"github.com/kyleconroy/sqlc/internal/sqlite"
2123
)
2224

@@ -71,23 +73,29 @@ func Run(conf config.SQL, combo config.CombinedSettings) (*Result, error) {
7173
return nil, fmt.Errorf("unknown engine: %s", conf.Engine)
7274
}
7375

74-
blobs := make([]io.Reader, 0, len(conf.Schema))
75-
for _, s := range conf.Schema {
76-
b, err := os.Open(s)
77-
if err != nil {
78-
return nil, err
79-
}
80-
blobs = append(blobs, b)
81-
}
82-
rd := io.MultiReader(blobs...)
83-
84-
stmts, err := p.Parse(rd)
76+
files, err := sqlpath.Glob(conf.Schema)
8577
if err != nil {
8678
return nil, err
8779
}
8880

89-
if err := c.Build(stmts); err != nil {
90-
return nil, err
81+
for _, filename := range files {
82+
blob, err := ioutil.ReadFile(filename)
83+
if err != nil {
84+
// merr.Add(filename, "", 0, err)
85+
return nil, err
86+
}
87+
contents := migrations.RemoveRollbackStatements(string(blob))
88+
stmts, err := p.Parse(strings.NewReader(contents))
89+
if err != nil {
90+
// merr.Add(filename, , 0, err)
91+
return nil, err
92+
}
93+
for i := range stmts {
94+
if err := c.Update(stmts[i]); err != nil {
95+
// merr.Add(filename, contents, location(stmt), err)
96+
return nil, err
97+
}
98+
}
9199
}
92100

93101
var structs []dinosql.GoStruct

0 commit comments

Comments
 (0)