@@ -10,7 +10,6 @@ import (
1010
1111 "github.com/kyleconroy/sqlc/internal/codegen"
1212 "github.com/kyleconroy/sqlc/internal/config"
13- "github.com/kyleconroy/sqlc/internal/core"
1413 "github.com/kyleconroy/sqlc/internal/inflection"
1514 "github.com/kyleconroy/sqlc/internal/metadata"
1615 "github.com/kyleconroy/sqlc/internal/plugin"
@@ -55,7 +54,7 @@ type Field struct {
5554}
5655
5756type Struct struct {
58- Table core. FQN
57+ Table plugin. Identifier
5958 Name string
6059 Fields []Field
6160 Comment string
@@ -202,8 +201,8 @@ func pyInnerType(req *plugin.CodeGenRequest, col *plugin.Column) string {
202201 }
203202 }
204203
205- switch config . Engine ( req .Settings .Engine ) {
206- case config . EnginePostgreSQL :
204+ switch req .Settings .Engine {
205+ case "postgresql" :
207206 return postgresType (req , col )
208207 default :
209208 log .Println ("unsupported engine type" )
@@ -334,7 +333,7 @@ func buildModels(req *plugin.CodeGenRequest) []Struct {
334333 structName = inflection .Singular (structName )
335334 }
336335 s := Struct {
337- Table : core. FQN {Schema : schema .Name , Rel : table .Rel .Name },
336+ Table : plugin. Identifier {Schema : schema .Name , Name : table .Rel .Name },
338337 Name : modelName (structName , req .Settings ),
339338 Comment : table .Comment ,
340339 }
@@ -405,24 +404,24 @@ func columnsToStruct(req *plugin.CodeGenRequest, name string, columns []pyColumn
405404 return & gs
406405}
407406
408- func sameTableName (tableID * plugin. Identifier , f core. FQN , defaultSchema string ) bool {
407+ func sameTableName (tableID , f * plugin. Identifier , defaultSchema string ) bool {
409408 if tableID == nil {
410409 return false
411410 }
412411 schema := tableID .Schema
413412 if tableID .Schema == "" {
414413 schema = defaultSchema
415414 }
416- return tableID .Catalog == f .Catalog && schema == f .Schema && tableID .Name == f .Rel
415+ return tableID .Catalog == f .Catalog && schema == f .Schema && tableID .Name == f .Name
417416}
418417
419418var postgresPlaceholderRegexp = regexp .MustCompile (`\B\$(\d+)\b` )
420419
421420// Sqlalchemy uses ":name" for placeholders, so "$N" is converted to ":pN"
422421// This also means ":" has special meaning to sqlalchemy, so it must be escaped.
423- func sqlalchemySQL (s string , engine config. Engine ) string {
422+ func sqlalchemySQL (s , engine string ) string {
424423 s = strings .ReplaceAll (s , ":" , `\\:` )
425- if engine == config . EnginePostgreSQL {
424+ if engine == "postgresql" {
426425 return postgresPlaceholderRegexp .ReplaceAllString (s , ":p$1" )
427426 }
428427 return s
@@ -449,7 +448,7 @@ func buildQueries(req *plugin.CodeGenRequest, structs []Struct) ([]Query, error)
449448 MethodName : methodName ,
450449 FieldName : codegen .LowerTitle (query .Name ) + "Stmt" ,
451450 ConstantName : strings .ToUpper (methodName ),
452- SQL : sqlalchemySQL (query .Text , config . Engine ( req .Settings .Engine ) ),
451+ SQL : sqlalchemySQL (query .Text , req .Settings .Engine ),
453452 SourceName : query .Filename ,
454453 }
455454
@@ -500,7 +499,7 @@ func buildQueries(req *plugin.CodeGenRequest, structs []Struct) ([]Query, error)
500499 trimmedPyType .InnerType = strings .TrimPrefix (trimmedPyType .InnerType , "models." )
501500 sameName := f .Name == columnName (c , i )
502501 sameType := f .Type == trimmedPyType
503- sameTable := sameTableName (c .Table , s .Table , req .Catalog .DefaultSchema )
502+ sameTable := sameTableName (c .Table , & s .Table , req .Catalog .DefaultSchema )
504503 if ! sameName || ! sameType || ! sameTable {
505504 same = false
506505 }
0 commit comments