sea-query
sea-query copied to clipboard
issues-336 Array support
PR Info
- Closes https://github.com/SeaQL/sea-query/issues/336
This is continue: https://github.com/SeaQL/sea-query/pull/390
Perhaps we can start from removing the object variants from Value (while keeping the primitive variants)?
The requirements:
- No downcast
- Keep SeaQuery clean, outsource heavy lifting of value binding to binder
- Include binder in sea-query's dependency but do not turn on the features by default
- It could be
Valuein sea-query,ValueTraitin binder - Could we enable multiple backend support in an additive compatible way? I.e. if one downstream turned on SQLx and another turn on postgres. The
?cargo syntax should be helpful
@billy1624 @tyt2y3 , hello! I have a bad surprise. trait ToSql from postgres-types crate need: Self: Sized, but I cannot make ValueTrait: Sized, because I need dyn ValueTrait
It looks like instead of create our own ValueTrait make all types, which hold Value should be generic...
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 ValueTrait to after 0.27, and trying to get array working with sqlx-postgres for now
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:
- I cannot combine
rusqliteandsqlxin one crate (failed to select a version for libsqlite3-sys) - I cannot make
&dyn SqlxbecauseType<T>-Sqlxcannot be made into an object` - https://github.com/launchbadge/sqlx/issues/1461 sea-query-postgresthrow compile error:the to_sqlmethod cannot be invoked on a trait object`
1: I think we won't combine them 2: we have to create our own trait based on that but is object safe
I guess we can close this?
I guess we can close this?
@billy1624 I think, no, we cannot... I will continue work on it.
Alright, a trait based Value with array support would be cool. And a huge step forward :)