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<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<'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>,