Trait diesel::types::FromSql
[−]
[src]
pub trait FromSql<A, DB: Backend + HasSqlType<A>>: Sized { fn from_sql(
bytes: Option<&DB::RawValue>
) -> Result<Self, Box<Error + Send + Sync>>; }
Deserialize a single field of a given SQL type.
When possible, implementations of this trait should prefer to use an
existing implementation, rather than reading from bytes
. (For example, if
you are implementing this for an enum which is represented as an integer in
the database, prefer i32::from_sql(bytes)
over reading from bytes
directly)
Backend specific details
- For PostgreSQL, the bytes will be sent using the binary protocol, not text.
- For SQLite, the actual type of
DB::RawValue
is private API. All implementations of this trait must be written in terms of an existing primitive. - For MySQL, the value of
bytes
will depend on the return value oftype_metadata
for the given SQL type. SeeMysqlType
for details. - For third party backends, consult that backend's documentation.
Required Methods
fn from_sql(
bytes: Option<&DB::RawValue>
) -> Result<Self, Box<Error + Send + Sync>>
bytes: Option<&DB::RawValue>
) -> Result<Self, Box<Error + Send + Sync>>
See the trait documentation.
Implementations on Foreign Types
impl<DB: Backend<RawValue = [u8]>> FromSql<Float, DB> for f32
[src]
impl<DB: Backend<RawValue = [u8]>> FromSql<Double, DB> for f64
[src]
impl<DB: Backend<RawValue = [u8]>> FromSql<SmallInt, DB> for i16
[src]
impl<DB: Backend<RawValue = [u8]>> FromSql<Integer, DB> for i32
[src]
impl<DB: Backend<RawValue = [u8]>> FromSql<BigInt, DB> for i64
[src]
impl<T, ST, DB> FromSql<Nullable<ST>, DB> for Option<T> where
T: FromSql<ST, DB>,
DB: Backend + HasSqlType<ST>,
ST: NotNull,
[src]
T: FromSql<ST, DB>,
DB: Backend + HasSqlType<ST>,
ST: NotNull,
impl<DB: Backend<RawValue = [u8]>> FromSql<Text, DB> for String
[src]
impl<DB: Backend<RawValue = [u8]>> FromSql<Binary, DB> for Vec<u8>
[src]
impl<'a, T: ?Sized, ST, DB> FromSql<ST, DB> for Cow<'a, T> where
T: 'a + ToOwned,
DB: Backend + HasSqlType<ST>,
T::Owned: FromSql<ST, DB>,
[src]
T: 'a + ToOwned,
DB: Backend + HasSqlType<ST>,
T::Owned: FromSql<ST, DB>,
impl FromSql<Datetime, Mysql> for MYSQL_TIME
[src]
impl FromSql<Timestamp, Mysql> for MYSQL_TIME
[src]
impl FromSql<Time, Mysql> for MYSQL_TIME
[src]
impl FromSql<Date, Mysql> for MYSQL_TIME
[src]
impl FromSql<Datetime, Mysql> for NaiveDateTime
[src]
impl FromSql<Timestamp, Mysql> for NaiveDateTime
[src]
impl FromSql<Time, Mysql> for NaiveTime
[src]
impl FromSql<Date, Mysql> for NaiveDate
[src]
impl FromSql<Numeric, Mysql> for BigDecimal
[src]
impl FromSql<Tinyint, Mysql> for i8
[src]
impl FromSql<Bool, Mysql> for bool
[src]
impl<T, ST> FromSql<Array<ST>, Pg> for Vec<T> where
T: FromSql<ST, Pg>,
Pg: HasSqlType<ST>,
[src]
T: FromSql<ST, Pg>,
Pg: HasSqlType<ST>,
impl<T, ST> FromSql<Range<ST>, Pg> for (Bound<T>, Bound<T>) where
T: FromSql<ST, Pg>,
Pg: HasSqlType<ST> + HasSqlType<Range<ST>>,
[src]
T: FromSql<ST, Pg>,
Pg: HasSqlType<ST> + HasSqlType<Range<ST>>,