This repository was archived by the owner on Apr 25, 2023. It is now read-only.
Prevent decimal/float conversions where unstable. Allow casting of expressions.#292
Open
Prevent decimal/float conversions where unstable. Allow casting of expressions.#292
Conversation
6481e1a to
9d1fc75
Compare
dpetrick
approved these changes
May 11, 2021
tomhoule
approved these changes
May 12, 2021
5acae5a to
042e341
Compare
added 4 commits
May 19, 2021 09:49
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
|
Contributor
Author
|
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. |
This file contains hidden or 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
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