Trait diesel::deserialize::Queryable
[−]
[src]
pub trait Queryable<ST, DB> where
DB: Backend, { type Row: FromSqlRow<ST, DB>; fn build(row: Self::Row) -> Self; }
Trait indicating that a record can be queried from the database.
Types which implement Queryable
represent the result of a SQL query. This
does not necessarily mean they represent a single database table.
This trait can be derived automatically using #[derive(Queryable)]
. This
trait can only be derived for structs, not enums.
Diesel represents the return type of a query as a tuple. The purpose of this trait is to convert from a tuple of Rust values that have been deserialized into your struct.
When this trait is derived, it will assume that the order of fields on your
struct match the order of the fields in the query. This means that field
order is significant if you are using #[derive(Queryable)]
. Field name has
no affect.
Examples
If we just want to map a query to our struct, we can use derive
.
#[derive(Queryable, PartialEq, Debug)] struct User { id: i32, name: String, } let first_user = users.first(&connection)?; let expected = User { id: 1, name: "Sean".into() }; assert_eq!(expected, first_user);
If we want to do additional work during deserialization, we can implement the trait ourselves.
use schema::users; use diesel::deserialize::Queryable; type DB = diesel::sqlite::Sqlite; #[derive(PartialEq, Debug)] struct User { id: i32, name: String, } impl Queryable<users::SqlType, DB> for User { type Row = (i32, String); fn build(row: Self::Row) -> Self { User { id: row.0, name: row.1.to_lowercase(), } } } let first_user = users.first(&connection)?; let expected = User { id: 1, name: "sean".into() }; assert_eq!(expected, first_user);
Associated Types
type Row: FromSqlRow<ST, DB>
The Rust type you'd like to map from.
This is typically a tuple of all of your struct's fields.
Required Methods
Implementations on Foreign Types
impl<T, ST> Queryable<Range<ST>, Pg> for (Bound<T>, Bound<T>) where
T: FromSql<ST, Pg> + Queryable<ST, Pg>,
[src]
T: FromSql<ST, Pg> + Queryable<ST, Pg>,
impl<__ST, __DB> Queryable<__ST, __DB> for Timespec where
__DB: Backend,
Self: FromSql<__ST, __DB>,
[src]
__DB: Backend,
Self: FromSql<__ST, __DB>,
impl<__ST, __DB> Queryable<__ST, __DB> for [u8; 6] where
__DB: Backend,
Self: FromSql<__ST, __DB>,
[src]
__DB: Backend,
Self: FromSql<__ST, __DB>,
impl<__ST, __DB> Queryable<__ST, __DB> for IpNetwork where
__DB: Backend,
Self: FromSql<__ST, __DB>,
[src]
__DB: Backend,
Self: FromSql<__ST, __DB>,
impl<__ST, __DB> Queryable<__ST, __DB> for Uuid where
__DB: Backend,
Self: FromSql<__ST, __DB>,
[src]
__DB: Backend,
Self: FromSql<__ST, __DB>,
impl<__ST, __DB> Queryable<__ST, __DB> for Value where
__DB: Backend,
Self: FromSql<__ST, __DB>,
[src]
__DB: Backend,
Self: FromSql<__ST, __DB>,
impl<__ST, __DB> Queryable<__ST, __DB> for SystemTime where
__DB: Backend,
Self: FromSql<__ST, __DB>,
[src]
__DB: Backend,
Self: FromSql<__ST, __DB>,
impl<__ST, __DB> Queryable<__ST, __DB> for NaiveDate where
__DB: Backend,
Self: FromSql<__ST, __DB>,
[src]
__DB: Backend,
Self: FromSql<__ST, __DB>,
impl<__ST, __DB> Queryable<__ST, __DB> for NaiveTime where
__DB: Backend,
Self: FromSql<__ST, __DB>,
[src]
__DB: Backend,
Self: FromSql<__ST, __DB>,
impl<__ST, __DB> Queryable<__ST, __DB> for NaiveDateTime where
__DB: Backend,
Self: FromSql<__ST, __DB>,
[src]
__DB: Backend,
Self: FromSql<__ST, __DB>,
impl<Tz: TimeZone, __ST, __DB> Queryable<__ST, __DB> for DateTime<Tz> where
__DB: Backend,
Self: FromSql<__ST, __DB>,
[src]
__DB: Backend,
Self: FromSql<__ST, __DB>,
impl<T, ST, DB> Queryable<Nullable<ST>, DB> for Option<T> where
T: Queryable<ST, DB>,
DB: Backend,
Option<T::Row>: FromSqlRow<Nullable<ST>, DB>,
ST: NotNull,
[src]
T: Queryable<ST, DB>,
DB: Backend,
Option<T::Row>: FromSqlRow<Nullable<ST>, DB>,
ST: NotNull,
impl<__ST, __DB> Queryable<__ST, __DB> for bool where
__DB: Backend,
Self: FromSql<__ST, __DB>,
[src]
__DB: Backend,
Self: FromSql<__ST, __DB>,
impl<__ST, __DB> Queryable<__ST, __DB> for i8 where
__DB: Backend,
Self: FromSql<__ST, __DB>,
[src]
__DB: Backend,
Self: FromSql<__ST, __DB>,
impl<__ST, __DB> Queryable<__ST, __DB> for i16 where
__DB: Backend,
Self: FromSql<__ST, __DB>,
[src]
__DB: Backend,
Self: FromSql<__ST, __DB>,
impl<__ST, __DB> Queryable<__ST, __DB> for i32 where
__DB: Backend,
Self: FromSql<__ST, __DB>,
[src]
__DB: Backend,
Self: FromSql<__ST, __DB>,
impl<__ST, __DB> Queryable<__ST, __DB> for i64 where
__DB: Backend,
Self: FromSql<__ST, __DB>,
[src]
__DB: Backend,
Self: FromSql<__ST, __DB>,
impl<__ST, __DB> Queryable<__ST, __DB> for u16 where
__DB: Backend,
Self: FromSql<__ST, __DB>,
[src]
__DB: Backend,
Self: FromSql<__ST, __DB>,
impl<__ST, __DB> Queryable<__ST, __DB> for u32 where
__DB: Backend,
Self: FromSql<__ST, __DB>,
[src]
__DB: Backend,
Self: FromSql<__ST, __DB>,
impl<__ST, __DB> Queryable<__ST, __DB> for u64 where
__DB: Backend,
Self: FromSql<__ST, __DB>,
[src]
__DB: Backend,
Self: FromSql<__ST, __DB>,
impl<__ST, __DB> Queryable<__ST, __DB> for f32 where
__DB: Backend,
Self: FromSql<__ST, __DB>,
[src]
__DB: Backend,
Self: FromSql<__ST, __DB>,
impl<__ST, __DB> Queryable<__ST, __DB> for f64 where
__DB: Backend,
Self: FromSql<__ST, __DB>,
[src]
__DB: Backend,
Self: FromSql<__ST, __DB>,
impl<__ST, __DB> Queryable<__ST, __DB> for String where
__DB: Backend,
Self: FromSql<__ST, __DB>,
[src]
__DB: Backend,
Self: FromSql<__ST, __DB>,
impl<T, __ST, __DB> Queryable<__ST, __DB> for Vec<T> where
__DB: Backend,
Self: FromSql<__ST, __DB>,
[src]
__DB: Backend,
Self: FromSql<__ST, __DB>,
impl<'a, T: ?Sized, ST, DB> Queryable<ST, DB> for Cow<'a, T> where
T: 'a + ToOwned,
DB: Backend,
Self: FromSqlRow<ST, DB>,
[src]
T: 'a + ToOwned,
DB: Backend,
Self: FromSqlRow<ST, DB>,
impl<A, SA, __DB> Queryable<(SA,), __DB> for (A,) where
__DB: Backend,
A: Queryable<SA, __DB>,
[src]
__DB: Backend,
A: Queryable<SA, __DB>,
impl<A, B, SA, SB, __DB> Queryable<(SA, SB), __DB> for (A, B) where
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
[src]
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
impl<A, B, C, SA, SB, SC, __DB> Queryable<(SA, SB, SC), __DB> for (A, B, C) where
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
[src]
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
impl<A, B, C, D, SA, SB, SC, SD, __DB> Queryable<(SA, SB, SC, SD), __DB> for (A, B, C, D) where
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
D: Queryable<SD, __DB>,
[src]
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
D: Queryable<SD, __DB>,
impl<A, B, C, D, E, SA, SB, SC, SD, SE, __DB> Queryable<(SA, SB, SC, SD, SE), __DB> for (A, B, C, D, E) where
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
D: Queryable<SD, __DB>,
E: Queryable<SE, __DB>,
[src]
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
D: Queryable<SD, __DB>,
E: Queryable<SE, __DB>,
impl<A, B, C, D, E, F, SA, SB, SC, SD, SE, SF, __DB> Queryable<(SA, SB, SC, SD, SE, SF), __DB> for (A, B, C, D, E, F) where
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
D: Queryable<SD, __DB>,
E: Queryable<SE, __DB>,
F: Queryable<SF, __DB>,
[src]
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
D: Queryable<SD, __DB>,
E: Queryable<SE, __DB>,
F: Queryable<SF, __DB>,
impl<A, B, C, D, E, F, G, SA, SB, SC, SD, SE, SF, SG, __DB> Queryable<(SA, SB, SC, SD, SE, SF, SG), __DB> for (A, B, C, D, E, F, G) where
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
D: Queryable<SD, __DB>,
E: Queryable<SE, __DB>,
F: Queryable<SF, __DB>,
G: Queryable<SG, __DB>,
[src]
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
D: Queryable<SD, __DB>,
E: Queryable<SE, __DB>,
F: Queryable<SF, __DB>,
G: Queryable<SG, __DB>,
impl<A, B, C, D, E, F, G, H, SA, SB, SC, SD, SE, SF, SG, SH, __DB> Queryable<(SA, SB, SC, SD, SE, SF, SG, SH), __DB> for (A, B, C, D, E, F, G, H) where
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
D: Queryable<SD, __DB>,
E: Queryable<SE, __DB>,
F: Queryable<SF, __DB>,
G: Queryable<SG, __DB>,
H: Queryable<SH, __DB>,
[src]
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
D: Queryable<SD, __DB>,
E: Queryable<SE, __DB>,
F: Queryable<SF, __DB>,
G: Queryable<SG, __DB>,
H: Queryable<SH, __DB>,
impl<A, B, C, D, E, F, G, H, I, SA, SB, SC, SD, SE, SF, SG, SH, SI, __DB> Queryable<(SA, SB, SC, SD, SE, SF, SG, SH, SI), __DB> for (A, B, C, D, E, F, G, H, I) where
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
D: Queryable<SD, __DB>,
E: Queryable<SE, __DB>,
F: Queryable<SF, __DB>,
G: Queryable<SG, __DB>,
H: Queryable<SH, __DB>,
I: Queryable<SI, __DB>,
[src]
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
D: Queryable<SD, __DB>,
E: Queryable<SE, __DB>,
F: Queryable<SF, __DB>,
G: Queryable<SG, __DB>,
H: Queryable<SH, __DB>,
I: Queryable<SI, __DB>,
impl<A, B, C, D, E, F, G, H, I, J, SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, __DB> Queryable<(SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ), __DB> for (A, B, C, D, E, F, G, H, I, J) where
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
D: Queryable<SD, __DB>,
E: Queryable<SE, __DB>,
F: Queryable<SF, __DB>,
G: Queryable<SG, __DB>,
H: Queryable<SH, __DB>,
I: Queryable<SI, __DB>,
J: Queryable<SJ, __DB>,
[src]
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
D: Queryable<SD, __DB>,
E: Queryable<SE, __DB>,
F: Queryable<SF, __DB>,
G: Queryable<SG, __DB>,
H: Queryable<SH, __DB>,
I: Queryable<SI, __DB>,
J: Queryable<SJ, __DB>,
impl<A, B, C, D, E, F, G, H, I, J, K, SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, __DB> Queryable<(SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK), __DB> for (A, B, C, D, E, F, G, H, I, J, K) where
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
D: Queryable<SD, __DB>,
E: Queryable<SE, __DB>,
F: Queryable<SF, __DB>,
G: Queryable<SG, __DB>,
H: Queryable<SH, __DB>,
I: Queryable<SI, __DB>,
J: Queryable<SJ, __DB>,
K: Queryable<SK, __DB>,
[src]
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
D: Queryable<SD, __DB>,
E: Queryable<SE, __DB>,
F: Queryable<SF, __DB>,
G: Queryable<SG, __DB>,
H: Queryable<SH, __DB>,
I: Queryable<SI, __DB>,
J: Queryable<SJ, __DB>,
K: Queryable<SK, __DB>,
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, __DB> Queryable<(SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, SL), __DB> for (A, B, C, D, E, F, G, H, I, J, K, L) where
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
D: Queryable<SD, __DB>,
E: Queryable<SE, __DB>,
F: Queryable<SF, __DB>,
G: Queryable<SG, __DB>,
H: Queryable<SH, __DB>,
I: Queryable<SI, __DB>,
J: Queryable<SJ, __DB>,
K: Queryable<SK, __DB>,
L: Queryable<SL, __DB>,
[src]
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
D: Queryable<SD, __DB>,
E: Queryable<SE, __DB>,
F: Queryable<SF, __DB>,
G: Queryable<SG, __DB>,
H: Queryable<SH, __DB>,
I: Queryable<SI, __DB>,
J: Queryable<SJ, __DB>,
K: Queryable<SK, __DB>,
L: Queryable<SL, __DB>,
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, __DB> Queryable<(SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, SL, SM), __DB> for (A, B, C, D, E, F, G, H, I, J, K, L, M) where
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
D: Queryable<SD, __DB>,
E: Queryable<SE, __DB>,
F: Queryable<SF, __DB>,
G: Queryable<SG, __DB>,
H: Queryable<SH, __DB>,
I: Queryable<SI, __DB>,
J: Queryable<SJ, __DB>,
K: Queryable<SK, __DB>,
L: Queryable<SL, __DB>,
M: Queryable<SM, __DB>,
[src]
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
D: Queryable<SD, __DB>,
E: Queryable<SE, __DB>,
F: Queryable<SF, __DB>,
G: Queryable<SG, __DB>,
H: Queryable<SH, __DB>,
I: Queryable<SI, __DB>,
J: Queryable<SJ, __DB>,
K: Queryable<SK, __DB>,
L: Queryable<SL, __DB>,
M: Queryable<SM, __DB>,
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, __DB> Queryable<(SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, SL, SM, SN), __DB> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N) where
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
D: Queryable<SD, __DB>,
E: Queryable<SE, __DB>,
F: Queryable<SF, __DB>,
G: Queryable<SG, __DB>,
H: Queryable<SH, __DB>,
I: Queryable<SI, __DB>,
J: Queryable<SJ, __DB>,
K: Queryable<SK, __DB>,
L: Queryable<SL, __DB>,
M: Queryable<SM, __DB>,
N: Queryable<SN, __DB>,
[src]
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
D: Queryable<SD, __DB>,
E: Queryable<SE, __DB>,
F: Queryable<SF, __DB>,
G: Queryable<SG, __DB>,
H: Queryable<SH, __DB>,
I: Queryable<SI, __DB>,
J: Queryable<SJ, __DB>,
K: Queryable<SK, __DB>,
L: Queryable<SL, __DB>,
M: Queryable<SM, __DB>,
N: Queryable<SN, __DB>,
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, __DB> Queryable<(SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, SL, SM, SN, SO), __DB> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O) where
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
D: Queryable<SD, __DB>,
E: Queryable<SE, __DB>,
F: Queryable<SF, __DB>,
G: Queryable<SG, __DB>,
H: Queryable<SH, __DB>,
I: Queryable<SI, __DB>,
J: Queryable<SJ, __DB>,
K: Queryable<SK, __DB>,
L: Queryable<SL, __DB>,
M: Queryable<SM, __DB>,
N: Queryable<SN, __DB>,
O: Queryable<SO, __DB>,
[src]
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
D: Queryable<SD, __DB>,
E: Queryable<SE, __DB>,
F: Queryable<SF, __DB>,
G: Queryable<SG, __DB>,
H: Queryable<SH, __DB>,
I: Queryable<SI, __DB>,
J: Queryable<SJ, __DB>,
K: Queryable<SK, __DB>,
L: Queryable<SL, __DB>,
M: Queryable<SM, __DB>,
N: Queryable<SN, __DB>,
O: Queryable<SO, __DB>,
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, __DB> Queryable<(SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, SL, SM, SN, SO, SP), __DB> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) where
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
D: Queryable<SD, __DB>,
E: Queryable<SE, __DB>,
F: Queryable<SF, __DB>,
G: Queryable<SG, __DB>,
H: Queryable<SH, __DB>,
I: Queryable<SI, __DB>,
J: Queryable<SJ, __DB>,
K: Queryable<SK, __DB>,
L: Queryable<SL, __DB>,
M: Queryable<SM, __DB>,
N: Queryable<SN, __DB>,
O: Queryable<SO, __DB>,
P: Queryable<SP, __DB>,
[src]
__DB: Backend,
A: Queryable<SA, __DB>,
B: Queryable<SB, __DB>,
C: Queryable<SC, __DB>,
D: Queryable<SD, __DB>,
E: Queryable<SE, __DB>,
F: Queryable<SF, __DB>,
G: Queryable<SG, __DB>,
H: Queryable<SH, __DB>,
I: Queryable<SI, __DB>,
J: Queryable<SJ, __DB>,
K: Queryable<SK, __DB>,
L: Queryable<SL, __DB>,
M: Queryable<SM, __DB>,
N: Queryable<SN, __DB>,
O: Queryable<SO, __DB>,
P: Queryable<SP, __DB>,
impl<__ST, __DB> Queryable<__ST, __DB> for BigDecimal where
__DB: Backend,
Self: FromSql<__ST, __DB>,
[src]
__DB: Backend,
Self: FromSql<__ST, __DB>,
Implementors
impl<__ST, __DB> Queryable<__ST, __DB> for PgTimestamp where
__DB: Backend,
Self: FromSql<__ST, __DB>, type Row = Self;impl<__ST, __DB> Queryable<__ST, __DB> for PgDate where
__DB: Backend,
Self: FromSql<__ST, __DB>, type Row = Self;impl<__ST, __DB> Queryable<__ST, __DB> for PgTime where
__DB: Backend,
Self: FromSql<__ST, __DB>, type Row = Self;impl<__ST, __DB> Queryable<__ST, __DB> for PgInterval where
__DB: Backend,
Self: FromSql<__ST, __DB>, type Row = Self;impl<__ST, __DB> Queryable<__ST, __DB> for PgNumeric where
__DB: Backend,
Self: FromSql<__ST, __DB>, type Row = Self;impl<__ST, __DB> Queryable<__ST, __DB> for PgMoney where
__DB: Backend,
Self: FromSql<__ST, __DB>, type Row = Self;impl Queryable<(Oid, Oid), Pg> for PgTypeMetadata type Row = (u32, u32);