-
-
Notifications
You must be signed in to change notification settings - Fork 196
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
Replace Value
enum with dyn QueryValue
#146
Conversation
Thank you for the effort. There seems to be a lot of useful ideas!
And the impact to users is seemingly small. My only wonder is, what new possibilities does this change bring to users? |
I finally can answer this question with the PR in Sea ORM SeaQL/sea-orm#214 It allows support for |
PrimitiveValue::BigUnsigned(value) => value.query_value(query_builder), | ||
PrimitiveValue::Float(value) => value.query_value(query_builder), | ||
PrimitiveValue::Double(value) => value.query_value(query_builder), | ||
PrimitiveValue::String(value) => value.as_deref().cloned().query_value(query_builder), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find a way to do this without .cloned()
. I think some changes need to be made in impl<T> QueryValue for Option<T>
, but I had issues getting it to work.
With the new issue made SeaQL/sea-orm#252, I wil close this PR for now. If needed it can be reopened. On a side note, I feel over using dynamic trait objects is tempting but not always the solution. |
This PR deprecated the old
Value
enum, and creates a new struct:Value(Box<dyn QueryValue>)
.Any type that implements the new trait
QueryValue
can be used as aValue
.Many of the primitive types implement QueryValue, including:
&str
,String
,i8
,i16
,i32
,i64
,u8
,u16
,u32
,u64
,f32
,f64
,bool
,()
(represents NULL),Vec<u8>
,serde_json::Value
,chrono::NaiveDate
,chrono::NaiveTime
,chrono::NaiveDateTime
,chrono::DateTime<chrono::FixedOffset>
,uuid::Uuid
,rust_decimal::Decimal
,bigdecimal::BigDecimal
.This means they can be used in queries (as they would previously), and calling
.into()
where necessary.The old enum
Value
has been renamed toPrimitiveValue
and has been marked as deprecated. This PR updates sea-query's version to 0.17.0. If this needs to be changed, let me know :)