sea-orm
sea-orm copied to clipboard
Generate select_as and save_as attributes for custom column types.
PR Info
- Fixes #1643
New Features
- Generate select_as and save_as attributes to automatically cast custom types Before, using custom types in postgres resulted in a error like this:
DatabaseError occurred: Query Error: error occurred while decoding column "email": mismatched types; Rust type `core::option::Option<alloc::string::String>` (as SQL type `TEXT`) is not compatible with SQL type `citext`
Now it will be casted correctly.
I am not sure what the implications of adding select_as and save_as are for other database backends, since I believe this is only needed for postgres? So maybe it will need to be made configurable or only be enabled for postgres. Some feedback on this would be appreciated.
I've tested these changes in my codebase where it works great.
Breaking Changes
- Custom types will now have the select_as and save_as attributes generated. But since they wouldn't have been usable before, at least with postgres, I'm not sure if this is a breaking change.
I keep shooting myself in the foot with this issue - sea-orm-cli will overwrite the change to my users.rs file, which includes save_as = "citext", then I accidentally deploy the site without that save_as, and user lookups take 5 seconds instead of .01 seconds, since it's doing a full scan when querying citext columns as TEXT. Was also quite difficult to figure out this is what was going on, at first.
TL;DR: would love for this to be merged