@@ -13,6 +13,7 @@ import (
13
13
"unicode"
14
14
15
15
"github.com/kyleconroy/sqlc/internal/catalog"
16
+ "github.com/kyleconroy/sqlc/internal/config"
16
17
core "github.com/kyleconroy/sqlc/internal/pg"
17
18
18
19
"github.com/jinzhu/inflection"
@@ -159,12 +160,12 @@ type GoQuery struct {
159
160
}
160
161
161
162
type Generateable interface {
162
- Structs (settings CombinedSettings ) []GoStruct
163
- GoQueries (settings CombinedSettings ) []GoQuery
164
- Enums (settings CombinedSettings ) []GoEnum
163
+ Structs (settings config. CombinedSettings ) []GoStruct
164
+ GoQueries (settings config. CombinedSettings ) []GoQuery
165
+ Enums (settings config. CombinedSettings ) []GoEnum
165
166
}
166
167
167
- func UsesType (r Generateable , typ string , settings CombinedSettings ) bool {
168
+ func UsesType (r Generateable , typ string , settings config. CombinedSettings ) bool {
168
169
for _ , strct := range r .Structs (settings ) {
169
170
for _ , f := range strct .Fields {
170
171
fType := strings .TrimPrefix (f .Type , "[]" )
@@ -176,7 +177,7 @@ func UsesType(r Generateable, typ string, settings CombinedSettings) bool {
176
177
return false
177
178
}
178
179
179
- func UsesArrays (r Generateable , settings CombinedSettings ) bool {
180
+ func UsesArrays (r Generateable , settings config. CombinedSettings ) bool {
180
181
for _ , strct := range r .Structs (settings ) {
181
182
for _ , f := range strct .Fields {
182
183
if strings .HasPrefix (f .Type , "[]" ) {
@@ -187,7 +188,7 @@ func UsesArrays(r Generateable, settings CombinedSettings) bool {
187
188
return false
188
189
}
189
190
190
- func Imports (r Generateable , settings CombinedSettings ) func (string ) [][]string {
191
+ func Imports (r Generateable , settings config. CombinedSettings ) func (string ) [][]string {
191
192
return func (filename string ) [][]string {
192
193
if filename == "db.go" {
193
194
imps := []string {"context" , "database/sql" }
@@ -209,7 +210,7 @@ func Imports(r Generateable, settings CombinedSettings) func(string) [][]string
209
210
}
210
211
}
211
212
212
- func InterfaceImports (r Generateable , settings CombinedSettings ) [][]string {
213
+ func InterfaceImports (r Generateable , settings config. CombinedSettings ) [][]string {
213
214
gq := r .GoQueries (settings )
214
215
uses := func (name string ) bool {
215
216
for _ , q := range gq {
@@ -246,10 +247,10 @@ func InterfaceImports(r Generateable, settings CombinedSettings) [][]string {
246
247
pkg := make (map [string ]struct {})
247
248
overrideTypes := map [string ]string {}
248
249
for _ , o := range settings .Overrides {
249
- if o .goBasicType {
250
+ if o .GoBasicType {
250
251
continue
251
252
}
252
- overrideTypes [o .GoTypeName ] = o .goPackage
253
+ overrideTypes [o .GoTypeName ] = o .GoPackage
253
254
}
254
255
255
256
_ , overrideNullTime := overrideTypes ["pq.NullTime" ]
@@ -283,7 +284,7 @@ func InterfaceImports(r Generateable, settings CombinedSettings) [][]string {
283
284
return [][]string {stds , pkgs }
284
285
}
285
286
286
- func ModelImports (r Generateable , settings CombinedSettings ) [][]string {
287
+ func ModelImports (r Generateable , settings config. CombinedSettings ) [][]string {
287
288
std := make (map [string ]struct {})
288
289
if UsesType (r , "sql.Null" , settings ) {
289
290
std ["database/sql" ] = struct {}{}
@@ -302,10 +303,10 @@ func ModelImports(r Generateable, settings CombinedSettings) [][]string {
302
303
pkg := make (map [string ]struct {})
303
304
overrideTypes := map [string ]string {}
304
305
for _ , o := range settings .Overrides {
305
- if o .goBasicType {
306
+ if o .GoBasicType {
306
307
continue
307
308
}
308
- overrideTypes [o .GoTypeName ] = o .goPackage
309
+ overrideTypes [o .GoTypeName ] = o .GoPackage
309
310
}
310
311
311
312
_ , overrideNullTime := overrideTypes ["pq.NullTime" ]
@@ -339,7 +340,7 @@ func ModelImports(r Generateable, settings CombinedSettings) [][]string {
339
340
return [][]string {stds , pkgs }
340
341
}
341
342
342
- func QueryImports (r Generateable , settings CombinedSettings , filename string ) [][]string {
343
+ func QueryImports (r Generateable , settings config. CombinedSettings , filename string ) [][]string {
343
344
// for _, strct := range r.Structs() {
344
345
// for _, f := range strct.Fields {
345
346
// if strings.HasPrefix(f.Type, "[]") {
@@ -437,10 +438,10 @@ func QueryImports(r Generateable, settings CombinedSettings, filename string) []
437
438
pkg := make (map [string ]struct {})
438
439
overrideTypes := map [string ]string {}
439
440
for _ , o := range settings .Overrides {
440
- if o .goBasicType {
441
+ if o .GoBasicType {
441
442
continue
442
443
}
443
- overrideTypes [o .GoTypeName ] = o .goPackage
444
+ overrideTypes [o .GoTypeName ] = o .GoPackage
444
445
}
445
446
446
447
if sliceScan () {
@@ -489,7 +490,7 @@ func enumValueName(value string) string {
489
490
return name
490
491
}
491
492
492
- func (r Result ) Enums (settings CombinedSettings ) []GoEnum {
493
+ func (r Result ) Enums (settings config. CombinedSettings ) []GoEnum {
493
494
var enums []GoEnum
494
495
for name , schema := range r .Catalog .Schemas {
495
496
if name == "pg_catalog" {
@@ -522,7 +523,7 @@ func (r Result) Enums(settings CombinedSettings) []GoEnum {
522
523
return enums
523
524
}
524
525
525
- func StructName (name string , settings CombinedSettings ) string {
526
+ func StructName (name string , settings config. CombinedSettings ) string {
526
527
if rename := settings .Global .Rename [name ]; rename != "" {
527
528
return rename
528
529
}
@@ -537,7 +538,7 @@ func StructName(name string, settings CombinedSettings) string {
537
538
return out
538
539
}
539
540
540
- func (r Result ) Structs (settings CombinedSettings ) []GoStruct {
541
+ func (r Result ) Structs (settings config. CombinedSettings ) []GoStruct {
541
542
var structs []GoStruct
542
543
for name , schema := range r .Catalog .Schemas {
543
544
if name == "pg_catalog" {
@@ -572,7 +573,7 @@ func (r Result) Structs(settings CombinedSettings) []GoStruct {
572
573
return structs
573
574
}
574
575
575
- func (r Result ) goType (col core.Column , settings CombinedSettings ) string {
576
+ func (r Result ) goType (col core.Column , settings config. CombinedSettings ) string {
576
577
// package overrides have a higher precedence
577
578
for _ , oride := range settings .Overrides {
578
579
if oride .Column != "" && oride .ColumnName == col .Name && oride .Table == col .Table {
@@ -586,7 +587,7 @@ func (r Result) goType(col core.Column, settings CombinedSettings) string {
586
587
return typ
587
588
}
588
589
589
- func (r Result ) goInnerType (col core.Column , settings CombinedSettings ) string {
590
+ func (r Result ) goInnerType (col core.Column , settings config. CombinedSettings ) string {
590
591
columnType := col .DataType
591
592
notNull := col .NotNull || col .IsArray
592
593
@@ -741,7 +742,7 @@ func (r Result) goInnerType(col core.Column, settings CombinedSettings) string {
741
742
// JSON tags: count, count_2, count_2
742
743
//
743
744
// This is unlikely to happen, so don't fix it yet
744
- func (r Result ) columnsToStruct (name string , columns []core.Column , settings CombinedSettings ) * GoStruct {
745
+ func (r Result ) columnsToStruct (name string , columns []core.Column , settings config. CombinedSettings ) * GoStruct {
745
746
gs := GoStruct {
746
747
Name : name ,
747
748
}
@@ -801,7 +802,7 @@ func compareFQN(a *core.FQN, b *core.FQN) bool {
801
802
return a .Catalog == b .Catalog && a .Schema == b .Schema && a .Rel == b .Rel
802
803
}
803
804
804
- func (r Result ) GoQueries (settings CombinedSettings ) []GoQuery {
805
+ func (r Result ) GoQueries (settings config. CombinedSettings ) []GoQuery {
805
806
structs := r .Structs (settings )
806
807
807
808
qs := make ([]GoQuery , 0 , len (r .Queries ))
@@ -1182,7 +1183,7 @@ type tmplCtx struct {
1182
1183
Enums []GoEnum
1183
1184
Structs []GoStruct
1184
1185
GoQueries []GoQuery
1185
- Settings GenerateSettings
1186
+ Settings config. GenerateSettings
1186
1187
1187
1188
// TODO: Race conditions
1188
1189
SourceName string
@@ -1198,7 +1199,7 @@ func LowerTitle(s string) string {
1198
1199
return string (a )
1199
1200
}
1200
1201
1201
- func Generate (r Generateable , settings CombinedSettings ) (map [string ]string , error ) {
1202
+ func Generate (r Generateable , settings config. CombinedSettings ) (map [string ]string , error ) {
1202
1203
funcMap := template.FuncMap {
1203
1204
"lowerTitle" : LowerTitle ,
1204
1205
"imports" : Imports (r , settings ),
0 commit comments