1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
pub mod debug;
mod delete_statement;
#[doc(hidden)]
pub mod functions;
#[doc(hidden)]
pub mod nodes;
#[macro_use]
mod clause_macro;
mod group_by_clause;
mod limit_clause;
mod offset_clause;
mod order_clause;
mod select_statement;
mod where_clause;
pub mod insert_statement;
pub mod update_statement;
#[doc(hidden)]
pub use self::select_statement::SelectStatement;
#[doc(inline)]
pub use self::update_statement::{IncompleteUpdateStatement, AsChangeset, Changeset, UpdateTarget};
#[doc(inline)]
pub use self::insert_statement::IncompleteInsertStatement;
use std::error::Error;
use backend::Backend;
use types::HasSqlType;
#[doc(hidden)]
pub type Binds = Vec<Option<Vec<u8>>>;
pub type BuildQueryResult = Result<(), Box<Error>>;
pub trait QueryBuilder<DB: Backend> {
fn push_sql(&mut self, sql: &str);
fn push_identifier(&mut self, identifier: &str) -> BuildQueryResult;
fn push_bound_value<T>(&mut self, binds: Option<Vec<u8>>) where
DB: HasSqlType<T>;
}
pub trait Query {
type SqlType;
}
impl<'a, T: Query> Query for &'a T {
type SqlType = T::SqlType;
}
pub trait QueryFragment<DB: Backend> {
fn to_sql(&self, out: &mut DB::QueryBuilder) -> BuildQueryResult;
}
impl<T: ?Sized, DB> QueryFragment<DB> for Box<T> where
DB: Backend,
T: QueryFragment<DB>,
{
fn to_sql(&self, out: &mut DB::QueryBuilder) -> BuildQueryResult {
QueryFragment::to_sql(&**self, out)
}
}
impl<'a, T: ?Sized, DB> QueryFragment<DB> for &'a T where
DB: Backend,
T: QueryFragment<DB>,
{
fn to_sql(&self, out: &mut DB::QueryBuilder) -> BuildQueryResult {
QueryFragment::to_sql(&**self, out)
}
}
impl<DB: Backend> QueryFragment<DB> for () {
fn to_sql(&self, _out: &mut DB::QueryBuilder) -> BuildQueryResult {
Ok(())
}
}
pub trait AsQuery {
type SqlType;
type Query: Query<SqlType=Self::SqlType>;
fn as_query(self) -> Self::Query;
}
impl<T: Query> AsQuery for T {
type SqlType = <Self as Query>::SqlType;
type Query = Self;
fn as_query(self) -> Self::Query {
self
}
}