diesel/query_dsl/
load_dsl.rs

1use super::RunQueryDsl;
2use backend::Backend;
3use connection::Connection;
4use deserialize::Queryable;
5use query_builder::{AsQuery, QueryFragment, QueryId};
6use result::QueryResult;
7use sql_types::HasSqlType;
8
9/// The `load` method
10///
11/// This trait should not be relied on directly by most apps. Its behavior is
12/// provided by [`RunQueryDsl`]. However, you may need a where clause on this trait
13/// to call `load` from generic code.
14///
15/// [`RunQueryDsl`]: ../trait.RunQueryDsl.html
16pub trait LoadQuery<Conn, U>: RunQueryDsl<Conn> {
17    /// Load this query
18    fn internal_load(self, conn: &Conn) -> QueryResult<Vec<U>>;
19}
20
21impl<Conn, T, U> LoadQuery<Conn, U> for T
22where
23    Conn: Connection,
24    Conn::Backend: HasSqlType<T::SqlType>,
25    T: AsQuery + RunQueryDsl<Conn>,
26    T::Query: QueryFragment<Conn::Backend> + QueryId,
27    U: Queryable<T::SqlType, Conn::Backend>,
28{
29    fn internal_load(self, conn: &Conn) -> QueryResult<Vec<U>> {
30        conn.query_by_index(self)
31    }
32}
33
34/// The `execute` method
35///
36/// This trait should not be relied on directly by most apps. Its behavior is
37/// provided by [`RunQueryDsl`]. However, you may need a where clause on this trait
38/// to call `execute` from generic code.
39///
40/// [`RunQueryDsl`]: ../trait.RunQueryDsl.html
41pub trait ExecuteDsl<Conn: Connection<Backend = DB>, DB: Backend = <Conn as Connection>::Backend>:
42    Sized
43{
44    /// Execute this command
45    fn execute(query: Self, conn: &Conn) -> QueryResult<usize>;
46}
47
48impl<Conn, DB, T> ExecuteDsl<Conn, DB> for T
49where
50    Conn: Connection<Backend = DB>,
51    DB: Backend,
52    T: QueryFragment<DB> + QueryId,
53{
54    fn execute(query: Self, conn: &Conn) -> QueryResult<usize> {
55        conn.execute_returning_count(&query)
56    }
57}