volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.73k stars 544 forks source link

Struct name + field <-> table + column name mappings #239

Closed theduke closed 6 years ago

theduke commented 6 years ago

I have to work with a convoluted legacy database, where table names and column names are more or less unusable as struct and field names.

I'd need some way of overwriting struct and column names in the generated code, while still preserving the option to re-generate everything.

Something like this would be nice:

sqlBoiler.toml

[mappings.tables]
tbl_whatEverConvolutedNameHere = "MyStructName"

[mappings.columns.tbl_whatEverConvolutedNameHere]
_some_bad_column_name = "SaneStructFieldName"

Is this something you would accept / support?

I'm willing to whip up a PR if so.

aarondl commented 6 years ago

More and more I think I can see the need for this. I'd like to base it on top of the v3 code though since it'll be quite an involved change I think. And it needs to be developed alongside the name collision avoidance code. Since that's going to end up being something really important: https://github.com/volatiletech/sqlboiler/issues/116

aarondl commented 6 years ago

The generated Go names for Tables, Columns, and Relationships can now be aliased to prevent collisions: https://github.com/volatiletech/sqlboiler/tree/v3#names