This repository has been archived by the owner on Apr 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Prevent decimal/float conversions where unstable. Allow casting of expressions. #292
Open
pimeys
wants to merge
5
commits into
main
Choose a base branch
from
serialize-decimals-as-strings
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6481e1a
to
9d1fc75
Compare
dpetrick
approved these changes
May 11, 2021
tomhoule
approved these changes
May 12, 2021
5acae5a
to
042e341
Compare
It's unstable and will lead to tears.
Introduces a new trait `Castable`, implemented so far by anything that can be converted to an `Expression`. Usage: ```rust Select::default().value(1.cast_to(CastType::int2())) ``` Will convert the given value to an `int2` or a corresponding type in the database. Casting will happen on all visitors except SQLite. To whitelist where casting should happen, it should happen in the `CastType`: ```rust Select::default().value(1.cast_to(CastType::int2().on_postgres())) ``` This will only cast on PostgreSQL. The methods can be chained: ``` 1.cast_to(CastType::int2().on_postgres().on_sql_server()); ``` There are certain restrictions what can be casted, and the casting mechanism tries to find the closest allowed type from each database.
2bee954
to
7588c4b
Compare
fdc5b01
to
1276f6a
Compare
@pimeys This looks great! Just what I have been looking for to add query support to enum types. Anything I can do to help fast track this PR? |
@pimeys Slight correction in postgres visitor (Not sure about other databases), the custom type name should be double quoted. let comparison = "kind".equals(value.cast_as("UserKind")); The query output is: SELECT
"public"."users".*
FROM
"public"."users"
WHERE
"kind" = ($1) :: UserKind # I know crazy type name, but sometimes external databases have stuff like this
|
This whole issue is on hold now due to not having time in any team and if we merge this, we'll break our main product (it needs to get the corresponding PR finished and merged)... |
Ah, understood. Thanks, I'll try something at my end. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Part of: prisma/prisma#6902