mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-11-09 01:43:15 +00:00
fix(any): rework decode and encode to not use blanket impls
This commit is contained in:
parent
e2dabeeeee
commit
f9d961ae1d
@ -1,7 +1,4 @@
|
|||||||
use crate::any::value::AnyValueRefKind;
|
|
||||||
use crate::any::{Any, AnyValueRef};
|
|
||||||
use crate::decode::Decode;
|
use crate::decode::Decode;
|
||||||
use crate::error::BoxDynError;
|
|
||||||
use crate::types::Type;
|
use crate::types::Type;
|
||||||
|
|
||||||
#[cfg(feature = "postgres")]
|
#[cfg(feature = "postgres")]
|
||||||
@ -18,29 +15,39 @@ use crate::sqlite::Sqlite;
|
|||||||
|
|
||||||
// Implements Decode for any T where T supports Decode for any database that has support currently
|
// Implements Decode for any T where T supports Decode for any database that has support currently
|
||||||
// compiled into SQLx
|
// compiled into SQLx
|
||||||
impl<'r, T> Decode<'r, Any> for T
|
macro_rules! impl_any_decode {
|
||||||
where
|
($ty:ty) => {
|
||||||
T: AnyDecode<'r>,
|
impl<'r> crate::decode::Decode<'r, crate::any::Any> for $ty
|
||||||
{
|
where
|
||||||
fn decode(value: AnyValueRef<'r>) -> Result<Self, BoxDynError> {
|
$ty: crate::any::AnyDecode<'r>,
|
||||||
|
{
|
||||||
|
fn decode(
|
||||||
|
value: crate::any::AnyValueRef<'r>,
|
||||||
|
) -> Result<Self, crate::error::BoxDynError> {
|
||||||
match value.0 {
|
match value.0 {
|
||||||
#[cfg(feature = "mysql")]
|
#[cfg(feature = "mysql")]
|
||||||
AnyValueRefKind::MySql(value) => <T as Decode<'r, crate::mysql::MySql>>::decode(value),
|
crate::any::value::AnyValueRefKind::MySql(value) => {
|
||||||
|
<$ty as crate::decode::Decode<'r, crate::mysql::MySql>>::decode(value)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "sqlite")]
|
#[cfg(feature = "sqlite")]
|
||||||
AnyValueRefKind::Sqlite(value) => {
|
crate::any::value::AnyValueRefKind::Sqlite(value) => {
|
||||||
<T as Decode<'r, crate::sqlite::Sqlite>>::decode(value)
|
<$ty as crate::decode::Decode<'r, crate::sqlite::Sqlite>>::decode(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "mssql")]
|
#[cfg(feature = "mssql")]
|
||||||
AnyValueRefKind::Mssql(value) => <T as Decode<'r, crate::mssql::Mssql>>::decode(value),
|
crate::any::value::AnyValueRefKind::Mssql(value) => {
|
||||||
|
<$ty as crate::decode::Decode<'r, crate::mssql::Mssql>>::decode(value)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "postgres")]
|
#[cfg(feature = "postgres")]
|
||||||
AnyValueRefKind::Postgres(value) => {
|
crate::any::value::AnyValueRefKind::Postgres(value) => {
|
||||||
<T as Decode<'r, crate::postgres::Postgres>>::decode(value)
|
<$ty as crate::decode::Decode<'r, crate::postgres::Postgres>>::decode(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Find a nice way to auto-generate the below or petition Rust to add support for #[cfg]
|
// FIXME: Find a nice way to auto-generate the below or petition Rust to add support for #[cfg]
|
||||||
|
|||||||
@ -1,6 +1,4 @@
|
|||||||
use crate::any::arguments::AnyArgumentBufferKind;
|
use crate::encode::Encode;
|
||||||
use crate::any::{Any, AnyArgumentBuffer};
|
|
||||||
use crate::encode::{Encode, IsNull};
|
|
||||||
use crate::types::Type;
|
use crate::types::Type;
|
||||||
|
|
||||||
#[cfg(feature = "postgres")]
|
#[cfg(feature = "postgres")]
|
||||||
@ -17,28 +15,37 @@ use crate::sqlite::Sqlite;
|
|||||||
|
|
||||||
// Implements Encode for any T where T supports Encode for any database that has support currently
|
// Implements Encode for any T where T supports Encode for any database that has support currently
|
||||||
// compiled into SQLx
|
// compiled into SQLx
|
||||||
impl<'q, T> Encode<'q, Any> for T
|
macro_rules! impl_any_encode {
|
||||||
where
|
($ty:ty) => {
|
||||||
T: AnyEncode<'q>,
|
impl<'q> crate::encode::Encode<'q, crate::any::Any> for $ty
|
||||||
{
|
where
|
||||||
fn encode_by_ref(&self, buf: &mut AnyArgumentBuffer<'q>) -> IsNull {
|
$ty: crate::any::AnyEncode<'q>,
|
||||||
|
{
|
||||||
|
fn encode_by_ref(
|
||||||
|
&self,
|
||||||
|
buf: &mut crate::any::AnyArgumentBuffer<'q>,
|
||||||
|
) -> crate::encode::IsNull {
|
||||||
match &mut buf.0 {
|
match &mut buf.0 {
|
||||||
#[cfg(feature = "postgres")]
|
#[cfg(feature = "postgres")]
|
||||||
AnyArgumentBufferKind::Postgres(args, _) => args.add(self),
|
crate::any::arguments::AnyArgumentBufferKind::Postgres(args, _) => {
|
||||||
|
args.add(self)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "mysql")]
|
#[cfg(feature = "mysql")]
|
||||||
AnyArgumentBufferKind::MySql(args, _) => args.add(self),
|
crate::any::arguments::AnyArgumentBufferKind::MySql(args, _) => args.add(self),
|
||||||
|
|
||||||
#[cfg(feature = "mssql")]
|
#[cfg(feature = "mssql")]
|
||||||
AnyArgumentBufferKind::Mssql(args, _) => args.add(self),
|
crate::any::arguments::AnyArgumentBufferKind::Mssql(args, _) => args.add(self),
|
||||||
|
|
||||||
#[cfg(feature = "sqlite")]
|
#[cfg(feature = "sqlite")]
|
||||||
AnyArgumentBufferKind::Sqlite(args) => args.add(self),
|
crate::any::arguments::AnyArgumentBufferKind::Sqlite(args) => args.add(self),
|
||||||
}
|
}
|
||||||
|
|
||||||
// unused
|
// unused
|
||||||
IsNull::No
|
crate::encode::IsNull::No
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Find a nice way to auto-generate the below or petition Rust to add support for #[cfg]
|
// FIXME: Find a nice way to auto-generate the below or petition Rust to add support for #[cfg]
|
||||||
|
|||||||
@ -1,13 +1,20 @@
|
|||||||
|
#[macro_use]
|
||||||
|
mod decode;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
mod encode;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
mod r#type;
|
||||||
|
|
||||||
mod arguments;
|
mod arguments;
|
||||||
mod connection;
|
mod connection;
|
||||||
mod database;
|
mod database;
|
||||||
mod decode;
|
|
||||||
mod encode;
|
|
||||||
mod options;
|
mod options;
|
||||||
mod row;
|
mod row;
|
||||||
mod transaction;
|
mod transaction;
|
||||||
mod type_info;
|
mod type_info;
|
||||||
mod types;
|
pub mod types;
|
||||||
mod value;
|
mod value;
|
||||||
|
|
||||||
pub use arguments::{AnyArgumentBuffer, AnyArguments};
|
pub use arguments::{AnyArgumentBuffer, AnyArguments};
|
||||||
@ -16,6 +23,7 @@ pub use database::Any;
|
|||||||
pub use decode::AnyDecode;
|
pub use decode::AnyDecode;
|
||||||
pub use encode::AnyEncode;
|
pub use encode::AnyEncode;
|
||||||
pub use options::AnyConnectOptions;
|
pub use options::AnyConnectOptions;
|
||||||
|
pub use r#type::AnyType;
|
||||||
pub use row::AnyRow;
|
pub use row::AnyRow;
|
||||||
pub use transaction::AnyTransactionManager;
|
pub use transaction::AnyTransactionManager;
|
||||||
pub use type_info::AnyTypeInfo;
|
pub use type_info::AnyTypeInfo;
|
||||||
|
|||||||
252
sqlx-core/src/any/type.rs
Normal file
252
sqlx-core/src/any/type.rs
Normal file
@ -0,0 +1,252 @@
|
|||||||
|
use crate::types::Type;
|
||||||
|
|
||||||
|
#[cfg(feature = "postgres")]
|
||||||
|
use crate::postgres::Postgres;
|
||||||
|
|
||||||
|
#[cfg(feature = "mysql")]
|
||||||
|
use crate::mysql::MySql;
|
||||||
|
|
||||||
|
#[cfg(feature = "mssql")]
|
||||||
|
use crate::mssql::Mssql;
|
||||||
|
|
||||||
|
#[cfg(feature = "sqlite")]
|
||||||
|
use crate::sqlite::Sqlite;
|
||||||
|
|
||||||
|
// Type is required by the bounds of the [Row] and [Arguments] trait but its been overridden in
|
||||||
|
// AnyRow and AnyArguments to not use this implementation; but instead, delegate to the
|
||||||
|
// database-specific implementation.
|
||||||
|
//
|
||||||
|
// The other use of this trait is for compile-time verification which is not feasible to support
|
||||||
|
// for the [Any] driver.
|
||||||
|
macro_rules! impl_any_type {
|
||||||
|
($ty:ty) => {
|
||||||
|
impl crate::types::Type<crate::any::Any> for $ty
|
||||||
|
where
|
||||||
|
$ty: crate::any::AnyType,
|
||||||
|
{
|
||||||
|
fn type_info() -> crate::any::AnyTypeInfo {
|
||||||
|
// FIXME: nicer panic explaining why this isn't possible
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn compatible(ty: &crate::any::AnyTypeInfo) -> bool {
|
||||||
|
match &ty.0 {
|
||||||
|
#[cfg(feature = "postgres")]
|
||||||
|
crate::any::type_info::AnyTypeInfoKind::Postgres(ty) => {
|
||||||
|
<$ty as crate::types::Type<crate::postgres::Postgres>>::compatible(&ty)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "mysql")]
|
||||||
|
crate::any::type_info::AnyTypeInfoKind::MySql(ty) => {
|
||||||
|
<$ty as crate::types::Type<crate::mysql::MySql>>::compatible(&ty)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "sqlite")]
|
||||||
|
crate::any::type_info::AnyTypeInfoKind::Sqlite(ty) => {
|
||||||
|
<$ty as crate::types::Type<crate::sqlite::Sqlite>>::compatible(&ty)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "mssql")]
|
||||||
|
crate::any::type_info::AnyTypeInfoKind::Mssql(ty) => {
|
||||||
|
<$ty as crate::types::Type<crate::mssql::Mssql>>::compatible(&ty)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Find a nice way to auto-generate the below or petition Rust to add support for #[cfg]
|
||||||
|
// to trait bounds
|
||||||
|
|
||||||
|
// all 4
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
feature = "postgres",
|
||||||
|
feature = "mysql",
|
||||||
|
feature = "mssql",
|
||||||
|
feature = "sqlite"
|
||||||
|
))]
|
||||||
|
pub trait AnyType: Type<Postgres> + Type<MySql> + Type<Mssql> + Type<Sqlite> {}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
feature = "postgres",
|
||||||
|
feature = "mysql",
|
||||||
|
feature = "mssql",
|
||||||
|
feature = "sqlite"
|
||||||
|
))]
|
||||||
|
impl<T: ?Sized> AnyType for T where T: Type<Postgres> + Type<MySql> + Type<Mssql> + Type<Sqlite> {}
|
||||||
|
|
||||||
|
// only 3 (4)
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(feature = "mssql"),
|
||||||
|
all(feature = "postgres", feature = "mysql", feature = "sqlite")
|
||||||
|
))]
|
||||||
|
pub trait AnyType: Type<Postgres> + Type<MySql> + Type<Sqlite> {}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(feature = "mssql"),
|
||||||
|
all(feature = "postgres", feature = "mysql", feature = "sqlite")
|
||||||
|
))]
|
||||||
|
impl<T: ?Sized> AnyType for T where T: Type<Postgres> + Type<MySql> + Type<Sqlite> {}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(feature = "mysql"),
|
||||||
|
all(feature = "postgres", feature = "mssql", feature = "sqlite")
|
||||||
|
))]
|
||||||
|
pub trait AnyType: Type<Postgres> + Type<Mssql> + Type<Sqlite> {}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(feature = "mysql"),
|
||||||
|
all(feature = "postgres", feature = "mssql", feature = "sqlite")
|
||||||
|
))]
|
||||||
|
impl<T: ?Sized> AnyType for T where T: Type<Postgres> + Type<Mssql> + Type<Sqlite> {}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(feature = "sqlite"),
|
||||||
|
all(feature = "postgres", feature = "mysql", feature = "mssql")
|
||||||
|
))]
|
||||||
|
pub trait AnyType: Type<Postgres> + Type<MySql> + Type<Mssql> {}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(feature = "sqlite"),
|
||||||
|
all(feature = "postgres", feature = "mysql", feature = "mssql")
|
||||||
|
))]
|
||||||
|
impl<T: ?Sized> AnyType for T where T: Type<Postgres> + Type<MySql> + Type<Mssql> {}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(feature = "postgres"),
|
||||||
|
all(feature = "sqlite", feature = "mysql", feature = "mssql")
|
||||||
|
))]
|
||||||
|
pub trait AnyType: Type<Sqlite> + Type<MySql> + Type<Mssql> {}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(feature = "postgres"),
|
||||||
|
all(feature = "sqlite", feature = "mysql", feature = "mssql")
|
||||||
|
))]
|
||||||
|
impl<T: ?Sized> AnyType for T where T: Type<Sqlite> + Type<MySql> + Type<Mssql> {}
|
||||||
|
|
||||||
|
// only 2 (6)
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(any(feature = "mssql", feature = "sqlite")),
|
||||||
|
all(feature = "postgres", feature = "mysql")
|
||||||
|
))]
|
||||||
|
pub trait AnyType: Type<Postgres> + Type<MySql> {}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(any(feature = "mssql", feature = "sqlite")),
|
||||||
|
all(feature = "postgres", feature = "mysql")
|
||||||
|
))]
|
||||||
|
impl<T: ?Sized> AnyType for T where T: Type<Postgres> + Type<MySql> {}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(any(feature = "mysql", feature = "sqlite")),
|
||||||
|
all(feature = "postgres", feature = "mssql")
|
||||||
|
))]
|
||||||
|
pub trait AnyType: Type<Postgres> + Type<Mssql> {}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(any(feature = "mysql", feature = "sqlite")),
|
||||||
|
all(feature = "postgres", feature = "mssql")
|
||||||
|
))]
|
||||||
|
impl<T: ?Sized> AnyType for T where T: Type<Postgres> + Type<Mssql> {}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(any(feature = "mysql", feature = "mssql")),
|
||||||
|
all(feature = "postgres", feature = "sqlite")
|
||||||
|
))]
|
||||||
|
pub trait AnyType: Type<Postgres> + Type<Sqlite> {}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(any(feature = "mysql", feature = "mssql")),
|
||||||
|
all(feature = "postgres", feature = "sqlite")
|
||||||
|
))]
|
||||||
|
impl<T: ?Sized> AnyType for T where T: Type<Postgres> + Type<Sqlite> {}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(any(feature = "postgres", feature = "sqlite")),
|
||||||
|
all(feature = "mssql", feature = "mysql")
|
||||||
|
))]
|
||||||
|
pub trait AnyType: Type<Mssql> + Type<MySql> {}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(any(feature = "postgres", feature = "sqlite")),
|
||||||
|
all(feature = "mssql", feature = "mysql")
|
||||||
|
))]
|
||||||
|
impl<T: ?Sized> AnyType for T where T: Type<Mssql> + Type<MySql> {}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(any(feature = "postgres", feature = "mysql")),
|
||||||
|
all(feature = "mssql", feature = "sqlite")
|
||||||
|
))]
|
||||||
|
pub trait AnyType: Type<Mssql> + Type<Sqlite> {}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(any(feature = "postgres", feature = "mysql")),
|
||||||
|
all(feature = "mssql", feature = "sqlite")
|
||||||
|
))]
|
||||||
|
impl<T: ?Sized> AnyType for T where T: Type<Mssql> + Type<Sqlite> {}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(any(feature = "postgres", feature = "mssql")),
|
||||||
|
all(feature = "mysql", feature = "sqlite")
|
||||||
|
))]
|
||||||
|
pub trait AnyType: Type<MySql> + Type<Sqlite> {}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(any(feature = "postgres", feature = "mssql")),
|
||||||
|
all(feature = "mysql", feature = "sqlite")
|
||||||
|
))]
|
||||||
|
impl<T: ?Sized> AnyType for T where T: Type<MySql> + Type<Sqlite> {}
|
||||||
|
|
||||||
|
// only 1 (4)
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(any(feature = "mysql", feature = "mssql", feature = "sqlite")),
|
||||||
|
feature = "postgres"
|
||||||
|
))]
|
||||||
|
pub trait AnyType: Type<Postgres> {}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(any(feature = "mysql", feature = "mssql", feature = "sqlite")),
|
||||||
|
feature = "postgres"
|
||||||
|
))]
|
||||||
|
impl<T: ?Sized> AnyType for T where T: Type<Postgres> {}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(any(feature = "postgres", feature = "mssql", feature = "sqlite")),
|
||||||
|
feature = "mysql"
|
||||||
|
))]
|
||||||
|
pub trait AnyType: Type<MySql> {}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(any(feature = "postgres", feature = "mssql", feature = "sqlite")),
|
||||||
|
feature = "mysql"
|
||||||
|
))]
|
||||||
|
impl<T: ?Sized> AnyType for T where T: Type<MySql> {}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(any(feature = "mysql", feature = "postgres", feature = "sqlite")),
|
||||||
|
feature = "mssql"
|
||||||
|
))]
|
||||||
|
pub trait AnyType: Type<Mssql> {}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(any(feature = "mysql", feature = "postgres", feature = "sqlite")),
|
||||||
|
feature = "mssql"
|
||||||
|
))]
|
||||||
|
impl<T: ?Sized> AnyType for T where T: Type<Mssql> {}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(any(feature = "mysql", feature = "mssql", feature = "postgres")),
|
||||||
|
feature = "sqlite"
|
||||||
|
))]
|
||||||
|
pub trait AnyType: Type<Sqlite> {}
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(any(feature = "mysql", feature = "mssql", feature = "postgres")),
|
||||||
|
feature = "sqlite"
|
||||||
|
))]
|
||||||
|
impl<T: ?Sized> AnyType for T where T: Type<Sqlite> {}
|
||||||
@ -1,243 +1,57 @@
|
|||||||
use crate::any::type_info::AnyTypeInfoKind;
|
//! Conversions between Rust and standard **SQL** types.
|
||||||
use crate::any::{Any, AnyTypeInfo};
|
//!
|
||||||
use crate::database::Database;
|
//! # Types
|
||||||
use crate::types::Type;
|
//!
|
||||||
|
//! | Rust type | SQL type(s) |
|
||||||
|
//! |---------------------------------------|------------------------------------------------------|
|
||||||
|
//! | `bool` | BOOLEAN |
|
||||||
|
//! | `i32` | INT |
|
||||||
|
//! | `i64` | BIGINT |
|
||||||
|
//! | `f32` | FLOAT |
|
||||||
|
//! | `f64` | DOUBLE |
|
||||||
|
//! | `&str`, `String` | VARCHAR, CHAR, TEXT |
|
||||||
|
//!
|
||||||
|
//! # Nullable
|
||||||
|
//!
|
||||||
|
//! In addition, `Option<T>` is supported where `T` implements `Type`. An `Option<T>` represents
|
||||||
|
//! a potentially `NULL` value from SQL.
|
||||||
|
//!
|
||||||
|
|
||||||
#[cfg(feature = "postgres")]
|
// Type
|
||||||
use crate::postgres::Postgres;
|
|
||||||
|
|
||||||
#[cfg(feature = "mysql")]
|
impl_any_type!(bool);
|
||||||
use crate::mysql::MySql;
|
|
||||||
|
|
||||||
#[cfg(feature = "mssql")]
|
impl_any_type!(i32);
|
||||||
use crate::mssql::Mssql;
|
impl_any_type!(i64);
|
||||||
|
|
||||||
#[cfg(feature = "sqlite")]
|
impl_any_type!(f32);
|
||||||
use crate::sqlite::Sqlite;
|
impl_any_type!(f64);
|
||||||
|
|
||||||
// Type is required by the bounds of the [Row] and [Arguments] trait but its been overridden in
|
impl_any_type!(str);
|
||||||
// AnyRow and AnyArguments to not use this implementation; but instead, delegate to the
|
impl_any_type!(String);
|
||||||
// database-specific implementation.
|
|
||||||
//
|
|
||||||
// The other use of this trait is for compile-time verification which is not feasible to support
|
|
||||||
// for the [Any] driver.
|
|
||||||
impl<T> Type<Any> for T
|
|
||||||
where
|
|
||||||
T: AnyType,
|
|
||||||
{
|
|
||||||
fn type_info() -> <Any as Database>::TypeInfo {
|
|
||||||
// FIXME: nicer panic explaining why this isn't possible
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn compatible(ty: &AnyTypeInfo) -> bool {
|
// Encode
|
||||||
match &ty.0 {
|
|
||||||
#[cfg(feature = "postgres")]
|
|
||||||
AnyTypeInfoKind::Postgres(ty) => <T as Type<Postgres>>::compatible(&ty),
|
|
||||||
|
|
||||||
#[cfg(feature = "mysql")]
|
impl_any_encode!(bool);
|
||||||
AnyTypeInfoKind::MySql(ty) => <T as Type<MySql>>::compatible(&ty),
|
|
||||||
|
|
||||||
#[cfg(feature = "sqlite")]
|
impl_any_encode!(i32);
|
||||||
AnyTypeInfoKind::Sqlite(ty) => <T as Type<Sqlite>>::compatible(&ty),
|
impl_any_encode!(i64);
|
||||||
|
|
||||||
#[cfg(feature = "mssql")]
|
impl_any_encode!(f32);
|
||||||
AnyTypeInfoKind::Mssql(ty) => <T as Type<Mssql>>::compatible(&ty),
|
impl_any_encode!(f64);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: Find a nice way to auto-generate the below or petition Rust to add support for #[cfg]
|
impl_any_encode!(&'q str);
|
||||||
// to trait bounds
|
impl_any_encode!(String);
|
||||||
|
|
||||||
// all 4
|
// Decode
|
||||||
|
|
||||||
#[cfg(all(
|
impl_any_decode!(bool);
|
||||||
feature = "postgres",
|
|
||||||
feature = "mysql",
|
|
||||||
feature = "mssql",
|
|
||||||
feature = "sqlite"
|
|
||||||
))]
|
|
||||||
pub trait AnyType: Type<Postgres> + Type<MySql> + Type<Mssql> + Type<Sqlite> {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
impl_any_decode!(i32);
|
||||||
feature = "postgres",
|
impl_any_decode!(i64);
|
||||||
feature = "mysql",
|
|
||||||
feature = "mssql",
|
|
||||||
feature = "sqlite"
|
|
||||||
))]
|
|
||||||
impl<T> AnyType for T where T: Type<Postgres> + Type<MySql> + Type<Mssql> + Type<Sqlite> {}
|
|
||||||
|
|
||||||
// only 3 (4)
|
impl_any_decode!(f32);
|
||||||
|
impl_any_decode!(f64);
|
||||||
|
|
||||||
#[cfg(all(
|
impl_any_decode!(&'r str);
|
||||||
not(feature = "mssql"),
|
impl_any_decode!(String);
|
||||||
all(feature = "postgres", feature = "mysql", feature = "sqlite")
|
|
||||||
))]
|
|
||||||
pub trait AnyType: Type<Postgres> + Type<MySql> + Type<Sqlite> {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(feature = "mssql"),
|
|
||||||
all(feature = "postgres", feature = "mysql", feature = "sqlite")
|
|
||||||
))]
|
|
||||||
impl<T> AnyType for T where T: Type<Postgres> + Type<MySql> + Type<Sqlite> {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(feature = "mysql"),
|
|
||||||
all(feature = "postgres", feature = "mssql", feature = "sqlite")
|
|
||||||
))]
|
|
||||||
pub trait AnyType: Type<Postgres> + Type<Mssql> + Type<Sqlite> {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(feature = "mysql"),
|
|
||||||
all(feature = "postgres", feature = "mssql", feature = "sqlite")
|
|
||||||
))]
|
|
||||||
impl<T> AnyType for T where T: Type<Postgres> + Type<Mssql> + Type<Sqlite> {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(feature = "sqlite"),
|
|
||||||
all(feature = "postgres", feature = "mysql", feature = "mssql")
|
|
||||||
))]
|
|
||||||
pub trait AnyType: Type<Postgres> + Type<MySql> + Type<Mssql> {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(feature = "sqlite"),
|
|
||||||
all(feature = "postgres", feature = "mysql", feature = "mssql")
|
|
||||||
))]
|
|
||||||
impl<T> AnyType for T where T: Type<Postgres> + Type<MySql> + Type<Mssql> {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(feature = "postgres"),
|
|
||||||
all(feature = "sqlite", feature = "mysql", feature = "mssql")
|
|
||||||
))]
|
|
||||||
pub trait AnyType: Type<Sqlite> + Type<MySql> + Type<Mssql> {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(feature = "postgres"),
|
|
||||||
all(feature = "sqlite", feature = "mysql", feature = "mssql")
|
|
||||||
))]
|
|
||||||
impl<T> AnyType for T where T: Type<Sqlite> + Type<MySql> + Type<Mssql> {}
|
|
||||||
|
|
||||||
// only 2 (6)
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(any(feature = "mssql", feature = "sqlite")),
|
|
||||||
all(feature = "postgres", feature = "mysql")
|
|
||||||
))]
|
|
||||||
pub trait AnyType: Type<Postgres> + Type<MySql> {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(any(feature = "mssql", feature = "sqlite")),
|
|
||||||
all(feature = "postgres", feature = "mysql")
|
|
||||||
))]
|
|
||||||
impl<T> AnyType for T where T: Type<Postgres> + Type<MySql> {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(any(feature = "mysql", feature = "sqlite")),
|
|
||||||
all(feature = "postgres", feature = "mssql")
|
|
||||||
))]
|
|
||||||
pub trait AnyType: Type<Postgres> + Type<Mssql> {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(any(feature = "mysql", feature = "sqlite")),
|
|
||||||
all(feature = "postgres", feature = "mssql")
|
|
||||||
))]
|
|
||||||
impl<T> AnyType for T where T: Type<Postgres> + Type<Mssql> {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(any(feature = "mysql", feature = "mssql")),
|
|
||||||
all(feature = "postgres", feature = "sqlite")
|
|
||||||
))]
|
|
||||||
pub trait AnyType: Type<Postgres> + Type<Sqlite> {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(any(feature = "mysql", feature = "mssql")),
|
|
||||||
all(feature = "postgres", feature = "sqlite")
|
|
||||||
))]
|
|
||||||
impl<T> AnyType for T where T: Type<Postgres> + Type<Sqlite> {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(any(feature = "postgres", feature = "sqlite")),
|
|
||||||
all(feature = "mssql", feature = "mysql")
|
|
||||||
))]
|
|
||||||
pub trait AnyType: Type<Mssql> + Type<MySql> {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(any(feature = "postgres", feature = "sqlite")),
|
|
||||||
all(feature = "mssql", feature = "mysql")
|
|
||||||
))]
|
|
||||||
impl<T> AnyType for T where T: Type<Mssql> + Type<MySql> {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(any(feature = "postgres", feature = "mysql")),
|
|
||||||
all(feature = "mssql", feature = "sqlite")
|
|
||||||
))]
|
|
||||||
pub trait AnyType: Type<Mssql> + Type<Sqlite> {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(any(feature = "postgres", feature = "mysql")),
|
|
||||||
all(feature = "mssql", feature = "sqlite")
|
|
||||||
))]
|
|
||||||
impl<T> AnyType for T where T: Type<Mssql> + Type<Sqlite> {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(any(feature = "postgres", feature = "mssql")),
|
|
||||||
all(feature = "mysql", feature = "sqlite")
|
|
||||||
))]
|
|
||||||
pub trait AnyType: Type<MySql> + Type<Sqlite> {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(any(feature = "postgres", feature = "mssql")),
|
|
||||||
all(feature = "mysql", feature = "sqlite")
|
|
||||||
))]
|
|
||||||
impl<T> AnyType for T where T: Type<MySql> + Type<Sqlite> {}
|
|
||||||
|
|
||||||
// only 1 (4)
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(any(feature = "mysql", feature = "mssql", feature = "sqlite")),
|
|
||||||
feature = "postgres"
|
|
||||||
))]
|
|
||||||
pub trait AnyType: Type<Postgres> {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(any(feature = "mysql", feature = "mssql", feature = "sqlite")),
|
|
||||||
feature = "postgres"
|
|
||||||
))]
|
|
||||||
impl<T> AnyType for T where T: Type<Postgres> {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(any(feature = "postgres", feature = "mssql", feature = "sqlite")),
|
|
||||||
feature = "mysql"
|
|
||||||
))]
|
|
||||||
pub trait AnyType: Type<MySql> {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(any(feature = "postgres", feature = "mssql", feature = "sqlite")),
|
|
||||||
feature = "mysql"
|
|
||||||
))]
|
|
||||||
impl<T> AnyType for T where T: Type<MySql> {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(any(feature = "mysql", feature = "postgres", feature = "sqlite")),
|
|
||||||
feature = "mssql"
|
|
||||||
))]
|
|
||||||
pub trait AnyType: Type<Mssql> {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(any(feature = "mysql", feature = "postgres", feature = "sqlite")),
|
|
||||||
feature = "mssql"
|
|
||||||
))]
|
|
||||||
impl<T> AnyType for T where T: Type<Mssql> {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(any(feature = "mysql", feature = "mssql", feature = "postgres")),
|
|
||||||
feature = "sqlite"
|
|
||||||
))]
|
|
||||||
pub trait AnyType: Type<Sqlite> {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
not(any(feature = "mysql", feature = "mssql", feature = "postgres")),
|
|
||||||
feature = "sqlite"
|
|
||||||
))]
|
|
||||||
impl<T> AnyType for T where T: Type<Sqlite> {}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user