@@ -181,18 +181,52 @@ func (q Query) ArgDictNode() *pyast.Node {
181181}
182182
183183func makePyType (req * plugin.GenerateRequest , col * plugin.Column ) pyType {
184- typ := pyInnerType (req , col )
184+ // Parse the configuration
185+ var conf Config
186+ if len (req .PluginOptions ) > 0 {
187+ if err := json .Unmarshal (req .PluginOptions , & conf ); err != nil {
188+ log .Printf ("failed to parse plugin options: %s" , err )
189+ }
190+ }
191+
192+ // Check for overrides
193+ if len (conf .Overrides ) > 0 && col .Table != nil {
194+ tableName := col .Table .Name
195+ if col .Table .Schema != "" && col .Table .Schema != req .Catalog .DefaultSchema {
196+ tableName = col .Table .Schema + "." + tableName
197+ }
198+
199+ // Look for a matching override
200+ for _ , override := range conf .Overrides {
201+ overrideKey := tableName + "." + col .Name
202+ if override .Column == overrideKey {
203+ // Found a match, use the override
204+ typeStr := override .PyType
205+ if override .PyImport != "" && ! strings .Contains (typeStr , "." ) {
206+ typeStr = override .PyImport + "." + override .PyType
207+ }
208+ return pyType {
209+ InnerType : typeStr ,
210+ IsArray : col .IsArray ,
211+ IsNull : ! col .NotNull ,
212+ }
213+ }
214+ }
215+ }
216+
217+ // No override found, use the standard type mapping
218+ typ := pyInnerType (conf , req , col )
185219 return pyType {
186220 InnerType : typ ,
187221 IsArray : col .IsArray ,
188222 IsNull : ! col .NotNull ,
189223 }
190224}
191225
192- func pyInnerType (req * plugin.GenerateRequest , col * plugin.Column ) string {
226+ func pyInnerType (conf Config , req * plugin.GenerateRequest , col * plugin.Column ) string {
193227 switch req .Settings .Engine {
194228 case "postgresql" :
195- return postgresType (req , col )
229+ return postgresType (conf , req , col )
196230 default :
197231 log .Println ("unsupported engine type" )
198232 return "Any"
@@ -226,18 +260,18 @@ func pyEnumValueName(value string) string {
226260 return strings .ToUpper (id )
227261}
228262
229- func buildEnums (req * plugin.GenerateRequest ) []Enum {
263+ func buildEnums (conf Config , req * plugin.GenerateRequest ) []Enum {
230264 var enums []Enum
231265 for _ , schema := range req .Catalog .Schemas {
232266 if schema .Name == "pg_catalog" || schema .Name == "information_schema" {
233267 continue
234268 }
235269 for _ , enum := range schema .Enums {
236270 var enumName string
237- if schema .Name == req .Catalog .DefaultSchema {
238- enumName = enum .Name
239- } else {
271+ if conf .EmitSchemaNamePrefix && schema .Name != req .Catalog .DefaultSchema {
240272 enumName = schema .Name + "_" + enum .Name
273+ } else {
274+ enumName = enum .Name
241275 }
242276 e := Enum {
243277 Name : modelName (enumName , req .Settings ),
@@ -267,10 +301,10 @@ func buildModels(conf Config, req *plugin.GenerateRequest) []Struct {
267301 }
268302 for _ , table := range schema .Tables {
269303 var tableName string
270- if schema .Name == req .Catalog .DefaultSchema {
271- tableName = table .Rel .Name
272- } else {
304+ if conf .EmitSchemaNamePrefix && schema .Name != req .Catalog .DefaultSchema {
273305 tableName = schema .Name + "_" + table .Rel .Name
306+ } else {
307+ tableName = table .Rel .Name
274308 }
275309 structName := tableName
276310 if ! conf .EmitExactTableNames {
@@ -1185,7 +1219,7 @@ func Generate(_ context.Context, req *plugin.GenerateRequest) (*plugin.GenerateR
11851219 }
11861220 }
11871221
1188- enums := buildEnums (req )
1222+ enums := buildEnums (conf , req )
11891223 models := buildModels (conf , req )
11901224 queries , err := buildQueries (conf , req , models )
11911225 if err != nil {
0 commit comments