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.
Object Safety§
Implementations on Foreign Types§
source§impl Decode<'_, Mssql> for bool
impl Decode<'_, Mssql> for bool
fn decode(value: MssqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Mssql> for f32
impl Decode<'_, Mssql> for f32
fn decode(value: MssqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Mssql> for f64
impl Decode<'_, Mssql> for f64
fn decode(value: MssqlValueRef<'_>) -> 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 i16
impl Decode<'_, Mssql> for i16
fn decode(value: MssqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Mssql> for i32
impl Decode<'_, Mssql> for i32
fn decode(value: MssqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Mssql> for i64
impl Decode<'_, Mssql> for i64
fn decode(value: MssqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Mssql> for u8
impl Decode<'_, Mssql> for u8
fn decode(value: MssqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Mssql> for String
impl Decode<'_, Mssql> for String
fn decode(value: MssqlValueRef<'_>) -> 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<'_, Mssql> for BigDecimal
impl Decode<'_, Mssql> for BigDecimal
fn decode(value: MssqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Mssql> for DateTime<FixedOffset>
impl Decode<'_, Mssql> for DateTime<FixedOffset>
fn decode(value: MssqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Mssql> for DateTime<Utc>
impl Decode<'_, Mssql> for DateTime<Utc>
fn decode(value: MssqlValueRef<'_>) -> 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 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<'_, Mssql> for NaiveTime
impl Decode<'_, Mssql> for NaiveTime
Decodes Time values received from the server
fn decode(value: MssqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Mssql> for Decimal
impl Decode<'_, Mssql> for Decimal
fn decode(value: MssqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, MySql> for bool
impl Decode<'_, MySql> for bool
fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, MySql> for f32
impl Decode<'_, MySql> for f32
fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, MySql> for f64
impl Decode<'_, MySql> for f64
fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, MySql> for i8
impl Decode<'_, MySql> for i8
fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, MySql> for i16
impl Decode<'_, MySql> for i16
fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, MySql> for i32
impl Decode<'_, MySql> for i32
fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, MySql> for i64
impl Decode<'_, MySql> for i64
fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, MySql> for u8
impl Decode<'_, MySql> for u8
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 u32
impl Decode<'_, MySql> for u32
fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, MySql> for u64
impl Decode<'_, MySql> for u64
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 Decode<'_, MySql> for Vec<u8>
impl Decode<'_, MySql> for Vec<u8>
fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, MySql> for BigDecimal
impl Decode<'_, MySql> for BigDecimal
fn decode(value: MySqlValueRef<'_>) -> 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 Hyphenated
impl Decode<'_, MySql> for Hyphenated
fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, MySql> for Uuid
impl Decode<'_, MySql> for Uuid
fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Postgres> for IpNetwork
impl Decode<'_, Postgres> for IpNetwork
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 Decode<'_, Postgres> for f32
impl Decode<'_, Postgres> for f32
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Postgres> for f64
impl Decode<'_, Postgres> for f64
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Postgres> for i8
impl Decode<'_, Postgres> for i8
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Postgres> for i16
impl Decode<'_, Postgres> for i16
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Postgres> for i32
impl Decode<'_, Postgres> for i32
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Postgres> for i64
impl Decode<'_, Postgres> for i64
fn decode(value: PgValueRef<'_>) -> 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 Vec<u8>
impl Decode<'_, Postgres> for Vec<u8>
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Postgres> for BigDecimal
impl Decode<'_, Postgres> for BigDecimal
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Postgres> for BitVec
impl Decode<'_, Postgres> for BitVec
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Postgres> for MacAddress
impl Decode<'_, Postgres> for MacAddress
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Postgres> for Decimal
impl Decode<'_, Postgres> for Decimal
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Postgres> for Uuid
impl Decode<'_, Postgres> for Uuid
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Sqlite> for BigDecimal
impl Decode<'_, Sqlite> for BigDecimal
fn decode(value: SqliteValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Sqlite> for Decimal
impl Decode<'_, Sqlite> for Decimal
fn decode(value: SqliteValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Sqlite> for Hyphenated
impl Decode<'_, Sqlite> for Hyphenated
fn decode(value: SqliteValueRef<'_>) -> Result<Self, BoxDynError>
source§impl Decode<'_, Sqlite> for Uuid
impl Decode<'_, Sqlite> for Uuid
fn decode(value: SqliteValueRef<'_>) -> Result<Self, BoxDynError>
source§impl<'db> Decode<'db, Postgres> for IpAddrwhere
IpNetwork: Decode<'db, Postgres>,
impl<'db> Decode<'db, Postgres> for IpAddrwhere IpNetwork: Decode<'db, Postgres>,
fn decode(value: PgValueRef<'db>) -> 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, 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<'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<'r> Decode<'r, Any> for f32where
f32: AnyDecode<'r>,
impl<'r> Decode<'r, Any> for f32where f32: AnyDecode<'r>,
fn decode(value: AnyValueRef<'r>) -> Result<Self, BoxDynError>
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<'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, 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, Any> for i64where
i64: AnyDecode<'r>,
impl<'r> Decode<'r, Any> for i64where i64: AnyDecode<'r>,
fn decode(value: AnyValueRef<'r>) -> 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<'r> Decode<'r, Any> for Vec<u8>where
Vec<u8>: AnyDecode<'r>,
impl<'r> Decode<'r, Any> for Vec<u8>where Vec<u8>: AnyDecode<'r>,
fn decode(value: AnyValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Any> for BigDecimalwhere
BigDecimal: AnyDecode<'r>,
impl<'r> Decode<'r, Any> for BigDecimalwhere BigDecimal: AnyDecode<'r>,
fn decode(value: AnyValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Any> for DateTime<Local>where
DateTime<Local>: AnyDecode<'r>,
impl<'r> Decode<'r, Any> for DateTime<Local>where DateTime<Local>: AnyDecode<'r>,
fn decode(value: AnyValueRef<'r>) -> 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<'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<'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<'r> Decode<'r, Any> for NaiveTimewhere
NaiveTime: AnyDecode<'r>,
impl<'r> Decode<'r, Any> for NaiveTimewhere NaiveTime: AnyDecode<'r>,
fn decode(value: AnyValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, Any> for Decimalwhere
Decimal: AnyDecode<'r>,
impl<'r> Decode<'r, Any> for Decimalwhere Decimal: AnyDecode<'r>,
fn decode(value: AnyValueRef<'r>) -> 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<'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, Mssql> for Cow<'r, [u8]>
impl<'r> Decode<'r, Mssql> for Cow<'r, [u8]>
fn decode(value: MssqlValueRef<'r>) -> Result<Self, BoxDynError>
source§impl<'r> Decode<'r, MySql> for &'r str
impl<'r> Decode<'r, MySql> for &'r str
fn decode(value: MySqlValueRef<'r>) -> 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> 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, MySql> for DateTime<FixedOffset>
impl<'r> Decode<'r, MySql> for DateTime<FixedOffset>
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 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 DateTime<Utc>
impl<'r> Decode<'r, MySql> for DateTime<Utc>
Note: assumes the connection’s time_zone
is set to +00:00
(UTC).