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

The Rust type you'd like to map from.

This is typically a tuple of all of your struct's fields.

Required Methods

Construct an instance of this type

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]

[src]

impl<__ST, __DB> Queryable<__ST, __DB> for Timespec where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[src]

[src]

impl<__ST, __DB> Queryable<__ST, __DB> for [u8; 6] where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[src]

[src]

impl<__ST, __DB> Queryable<__ST, __DB> for IpNetwork where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[src]

[src]

impl<__ST, __DB> Queryable<__ST, __DB> for Uuid where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[src]

[src]

impl<__ST, __DB> Queryable<__ST, __DB> for Value where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[src]

[src]

impl<__ST, __DB> Queryable<__ST, __DB> for SystemTime where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[src]

[src]

impl<__ST, __DB> Queryable<__ST, __DB> for NaiveDate where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[src]

[src]

impl<__ST, __DB> Queryable<__ST, __DB> for NaiveTime where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[src]

[src]

impl<__ST, __DB> Queryable<__ST, __DB> for NaiveDateTime where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[src]

[src]

impl<Tz: TimeZone, __ST, __DB> Queryable<__ST, __DB> for DateTime<Tz> where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[src]

[src]

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]

[src]

impl<__ST, __DB> Queryable<__ST, __DB> for bool where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[src]

[src]

impl<__ST, __DB> Queryable<__ST, __DB> for i8 where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[src]

[src]

impl<__ST, __DB> Queryable<__ST, __DB> for i16 where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[src]

[src]

impl<__ST, __DB> Queryable<__ST, __DB> for i32 where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[src]

[src]

impl<__ST, __DB> Queryable<__ST, __DB> for i64 where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[src]

[src]

impl<__ST, __DB> Queryable<__ST, __DB> for u16 where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[src]

[src]

impl<__ST, __DB> Queryable<__ST, __DB> for u32 where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[src]

[src]

impl<__ST, __DB> Queryable<__ST, __DB> for u64 where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[src]

[src]

impl<__ST, __DB> Queryable<__ST, __DB> for f32 where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[src]

[src]

impl<__ST, __DB> Queryable<__ST, __DB> for f64 where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[src]

[src]

impl<__ST, __DB> Queryable<__ST, __DB> for String where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[src]

[src]

impl<T, __ST, __DB> Queryable<__ST, __DB> for Vec<T> where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[src]

[src]

impl<'a, T: ?Sized, ST, DB> Queryable<ST, DB> for Cow<'a, T> where
    T: 'a + ToOwned,
    DB: Backend,
    Self: FromSqlRow<ST, DB>, 
[src]

[src]

impl<A, SA, __DB> Queryable<(SA,), __DB> for (A,) where
    __DB: Backend,
    A: Queryable<SA, __DB>, 
[src]

[src]

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]

[src]

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]

[src]

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]

[src]

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]

[src]

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]

[src]

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]

[src]

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]

[src]

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]

[src]

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]

[src]

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]

[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, __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]

[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, __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]

[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, __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]

[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, __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]

[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, __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]

[src]

impl<__ST, __DB> Queryable<__ST, __DB> for BigDecimal where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[src]

[src]

Implementors