Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate select_as and save_as attributes for custom column types. #2081

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lucasmerlin
Copy link

PR Info

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.

@lucasmerlin lucasmerlin force-pushed the select-as-save-as-for-custom-columns branch from 28fdb30 to 933f6e6 Compare May 31, 2024 17:13
@marcusbuffett
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sea-orm-cli generate entity migration select_as, save_as support
2 participants