Skip to content

Commit 7abb3ec

Browse files
committed
A list of paths can be past in for schemas and queries
1 parent 575ddd4 commit 7abb3ec

85 files changed

Lines changed: 272 additions & 252 deletions

File tree

Some content is hidden

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

examples/authors/db_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
func TestAuthors(t *testing.T) {
14-
sdb, cleanup := sqltest.PostgreSQL(t, "schema.sql")
14+
sdb, cleanup := sqltest.PostgreSQL(t, []string{"schema.sql"})
1515
defer cleanup()
1616

1717
ctx := context.Background()

examples/authors/sqlc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"version": "2",
33
"sql": [
44
{
5-
"schema": "schema.sql",
6-
"queries": "query.sql",
5+
"schema": ["schema.sql"],
6+
"queries": ["query.sql"],
77
"engine": "postgresql",
88
"gen": {
99
"go": {

examples/booktest/postgresql/db_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
func TestBooks(t *testing.T) {
15-
db, cleanup := sqltest.PostgreSQL(t, filepath.Join("schema.sql"))
15+
db, cleanup := sqltest.PostgreSQL(t, []string{filepath.Join("schema.sql")})
1616
defer cleanup()
1717

1818
ctx := context.Background()

examples/booktest/sqlc.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
{
55
"name": "booktest",
66
"path": "postgresql",
7-
"schema": "postgresql/schema.sql",
8-
"queries": "postgresql/query.sql",
7+
"schema": ["postgresql/schema.sql"],
8+
"queries": ["postgresql/query.sql"],
99
"engine": "postgresql"
1010
},
1111
{
1212
"name": "booktest",
1313
"path": "mysql",
14-
"schema": "mysql/schema.sql",
15-
"queries": "mysql/query.sql",
14+
"schema": ["mysql/schema.sql"],
15+
"queries": ["mysql/query.sql"],
1616
"engine": "mysql"
1717
}
1818
]

examples/jets/sqlc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
{
55
"path": ".",
66
"name": "jets",
7-
"schema": "schema.sql",
8-
"queries": "query-building.sql",
7+
"schema": ["schema.sql"],
8+
"queries": ["query-building.sql"],
99
"engine": "postgresql"
1010
}
1111
]

examples/kotlin/sqlc.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"version": "2",
33
"sql": [
44
{
5-
"schema": "src/main/resources/authors/schema.sql",
6-
"queries": "src/main/resources/authors/query.sql",
5+
"schema": ["src/main/resources/authors/schema.sql"],
6+
"queries": ["src/main/resources/authors/query.sql"],
77
"engine": "postgresql",
88
"gen": {
99
"kotlin": {
@@ -13,8 +13,8 @@
1313
}
1414
},
1515
{
16-
"schema": "src/main/resources/ondeck/schema",
17-
"queries": "src/main/resources/ondeck/query",
16+
"schema": ["src/main/resources/ondeck/schema"],
17+
"queries": ["src/main/resources/ondeck/query"],
1818
"engine": "postgresql",
1919
"gen": {
2020
"kotlin": {
@@ -24,8 +24,8 @@
2424
}
2525
},
2626
{
27-
"schema": "src/main/resources/jets/schema.sql",
28-
"queries": "src/main/resources/jets/query-building.sql",
27+
"schema": ["src/main/resources/jets/schema.sql"],
28+
"queries": ["src/main/resources/jets/query-building.sql"],
2929
"engine": "postgresql",
3030
"gen": {
3131
"kotlin": {
@@ -35,8 +35,8 @@
3535
}
3636
},
3737
{
38-
"schema": "src/main/resources/booktest/postgresql/schema.sql",
39-
"queries": "src/main/resources/booktest/postgresql/query.sql",
38+
"schema": ["src/main/resources/booktest/postgresql/schema.sql"],
39+
"queries": ["src/main/resources/booktest/postgresql/query.sql"],
4040
"engine": "postgresql",
4141
"gen": {
4242
"kotlin": {

examples/ondeck/db_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func runOnDeckQueries(t *testing.T, q *Queries) {
123123
func TestPrepared(t *testing.T) {
124124
t.Parallel()
125125

126-
sdb, cleanup := sqltest.PostgreSQL(t, "schema")
126+
sdb, cleanup := sqltest.PostgreSQL(t, []string{"schema"})
127127
defer cleanup()
128128

129129
q, err := Prepare(context.Background(), sdb)
@@ -137,7 +137,7 @@ func TestPrepared(t *testing.T) {
137137
func TestQueries(t *testing.T) {
138138
t.Parallel()
139139

140-
sdb, cleanup := sqltest.PostgreSQL(t, "schema")
140+
sdb, cleanup := sqltest.PostgreSQL(t, []string{"schema"})
141141
defer cleanup()
142142

143143
runOnDeckQueries(t, New(sdb))

examples/ondeck/sqlc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
{
55
"path": ".",
66
"name": "ondeck",
7-
"schema": "schema",
8-
"queries": "query",
7+
"schema": ["schema"],
8+
"queries": ["query"],
99
"engine": "postgresql",
1010
"emit_json_tags": true,
1111
"emit_prepared_queries": true,

internal/cmd/generate.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,17 @@ func Generate(dir string, stderr io.Writer) (map[string]string, error) {
113113
var result dinosql.Generateable
114114

115115
// TODO: This feels like a hack that will bite us later
116-
sql.Schema = filepath.Join(dir, sql.Schema)
117-
sql.Queries = filepath.Join(dir, sql.Queries)
116+
joined := make([]string, 0, len(sql.Schema))
117+
for _, s := range sql.Schema {
118+
joined = append(joined, filepath.Join(dir, s))
119+
}
120+
sql.Schema = joined
121+
122+
joined = make([]string, 0, len(sql.Queries))
123+
for _, q := range sql.Queries {
124+
joined = append(joined, filepath.Join(dir, q))
125+
}
126+
sql.Queries = joined
118127

119128
var name string
120129
parseOpts := dinosql.ParserOpts{}

internal/compiler/compile.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,15 @@ func Run(conf config.SQL, combo config.CombinedSettings) (*Result, error) {
7171
return nil, fmt.Errorf("unknown engine: %s", conf.Engine)
7272
}
7373

74-
rd, err := os.Open(conf.Schema)
75-
if err != nil {
76-
return nil, err
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)
7781
}
82+
rd := io.MultiReader(blobs...)
7883

7984
stmts, err := p.Parse(rd)
8085
if err != nil {

0 commit comments

Comments
 (0)