Trait sqlx_core_oldapi::decode::Decode
source · pub trait Decode<'r, DB: Database>: Sized {
// Required method
fn decode(
value: <DB as HasValueRef<'r>>::ValueRef
) -> Result<Self, BoxDynError>;
}Expand description
A type that can be decoded from the database.
How can I implement Decode?
A manual implementation of Decode can be useful when adding support for
types externally to SQLx.
The following showcases how to implement Decode to be generic over Database. The
implementation can be marginally simpler if you remove the DB type parameter and explicitly
use the concrete ValueRef and TypeInfo types.
struct MyType;
// DB is the database driver
// `'r` is the lifetime of the `Row` being decoded
impl<'r, DB: Database> Decode<'r, DB> for MyType
where
// we want to delegate some of the work to string decoding so let's make sure strings
// are supported by the database
&'r str: Decode<'r, DB>
{
fn decode(
value: <DB as HasValueRef<'r>>::ValueRef,
) -> Result<MyType, Box<dyn Error + 'static + Send + Sync>> {
// the interface of ValueRef is largely unstable at the moment
// so this is not directly implementable
// however, you can delegate to a type that matches the format of the type you want
// to decode (such as a UTF-8 string)
let value = <&str as Decode<DB>>::decode(value)?;
// now you can parse this into your type (assuming there is a `FromStr`)
Ok(value.parse()?)
}
}Required Methods§
sourcefn decode(value: <DB as HasValueRef<'r>>::ValueRef) -> Result<Self, BoxDynError>
fn decode(value: <DB as HasValueRef<'r>>::ValueRef) -> Result<Self, BoxDynError>
Decode a new value of this type using a raw value from the database.
Implementations on Foreign Types§
source§impl<'r> Decode<'r, Any> for f64where
f64: AnyDecode<'r>,
impl<'r> Decode<'r, Any> for f64where f64: AnyDecode<'r>,
fn decode(value: AnyValueRef<'r>) -> Result<Self, BoxDynError>
source§impl Decode<'_, MySql> for bool
impl Decode<'_, MySql> for bool
fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, MySql> for Date
impl<'r> Decode<'r, MySql> for Date
fn decode(value: MySqlValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r, T1> Decode<'r, Postgres> for (T1,)where
T1: 'r + Type<Postgres> + for<'a> Decode<'a, Postgres>,
impl<'r, T1> Decode<'r, Postgres> for (T1,)where T1: 'r + Type<Postgres> + for<'a> Decode<'a, Postgres>,
fn decode(value: PgValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Postgres> for &'r str
impl<'r> Decode<'r, Postgres> for &'r str
fn decode(value: PgValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Sqlite> for PrimitiveDateTime
impl<'r> Decode<'r, Sqlite> for PrimitiveDateTime
fn decode(value: SqliteValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Sqlite> for Time
impl<'r> Decode<'r, Sqlite> for Time
fn decode(value: SqliteValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Any> for i16where
i16: AnyDecode<'r>,
impl<'r> Decode<'r, Any> for i16where i16: AnyDecode<'r>,
fn decode(value: AnyValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Postgres> for NaiveTime
impl<'r> Decode<'r, Postgres> for NaiveTime
fn decode(value: PgValueRef<'r>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Postgres> for MacAddress
impl Decode<'_, Postgres> for MacAddress
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, MySql> for i64
impl Decode<'_, MySql> for i64
fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, MySql> for PrimitiveDateTime
impl<'r> Decode<'r, MySql> for PrimitiveDateTime
fn decode(value: MySqlValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Sqlite> for Vec<u8>
impl<'r> Decode<'r, Sqlite> for Vec<u8>
fn decode(value: SqliteValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Any> for NaiveDateTimewhere
NaiveDateTime: AnyDecode<'r>,
impl<'r> Decode<'r, Any> for NaiveDateTimewhere NaiveDateTime: AnyDecode<'r>,
fn decode(value: AnyValueRef<'r>) -> Result<Self, BoxDynError>
source§impl Decode<'_, MySql> for u32
impl Decode<'_, MySql> for u32
fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Any> for boolwhere
bool: AnyDecode<'r>,
impl<'r> Decode<'r, Any> for boolwhere bool: AnyDecode<'r>,
fn decode(value: AnyValueRef<'r>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Postgres> for Vec<u8>
impl Decode<'_, Postgres> for Vec<u8>
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Postgres> for DateTime<FixedOffset>
impl<'r> Decode<'r, Postgres> for DateTime<FixedOffset>
fn decode(value: PgValueRef<'r>) -> Result<Self, BoxDynError>
source§impl Decode<'_, MySql> for Uuid
impl Decode<'_, MySql> for Uuid
fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Sqlite> for bool
impl<'r> Decode<'r, Sqlite> for bool
fn decode(value: SqliteValueRef<'r>) -> Result<bool, BoxDynError>
source§impl<'r> Decode<'r, MySql> for Cow<'r, str>
impl<'r> Decode<'r, MySql> for Cow<'r, str>
fn decode(value: MySqlValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Sqlite> for &'r [u8]
impl<'r> Decode<'r, Sqlite> for &'r [u8]
fn decode(value: SqliteValueRef<'r>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Mssql> for NaiveDate
impl Decode<'_, Mssql> for NaiveDate
Decodes Date values received from the server
fn decode(value: MssqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Sqlite> for Date
impl<'r> Decode<'r, Sqlite> for Date
fn decode(value: SqliteValueRef<'r>) -> Result<Self, BoxDynError>
source§impl Decode<'_, MySql> for Vec<u8>
impl Decode<'_, MySql> for Vec<u8>
fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Postgres> for f32
impl Decode<'_, Postgres> for f32
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError>
source§impl<const N: usize> Decode<'_, Postgres> for [u8; N]
impl<const N: usize> Decode<'_, Postgres> for [u8; N]
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Sqlite> for Hyphenated
impl Decode<'_, Sqlite> for Hyphenated
fn decode(value: SqliteValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Postgres> for BigDecimal
impl Decode<'_, Postgres> for BigDecimal
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, MySql> for &'r [u8]
impl<'r> Decode<'r, MySql> for &'r [u8]
fn decode(value: MySqlValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r, T1, T2, T3, T4> Decode<'r, Postgres> for (T1, T2, T3, T4)where
T1: 'r + Type<Postgres> + for<'a> Decode<'a, Postgres>,
T2: 'r + Type<Postgres> + for<'a> Decode<'a, Postgres>,
T3: 'r + Type<Postgres> + for<'a> Decode<'a, Postgres>,
T4: 'r + Type<Postgres> + for<'a> Decode<'a, Postgres>,
impl<'r, T1, T2, T3, T4> Decode<'r, Postgres> for (T1, T2, T3, T4)where T1: 'r + Type<Postgres> + for<'a> Decode<'a, Postgres>, T2: 'r + Type<Postgres> + for<'a> Decode<'a, Postgres>, T3: 'r + Type<Postgres> + for<'a> Decode<'a, Postgres>, T4: 'r + Type<Postgres> + for<'a> Decode<'a, Postgres>,
fn decode(value: PgValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, MySql> for Time
impl<'r> Decode<'r, MySql> for Time
fn decode(value: MySqlValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Sqlite> for u32
impl<'r> Decode<'r, Sqlite> for u32
fn decode(value: SqliteValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Postgres> for Time
impl<'r> Decode<'r, Postgres> for Time
fn decode(value: PgValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Postgres> for Date
impl<'r> Decode<'r, Postgres> for Date
fn decode(value: PgValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, MySql> for DateTime<Utc>
impl<'r> Decode<'r, MySql> for DateTime<Utc>
Note: assumes the connection’s time_zone is set to +00:00 (UTC).
fn decode(value: MySqlValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Sqlite> for u16
impl<'r> Decode<'r, Sqlite> for u16
fn decode(value: SqliteValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r, DB, T> Decode<'r, DB> for Option<T>where
DB: Database,
T: Decode<'r, DB>,
impl<'r, DB, T> Decode<'r, DB> for Option<T>where DB: Database, T: Decode<'r, DB>,
fn decode(value: <DB as HasValueRef<'r>>::ValueRef) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Any> for i32where
i32: AnyDecode<'r>,
impl<'r> Decode<'r, Any> for i32where i32: AnyDecode<'r>,
fn decode(value: AnyValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Sqlite> for String
impl<'r> Decode<'r, Sqlite> for String
fn decode(value: SqliteValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Any> for NaiveDatewhere
NaiveDate: AnyDecode<'r>,
impl<'r> Decode<'r, Any> for NaiveDatewhere NaiveDate: AnyDecode<'r>,
fn decode(value: AnyValueRef<'r>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Postgres> for IpNetwork
impl Decode<'_, Postgres> for IpNetwork
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Sqlite> for OffsetDateTime
impl<'r> Decode<'r, Sqlite> for OffsetDateTime
fn decode(value: SqliteValueRef<'r>) -> Result<Self, BoxDynError>
source§impl Decode<'_, MySql> for i32
impl Decode<'_, MySql> for i32
fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl<'r, T1, T2, T3, T4, T5, T6, T7, T8> Decode<'r, Postgres> for (T1, T2, T3, T4, T5, T6, T7, T8)where
T1: 'r + Type<Postgres> + for<'a> Decode<'a, Postgres>,
T2: 'r + Type<Postgres> + for<'a> Decode<'a, Postgres>,
T3: 'r + Type<Postgres> + for<'a> Decode<'a, Postgres>,
T4: 'r + Type<Postgres> + for<'a> Decode<'a, Postgres>,
T5: 'r + Type<Postgres> + for<'a> Decode<'a, Postgres>,
T6: 'r + Type<Postgres> + for<'a> Decode<'a, Postgres>,
T7: 'r + Type<Postgres> + for<'a> Decode<'a, Postgres>,
T8: 'r + Type<Postgres> + for<'a> Decode<'a, Postgres>,
impl<'r, T1, T2, T3, T4, T5, T6, T7, T8> Decode<'r, Postgres> for (T1, T2, T3, T4, T5, T6, T7, T8)where T1: 'r + Type<Postgres> + for<'a> Decode<'a, Postgres>, T2: 'r + Type<Postgres> + for<'a> Decode<'a, Postgres>, T3: 'r + Type<Postgres> + for<'a> Decode<'a, Postgres>, T4: 'r + Type<Postgres> + for<'a> Decode<'a, Postgres>, T5: 'r + Type<Postgres> + for<'a> Decode<'a, Postgres>, T6: 'r + Type<Postgres> + for<'a> Decode<'a, Postgres>, T7: 'r + Type<Postgres> + for<'a> Decode<'a, Postgres>, T8: 'r + Type<Postgres> + for<'a> Decode<'a, Postgres>,
fn decode(value: PgValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Mssql> for Cow<'r, [u8]>
impl<'r> Decode<'r, Mssql> for Cow<'r, [u8]>
fn decode(value: MssqlValueRef<'r>) -> Result<Self, BoxDynError>
source§impl Decode<'_, MySql> for Decimal
impl Decode<'_, MySql> for Decimal
fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, MySql> for u16
impl Decode<'_, MySql> for u16
fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, MySql> for String
impl Decode<'_, MySql> for String
fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Any> for DateTime<Utc>where
DateTime<Utc>: AnyDecode<'r>,
impl<'r> Decode<'r, Any> for DateTime<Utc>where DateTime<Utc>: AnyDecode<'r>,
fn decode(value: AnyValueRef<'r>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Postgres> for i8
impl Decode<'_, Postgres> for i8
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Any> for Stringwhere
String: AnyDecode<'r>,
impl<'r> Decode<'r, Any> for Stringwhere String: AnyDecode<'r>,
fn decode(value: AnyValueRef<'r>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Mssql> for String
impl Decode<'_, Mssql> for String
fn decode(value: MssqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Any> for &'r strwhere
&'r str: AnyDecode<'r>,
impl<'r> Decode<'r, Any> for &'r strwhere &'r str: AnyDecode<'r>,
fn decode(value: AnyValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Sqlite> for i32
impl<'r> Decode<'r, Sqlite> for i32
fn decode(value: SqliteValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Sqlite> for &'r str
impl<'r> Decode<'r, Sqlite> for &'r str
fn decode(value: SqliteValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Sqlite> for i64
impl<'r> Decode<'r, Sqlite> for i64
fn decode(value: SqliteValueRef<'r>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Postgres> for String
impl Decode<'_, Postgres> for String
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Postgres> for bool
impl Decode<'_, Postgres> for bool
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Mssql> for &'r [u8]
impl<'r> Decode<'r, Mssql> for &'r [u8]
fn decode(value: MssqlValueRef<'r>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Postgres> for i16
impl Decode<'_, Postgres> for i16
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Sqlite> for i8
impl<'r> Decode<'r, Sqlite> for i8
fn decode(value: SqliteValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Sqlite> for DateTime<FixedOffset>
impl<'r> Decode<'r, Sqlite> for DateTime<FixedOffset>
fn decode(value: SqliteValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r, T, const N: usize> Decode<'r, Postgres> for [T; N]where
T: for<'a> Decode<'a, Postgres> + Type<Postgres>,
impl<'r, T, const N: usize> Decode<'r, Postgres> for [T; N]where T: for<'a> Decode<'a, Postgres> + Type<Postgres>,
fn decode(value: PgValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, MySql> for DateTime<Local>
impl<'r> Decode<'r, MySql> for DateTime<Local>
Note: assumes the connection’s time_zone is set to +00:00 (UTC).
fn decode(value: MySqlValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, MySql> for OffsetDateTime
impl<'r> Decode<'r, MySql> for OffsetDateTime
fn decode(value: MySqlValueRef<'r>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Postgres> for Decimal
impl Decode<'_, Postgres> for Decimal
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Sqlite> for DateTime<Local>
impl<'r> Decode<'r, Sqlite> for DateTime<Local>
fn decode(value: SqliteValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Postgres> for DateTime<Local>
impl<'r> Decode<'r, Postgres> for DateTime<Local>
fn decode(value: PgValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Postgres> for Cow<'r, str>
impl<'r> Decode<'r, Postgres> for Cow<'r, str>
fn decode(value: PgValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Mssql> for Cow<'r, str>
impl<'r> Decode<'r, Mssql> for Cow<'r, str>
fn decode(value: MssqlValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Postgres> for PrimitiveDateTime
impl<'r> Decode<'r, Postgres> for PrimitiveDateTime
fn decode(value: PgValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Any> for &'r [u8]where
&'r [u8]: AnyDecode<'r>,
impl<'r> Decode<'r, Any> for &'r [u8]where &'r [u8]: AnyDecode<'r>,
fn decode(value: AnyValueRef<'r>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Mssql> for NaiveDateTime
impl Decode<'_, Mssql> for NaiveDateTime
Decodes DateTime2N values received from the server
fn decode(value: MssqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, MySql> for Hyphenated
impl Decode<'_, MySql> for Hyphenated
fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Mssql> for Vec<u8>
impl Decode<'_, Mssql> for Vec<u8>
fn decode(value: MssqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, MySql> for f64
impl Decode<'_, MySql> for f64
fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Mssql> for i8
impl Decode<'_, Mssql> for i8
fn decode(value: MssqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Mssql> for NaiveTime
impl Decode<'_, Mssql> for NaiveTime
Decodes Time values received from the server