issues-336 Array support#413
Conversation
| #[derive(Debug, Clone)] | ||
| pub struct Value(Rc<Box<dyn ValueTrait>>); |
There was a problem hiding this comment.
Hey @ikrivosheev, thanks for the draft!!
One question come up in my mind. For sea-query-binder and sea-query-driver, how do we bind the value on db driver? Because we can't figure out what's the type that implemented ValueTrait without the help of downcast and Any trait.
There was a problem hiding this comment.
@billy1624 this is the biggest problem... Another idea is move sqlx and driver into sea-query
There was a problem hiding this comment.
@Sytten ideas?
@billy1624 I can make two PR with with downcast and with move sqlx and driver into sea-query.
There was a problem hiding this comment.
keeping the enum when you have the boxed trait
I wanted to pass-around primitives (and to some extend anything less than 16 bytes and impl Copy) on the stack, albeit they end up in a Values Vec.
There was a problem hiding this comment.
I imagine it's like
// Inside the root of sea-query
trait ValueTrait {}
enum SeaValue {
I32(i32),
Object(Box<dyn ValueTrait>),
}
impl ValueTrait for SeaValue {}
// Inside sea-orm-binder
struct SqlxMySqlValue<T>(T)
where
T: ValueTrait + for<'q> Encode<'q, MySql>;
impl<'p, T> Encode<'p, MySql> for SqlxMySqlValue<T>
where
T: ValueTrait + for<'q> Encode<'q, MySql>,
{
fn encode_by_ref(
&self,
buf: &mut <MySql as sqlx::database::HasArguments<'_>>::ArgumentBuffer,
) -> sqlx::encode::IsNull {
self.0.encode_by_ref(buf)
}
}There was a problem hiding this comment.
And, maybe...
trait ValueTrait {}
enum SeaValue {
I32(i32),
Object(Box<dyn ValueTrait>),
}
impl ValueTrait for SeaValue {}
impl<'p> Encode<'p, MySql> for dyn ValueTrait
where
Self: for<'q> Encode<'q, MySql>,
{
fn encode_by_ref(
&self,
buf: &mut <MySql as sqlx::database::HasArguments<'p>>::ArgumentBuffer,
) -> sqlx::encode::IsNull {
self.encode_by_ref(buf)
}
}There was a problem hiding this comment.
@billy1624 it seems like it won't work...
// Inside the root of sea-query
trait ValueTrait {}
enum Value {
I32(i32),
Object(Box<dyn ValueTrait>),
}
impl ValueTrait for Value {}
// Inside sea-query-rusqlite
#[derive(Clone, Debug)]
struct RusqliteValue<T>(T)
where
T: ValueTrait + ToSql;
impl<T> ToSql for RusqliteValue<T>
where
T: ValueTrait + ToSql,
{
fn to_sql(&self) -> Result<ToSqlOutput<'_>> {
self.0.to_sql()
}
}
#[derive(Clone, Debug)]
pub struct RusqliteValues<T>(pub Vec<RusqliteValue<T>>); // <--- I cannot put here enum Value because it does not impl ToSql and I cannot make this parameter generic and I cannot impl ToSql for Value because it from other trait
|
Perhaps we can start from removing the object variants from Value (while keeping the primitive variants)? |
|
The requirements:
|
fb44aa9 to
e98f4eb
Compare
|
@billy1624 @tyt2y3 , hello! I have a bad surprise. |
|
It looks like instead of create our own |
|
Hmmm another sought... Black magic with unsafe. This should work. I can store row pointer to data and then transmute it to value and type get from enum. Example: https://github.com/Diggsey/ijson/ |
|
May be we should postpone |
|
Ah, one more problem... I try something like this: pub trait Sqlx<'q, T: Database>: Encode<'q, T> + Type<T> {}
pub trait ValueTrait
where
Self: Debug,
{
fn to_sql_string(&self) -> String;
#[cfg(feature = "with-postgres")]
fn as_postgres_to_sql(&self) -> &(dyn PostgresToSql + Sync + Send);
#[cfg(feature = "sqlx-mysql")]
fn as_sqlx_mysql<'q>(&'q self) -> &(dyn Sqlx<'q, MySql>);
#[cfg(feature = "sqlx-postgres")]
fn as_sqlx_postgres<'q>(&'q self) -> &(dyn Sqlx<'q, Postgres>);
#[cfg(feature = "sqlx-sqlite")]
fn as_sqlx_sqlite<'q>(&'q self) -> &(dyn Sqlx<'q, Sqlite>);
}
#[derive(Debug, Clone)]
pub enum Value {
Bool(bool),
TinyInt(i8),
SmallInt(i16),
Int(i32),
BigInt(i64),
TinyUnsigned(u8),
SmallUnsigned(u16),
Unsigned(u32),
BigUnsigned(u64),
Float(f32),
Double(f64),
#[cfg(feature = "thread-safe")]
Object(SeaRc<Box<dyn ValueTrait + Sync + Send>>),
#[cfg(not(feature = "thread-safe"))]
Object(SeaRc<Box<dyn ValueTrait>>),
}
impl ValueTrait for Value {...}Problems:
|
|
1: I think we won't combine them |
|
I guess we can close this? |
@billy1624 I think, no, we cannot... I will continue work on it. |
|
Alright, a trait based |
PR Info
This is continue: #390