Alternate column names
We have several apps built in different languages that use the same database. At some point in the last 15 years of this app running, some columns have been named wonky or misspelled. We can't just easily run a RENAME COLUMN migration because there's no telling where all this thing may be called.
What if we had a way to rename the method that calls a column?
table do
column email : String, from: "employeemail"
end
This way I could also do UserQuery.new.email("[email protected]") which would still generate SELECT * FROM users WHERE employeemail = '[email protected]'
That's going to be very useful I think. Not only for legacy databases but also as an alias for longer column names.
I dig it 👍
Oh this is a cool feature, I'd like to work on this.
Sure! You can have at it @rnice01
We may be able to hook in to the @[DB::Field(key: "firstname")] annotation to handle this. https://github.com/crystal-lang/crystal-db/blob/master/src/db/serializable.cr#L41-L42
Just looked into this since DB.mapping supports the key field as well. I learned that the key only applies to reading the result set back from the database so it would take quite an investment to update the other places to use the override as well.