Trait diesel::deserialize::FromSql [−][src]
pub trait FromSql<A, DB: Backend>: Sized { fn from_sql(bytes: Option<&DB::RawValue>) -> Result<Self>; }
Expand description
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)
Types which implement this trait should also have #[derive(FromSqlRow)]
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.
Examples
Most implementations of this trait will be defined in terms of an existing implementation.
#[repr(i32)] #[derive(Debug, Clone, Copy)] pub enum MyEnum { A = 1, B = 2, } impl<DB> FromSql<Integer, DB> for MyEnum where DB: Backend, i32: FromSql<Integer, DB>, { fn from_sql(bytes: Option<&DB::RawValue>) -> deserialize::Result<Self> { match i32::from_sql(bytes)? { 1 => Ok(MyEnum::A), 2 => Ok(MyEnum::B), x => Err(format!("Unrecognized variant {}", x).into()), } } }
Required methods
Implementations on Foreign Types
impl<A, B, C, D, E, F, G, H, SA, SB, SC, SD, SE, SF, SG, SH> FromSql<Record<(SA, SB, SC, SD, SE, SF, SG, SH)>, Pg> for (A, B, C, D, E, F, G, H) where
A: FromSql<SA, Pg>,
B: FromSql<SB, Pg>,
C: FromSql<SC, Pg>,
D: FromSql<SD, Pg>,
E: FromSql<SE, Pg>,
F: FromSql<SF, Pg>,
G: FromSql<SG, Pg>,
H: FromSql<SH, Pg>,
[src]
impl<A, B, C, D, E, F, G, H, SA, SB, SC, SD, SE, SF, SG, SH> FromSql<Record<(SA, SB, SC, SD, SE, SF, SG, SH)>, Pg> for (A, B, C, D, E, F, G, H) where
A: FromSql<SA, Pg>,
B: FromSql<SB, Pg>,
C: FromSql<SC, Pg>,
D: FromSql<SD, Pg>,
E: FromSql<SE, Pg>,
F: FromSql<SF, Pg>,
G: FromSql<SG, Pg>,
H: FromSql<SH, Pg>,
[src]impl<A, B, C, D, E, F, G, H, I, SA, SB, SC, SD, SE, SF, SG, SH, SI> FromSql<Record<(SA, SB, SC, SD, SE, SF, SG, SH, SI)>, Pg> for (A, B, C, D, E, F, G, H, I) where
A: FromSql<SA, Pg>,
B: FromSql<SB, Pg>,
C: FromSql<SC, Pg>,
D: FromSql<SD, Pg>,
E: FromSql<SE, Pg>,
F: FromSql<SF, Pg>,
G: FromSql<SG, Pg>,
H: FromSql<SH, Pg>,
I: FromSql<SI, Pg>,
[src]
impl<A, B, C, D, E, F, G, H, I, SA, SB, SC, SD, SE, SF, SG, SH, SI> FromSql<Record<(SA, SB, SC, SD, SE, SF, SG, SH, SI)>, Pg> for (A, B, C, D, E, F, G, H, I) where
A: FromSql<SA, Pg>,
B: FromSql<SB, Pg>,
C: FromSql<SC, Pg>,
D: FromSql<SD, Pg>,
E: FromSql<SE, Pg>,
F: FromSql<SF, Pg>,
G: FromSql<SG, Pg>,
H: FromSql<SH, Pg>,
I: FromSql<SI, Pg>,
[src]impl<A, B, C, D, E, F, G, H, I, J, SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ> FromSql<Record<(SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ)>, Pg> for (A, B, C, D, E, F, G, H, I, J) where
A: FromSql<SA, Pg>,
B: FromSql<SB, Pg>,
C: FromSql<SC, Pg>,
D: FromSql<SD, Pg>,
E: FromSql<SE, Pg>,
F: FromSql<SF, Pg>,
G: FromSql<SG, Pg>,
H: FromSql<SH, Pg>,
I: FromSql<SI, Pg>,
J: FromSql<SJ, Pg>,
[src]
impl<A, B, C, D, E, F, G, H, I, J, SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ> FromSql<Record<(SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ)>, Pg> for (A, B, C, D, E, F, G, H, I, J) where
A: FromSql<SA, Pg>,
B: FromSql<SB, Pg>,
C: FromSql<SC, Pg>,
D: FromSql<SD, Pg>,
E: FromSql<SE, Pg>,
F: FromSql<SF, Pg>,
G: FromSql<SG, Pg>,
H: FromSql<SH, Pg>,
I: FromSql<SI, Pg>,
J: FromSql<SJ, Pg>,
[src]impl<A, B, C, D, E, F, G, H, I, J, K, SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK> FromSql<Record<(SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK)>, Pg> for (A, B, C, D, E, F, G, H, I, J, K) where
A: FromSql<SA, Pg>,
B: FromSql<SB, Pg>,
C: FromSql<SC, Pg>,
D: FromSql<SD, Pg>,
E: FromSql<SE, Pg>,
F: FromSql<SF, Pg>,
G: FromSql<SG, Pg>,
H: FromSql<SH, Pg>,
I: FromSql<SI, Pg>,
J: FromSql<SJ, Pg>,
K: FromSql<SK, Pg>,
[src]
impl<A, B, C, D, E, F, G, H, I, J, K, SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK> FromSql<Record<(SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK)>, Pg> for (A, B, C, D, E, F, G, H, I, J, K) where
A: FromSql<SA, Pg>,
B: FromSql<SB, Pg>,
C: FromSql<SC, Pg>,
D: FromSql<SD, Pg>,
E: FromSql<SE, Pg>,
F: FromSql<SF, Pg>,
G: FromSql<SG, Pg>,
H: FromSql<SH, Pg>,
I: FromSql<SI, Pg>,
J: FromSql<SJ, Pg>,
K: FromSql<SK, Pg>,
[src]impl<A, B, C, D, E, F, G, H, I, J, K, L, SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, SL> FromSql<Record<(SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, SL)>, Pg> for (A, B, C, D, E, F, G, H, I, J, K, L) where
A: FromSql<SA, Pg>,
B: FromSql<SB, Pg>,
C: FromSql<SC, Pg>,
D: FromSql<SD, Pg>,
E: FromSql<SE, Pg>,
F: FromSql<SF, Pg>,
G: FromSql<SG, Pg>,
H: FromSql<SH, Pg>,
I: FromSql<SI, Pg>,
J: FromSql<SJ, Pg>,
K: FromSql<SK, Pg>,
L: FromSql<SL, Pg>,
[src]
impl<A, B, C, D, E, F, G, H, I, J, K, L, SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, SL> FromSql<Record<(SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, SL)>, Pg> for (A, B, C, D, E, F, G, H, I, J, K, L) where
A: FromSql<SA, Pg>,
B: FromSql<SB, Pg>,
C: FromSql<SC, Pg>,
D: FromSql<SD, Pg>,
E: FromSql<SE, Pg>,
F: FromSql<SF, Pg>,
G: FromSql<SG, Pg>,
H: FromSql<SH, Pg>,
I: FromSql<SI, Pg>,
J: FromSql<SJ, Pg>,
K: FromSql<SK, Pg>,
L: FromSql<SL, Pg>,
[src]impl<A, B, C, D, E, F, G, H, I, J, K, L, M, SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, SL, SM> FromSql<Record<(SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, SL, SM)>, Pg> for (A, B, C, D, E, F, G, H, I, J, K, L, M) where
A: FromSql<SA, Pg>,
B: FromSql<SB, Pg>,
C: FromSql<SC, Pg>,
D: FromSql<SD, Pg>,
E: FromSql<SE, Pg>,
F: FromSql<SF, Pg>,
G: FromSql<SG, Pg>,
H: FromSql<SH, Pg>,
I: FromSql<SI, Pg>,
J: FromSql<SJ, Pg>,
K: FromSql<SK, Pg>,
L: FromSql<SL, Pg>,
M: FromSql<SM, Pg>,
[src]
impl<A, B, C, D, E, F, G, H, I, J, K, L, M, SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, SL, SM> FromSql<Record<(SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, SL, SM)>, Pg> for (A, B, C, D, E, F, G, H, I, J, K, L, M) where
A: FromSql<SA, Pg>,
B: FromSql<SB, Pg>,
C: FromSql<SC, Pg>,
D: FromSql<SD, Pg>,
E: FromSql<SE, Pg>,
F: FromSql<SF, Pg>,
G: FromSql<SG, Pg>,
H: FromSql<SH, Pg>,
I: FromSql<SI, Pg>,
J: FromSql<SJ, Pg>,
K: FromSql<SK, Pg>,
L: FromSql<SL, Pg>,
M: FromSql<SM, Pg>,
[src]impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, SL, SM, SN> FromSql<Record<(SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, SL, SM, SN)>, Pg> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N) where
A: FromSql<SA, Pg>,
B: FromSql<SB, Pg>,
C: FromSql<SC, Pg>,
D: FromSql<SD, Pg>,
E: FromSql<SE, Pg>,
F: FromSql<SF, Pg>,
G: FromSql<SG, Pg>,
H: FromSql<SH, Pg>,
I: FromSql<SI, Pg>,
J: FromSql<SJ, Pg>,
K: FromSql<SK, Pg>,
L: FromSql<SL, Pg>,
M: FromSql<SM, Pg>,
N: FromSql<SN, Pg>,
[src]
impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, SL, SM, SN> FromSql<Record<(SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, SL, SM, SN)>, Pg> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N) where
A: FromSql<SA, Pg>,
B: FromSql<SB, Pg>,
C: FromSql<SC, Pg>,
D: FromSql<SD, Pg>,
E: FromSql<SE, Pg>,
F: FromSql<SF, Pg>,
G: FromSql<SG, Pg>,
H: FromSql<SH, Pg>,
I: FromSql<SI, Pg>,
J: FromSql<SJ, Pg>,
K: FromSql<SK, Pg>,
L: FromSql<SL, Pg>,
M: FromSql<SM, Pg>,
N: FromSql<SN, Pg>,
[src]impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, SL, SM, SN, SO> FromSql<Record<(SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, SL, SM, SN, SO)>, Pg> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O) where
A: FromSql<SA, Pg>,
B: FromSql<SB, Pg>,
C: FromSql<SC, Pg>,
D: FromSql<SD, Pg>,
E: FromSql<SE, Pg>,
F: FromSql<SF, Pg>,
G: FromSql<SG, Pg>,
H: FromSql<SH, Pg>,
I: FromSql<SI, Pg>,
J: FromSql<SJ, Pg>,
K: FromSql<SK, Pg>,
L: FromSql<SL, Pg>,
M: FromSql<SM, Pg>,
N: FromSql<SN, Pg>,
O: FromSql<SO, Pg>,
[src]
impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, SL, SM, SN, SO> FromSql<Record<(SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, SL, SM, SN, SO)>, Pg> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O) where
A: FromSql<SA, Pg>,
B: FromSql<SB, Pg>,
C: FromSql<SC, Pg>,
D: FromSql<SD, Pg>,
E: FromSql<SE, Pg>,
F: FromSql<SF, Pg>,
G: FromSql<SG, Pg>,
H: FromSql<SH, Pg>,
I: FromSql<SI, Pg>,
J: FromSql<SJ, Pg>,
K: FromSql<SK, Pg>,
L: FromSql<SL, Pg>,
M: FromSql<SM, Pg>,
N: FromSql<SN, Pg>,
O: FromSql<SO, Pg>,
[src]impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, SL, SM, SN, SO, SP> FromSql<Record<(SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, SL, SM, SN, SO, SP)>, Pg> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) where
A: FromSql<SA, Pg>,
B: FromSql<SB, Pg>,
C: FromSql<SC, Pg>,
D: FromSql<SD, Pg>,
E: FromSql<SE, Pg>,
F: FromSql<SF, Pg>,
G: FromSql<SG, Pg>,
H: FromSql<SH, Pg>,
I: FromSql<SI, Pg>,
J: FromSql<SJ, Pg>,
K: FromSql<SK, Pg>,
L: FromSql<SL, Pg>,
M: FromSql<SM, Pg>,
N: FromSql<SN, Pg>,
O: FromSql<SO, Pg>,
P: FromSql<SP, Pg>,
[src]
impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, SL, SM, SN, SO, SP> FromSql<Record<(SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, SL, SM, SN, SO, SP)>, Pg> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) where
A: FromSql<SA, Pg>,
B: FromSql<SB, Pg>,
C: FromSql<SC, Pg>,
D: FromSql<SD, Pg>,
E: FromSql<SE, Pg>,
F: FromSql<SF, Pg>,
G: FromSql<SG, Pg>,
H: FromSql<SH, Pg>,
I: FromSql<SI, Pg>,
J: FromSql<SJ, Pg>,
K: FromSql<SK, Pg>,
L: FromSql<SL, Pg>,
M: FromSql<SM, Pg>,
N: FromSql<SN, Pg>,
O: FromSql<SO, Pg>,
P: FromSql<SP, Pg>,
[src]The returned pointer is only valid for the lifetime to the argument of
from_sql
. This impl is intended for uses where you want to write a new
impl in terms of String
, but don’t want to allocate. We have to return a
raw pointer instead of a reference with a lifetime due to the structure of
FromSql
The returned pointer is only valid for the lifetime to the argument of
from_sql
. This impl is intended for uses where you want to write a new
impl in terms of String
, but don’t want to allocate. We have to return a
raw pointer instead of a reference with a lifetime due to the structure of
FromSql
The returned pointer is only valid for the lifetime to the argument of
from_sql
. This impl is intended for uses where you want to write a new
impl in terms of String
, but don’t want to allocate. We have to return a
raw pointer instead of a reference with a lifetime due to the structure of
FromSql
The returned pointer is only valid for the lifetime to the argument of
from_sql
. This impl is intended for uses where you want to write a new
impl in terms of String
, but don’t want to allocate. We have to return a
raw pointer instead of a reference with a lifetime due to the structure of
FromSql
The returned pointer is only valid for the lifetime to the argument of
from_sql
. This impl is intended for uses where you want to write a new
impl in terms of Vec<u8>
, but don’t want to allocate. We have to return a
raw pointer instead of a reference with a lifetime due to the structure of
FromSql
The returned pointer is only valid for the lifetime to the argument of
from_sql
. This impl is intended for uses where you want to write a new
impl in terms of String
, but don’t want to allocate. We have to return a
raw pointer instead of a reference with a lifetime due to the structure of
FromSql
The returned pointer is only valid for the lifetime to the argument of
from_sql
. This impl is intended for uses where you want to write a new
impl in terms of Vec<u8>
, but don’t want to allocate. We have to return a
raw pointer instead of a reference with a lifetime due to the structure of
FromSql