@@ -10,8 +10,8 @@ import (
10
10
"sort"
11
11
"strings"
12
12
13
- "buf.build/gen/go/sqlc/sqlc/protocolbuffers/go/protos/plugin"
14
13
"github.com/sqlc-dev/sqlc-go/metadata"
14
+ "github.com/sqlc-dev/sqlc-go/plugin"
15
15
"github.com/sqlc-dev/sqlc-go/sdk"
16
16
17
17
pyast "github.com/sqlc-dev/sqlc-gen-python/internal/ast"
@@ -180,7 +180,7 @@ func (q Query) ArgDictNode() *pyast.Node {
180
180
}
181
181
}
182
182
183
- func makePyType (req * plugin.CodeGenRequest , col * plugin.Column ) pyType {
183
+ func makePyType (req * plugin.GenerateRequest , col * plugin.Column ) pyType {
184
184
typ := pyInnerType (req , col )
185
185
return pyType {
186
186
InnerType : typ ,
@@ -189,21 +189,7 @@ func makePyType(req *plugin.CodeGenRequest, col *plugin.Column) pyType {
189
189
}
190
190
}
191
191
192
- func pyInnerType (req * plugin.CodeGenRequest , col * plugin.Column ) string {
193
- columnType := sdk .DataType (col .Type )
194
- for _ , oride := range req .Settings .Overrides {
195
- if ! pyTypeIsSet (oride ) {
196
- continue
197
- }
198
- sameTable := sdk .Matches (oride , col .Table , req .Catalog .DefaultSchema )
199
- if oride .Column != "" && sdk .MatchString (oride .ColumnName , col .Name ) && sameTable {
200
- return oride .CodeType
201
- }
202
- if oride .DbType != "" && oride .DbType == columnType && oride .Nullable != (col .NotNull || col .IsArray ) {
203
- return oride .CodeType
204
- }
205
- }
206
-
192
+ func pyInnerType (req * plugin.GenerateRequest , col * plugin.Column ) string {
207
193
switch req .Settings .Engine {
208
194
case "postgresql" :
209
195
return postgresType (req , col )
@@ -214,9 +200,6 @@ func pyInnerType(req *plugin.CodeGenRequest, col *plugin.Column) string {
214
200
}
215
201
216
202
func modelName (name string , settings * plugin.Settings ) string {
217
- if rename := settings .Rename [name ]; rename != "" {
218
- return rename
219
- }
220
203
out := ""
221
204
for _ , p := range strings .Split (name , "_" ) {
222
205
out += strings .Title (p )
@@ -243,7 +226,7 @@ func pyEnumValueName(value string) string {
243
226
return strings .ToUpper (id )
244
227
}
245
228
246
- func buildEnums (req * plugin.CodeGenRequest ) []Enum {
229
+ func buildEnums (req * plugin.GenerateRequest ) []Enum {
247
230
var enums []Enum
248
231
for _ , schema := range req .Catalog .Schemas {
249
232
if schema .Name == "pg_catalog" || schema .Name == "information_schema" {
@@ -276,7 +259,7 @@ func buildEnums(req *plugin.CodeGenRequest) []Enum {
276
259
return enums
277
260
}
278
261
279
- func buildModels (conf Config , req * plugin.CodeGenRequest ) []Struct {
262
+ func buildModels (conf Config , req * plugin.GenerateRequest ) []Struct {
280
263
var structs []Struct
281
264
for _ , schema := range req .Catalog .Schemas {
282
265
if schema .Name == "pg_catalog" || schema .Name == "information_schema" {
@@ -338,7 +321,7 @@ type pyColumn struct {
338
321
* plugin.Column
339
322
}
340
323
341
- func columnsToStruct (req * plugin.CodeGenRequest , name string , columns []pyColumn ) * Struct {
324
+ func columnsToStruct (req * plugin.GenerateRequest , name string , columns []pyColumn ) * Struct {
342
325
gs := Struct {
343
326
Name : name ,
344
327
}
@@ -380,7 +363,7 @@ func sqlalchemySQL(s, engine string) string {
380
363
return s
381
364
}
382
365
383
- func buildQueries (conf Config , req * plugin.CodeGenRequest , structs []Struct ) ([]Query , error ) {
366
+ func buildQueries (conf Config , req * plugin.GenerateRequest , structs []Struct ) ([]Query , error ) {
384
367
qs := make ([]Query , 0 , len (req .Queries ))
385
368
for _ , query := range req .Queries {
386
369
if query .Name == "" {
@@ -1091,7 +1074,7 @@ func HashComment(s string) string {
1091
1074
return "# " + strings .ReplaceAll (s , "\n " , "\n # " )
1092
1075
}
1093
1076
1094
- func Generate (_ context.Context , req * plugin.CodeGenRequest ) (* plugin.CodeGenResponse , error ) {
1077
+ func Generate (_ context.Context , req * plugin.GenerateRequest ) (* plugin.GenerateResponse , error ) {
1095
1078
var conf Config
1096
1079
if len (req .PluginOptions ) > 0 {
1097
1080
if err := json .Unmarshal (req .PluginOptions , & conf ); err != nil {
@@ -1107,11 +1090,10 @@ func Generate(_ context.Context, req *plugin.CodeGenRequest) (*plugin.CodeGenRes
1107
1090
}
1108
1091
1109
1092
i := & importer {
1110
- Settings : req .Settings ,
1111
- Models : models ,
1112
- Queries : queries ,
1113
- Enums : enums ,
1114
- C : conf ,
1093
+ Models : models ,
1094
+ Queries : queries ,
1095
+ Enums : enums ,
1096
+ C : conf ,
1115
1097
}
1116
1098
1117
1099
tctx := pyTmplCtx {
@@ -1143,7 +1125,7 @@ func Generate(_ context.Context, req *plugin.CodeGenRequest) (*plugin.CodeGenRes
1143
1125
output [name ] = string (result .Python )
1144
1126
}
1145
1127
1146
- resp := plugin.CodeGenResponse {}
1128
+ resp := plugin.GenerateResponse {}
1147
1129
1148
1130
for filename , code := range output {
1149
1131
resp .Files = append (resp .Files , & plugin.File {
0 commit comments