-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
The trait sqlx::Type
is not object safe, as it does not take &self
in it's two methods fn type_info() -> TypeInfo
and fn compatible(ty: TypeInfo) -> bool
.
This is a major issue in a project I'm working on (sea-query & sea-orm), as in my case I am passing values as dyn Trait
objects, but cannot include sqlx::Type
in the trait objects.
For example, my trait has:
trait QueryValue: sqlx::Encode<'static, sqlx::MySql> + sqlx::Type<sqlx::MySql> {
fn query_value(&self, query_builder: &dyn QueryBuilder) -> String;
}
But this does not work as sqlx::Type
cannot be made into a trait object.
Another example would be if you had an enum containing many database types:
enum Value {
Bool(Option<bool>),
TinyInt(Option<i8>),
SmallInt(Option<i16>),
String(Option<Box<String>>),
...
Custom(Box<dyn QueryValue>),
}
This cannot be done without adding a generic to the Value
enum, which in my case needs to be avoided.
Is there any kind of workaround possible for this situation? My main use for QueryValue
is to pass it to .bind(value)
for use in queries.
Metadata
Metadata
Assignees
Labels
No labels