@@ -10,6 +10,15 @@ import (
1010 "github.com/swuecho/sqlc-fs/internal/sdk"
1111)
1212
13+ func jsonb2Str (s string ) string {
14+ if s == "jsonb" {
15+ return "string"
16+ } else {
17+ return s
18+ }
19+
20+ }
21+
1322func buildStructs (req * plugin.CodeGenRequest ) []Struct {
1423 var structs []Struct
1524 for _ , schema := range req .Catalog .Schemas {
@@ -24,7 +33,7 @@ func buildStructs(req *plugin.CodeGenRequest) []Struct {
2433 for _ , column := range table .Columns {
2534 s .Fields = append (s .Fields , Field {
2635 Name : FieldName (column .Name , req .Settings ),
27- Type : fsType (req , column ),
36+ Type : jsonb2Str ( fsType (req , column ) ),
2837 Comment : column .Comment ,
2938 })
3039 }
@@ -46,11 +55,9 @@ func npgsqlQuery(q *plugin.Query) string {
4655 return sql
4756}
4857
49-
50-
5158func buildQueries (req * plugin.CodeGenRequest , structs []Struct ) ([]Query , error ) {
5259 qs := make ([]Query , 0 , len (req .Queries ))
53-
60+
5461 for _ , query := range req .Queries {
5562 if query .Name == "" {
5663 continue
@@ -76,7 +83,7 @@ func buildQueries(req *plugin.CodeGenRequest, structs []Struct) ([]Query, error)
7683 p := query .Params [0 ]
7784 gq .Arg = QueryValue {
7885 Name : paramName (p ),
79- Typ : fsType (req , p .Column ),
86+ Typ : jsonb2Str ( fsType (req , p .Column ) ),
8087 }
8188 } else if len (query .Params ) > 1 {
8289 var cols []column
@@ -121,7 +128,7 @@ func buildQueries(req *plugin.CodeGenRequest, structs []Struct) ([]Query, error)
121128 }
122129 gq .Ret = QueryValue {
123130 Name : name ,
124- Typ : fsType (req , c ),
131+ Typ : jsonb2Str ( fsType (req , c ) ),
125132 }
126133 } else if len (query .Columns ) > 1 {
127134 var gs * Struct
@@ -135,7 +142,7 @@ func buildQueries(req *plugin.CodeGenRequest, structs []Struct) ([]Query, error)
135142 for i , f := range s .Fields {
136143 c := query .Columns [i ]
137144 sameName := f .Name == columnName (c , i )
138- sameType := f .Type == fsType (req , c )
145+ sameType := f .Type == jsonb2Str ( fsType (req , c ) )
139146 sameTable := sdk .SameTableName (c .Table , & s .Table , req .Catalog .DefaultSchema )
140147 if ! sameName || ! sameType || ! sameTable {
141148 same = false
@@ -229,9 +236,9 @@ func columnsToStruct(req *plugin.CodeGenRequest, name string, columns []column,
229236 fieldName = fmt .Sprintf ("%s_%d" , fieldName , suffix )
230237 }
231238 gs .Fields = append (gs .Fields , Field {
232- Name : fieldName ,
233- DBName : colName ,
234- Type : fsType (req , c .Column ),
239+ Name : fieldName ,
240+ DBName : colName ,
241+ Type : fsType (req , c .Column ),
235242 })
236243 if _ , found := seen [baseFieldName ]; ! found {
237244 seen [baseFieldName ] = []int {i }
0 commit comments