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
#[macro_use] extern crate itertools; extern crate modifier; extern crate postgres; use postgres::types::ToSql; use std::borrow::Cow; use std::fmt; pub use self::delete::Delete; pub use self::insert::Insert; pub use self::predicate::Predicate; pub use self::select::Select; pub use self::update::Update; pub use modifier::Set; pub use util::escape; mod delete; mod insert; mod predicate; mod select; mod update; mod util; #[derive(Debug)] pub struct Assignment<'a>(pub Cow<'static, str>, pub &'a ToSql); pub type Assignments<'a> = Vec<Assignment<'a>>; #[derive(Debug)] pub struct Condition<'a>(pub Cow<'static, str>, pub Predicate<'a>); pub type Conditions<'a> = Vec<Condition<'a>>; #[derive(Debug)] pub struct Selection(pub Cow<'static, str>); pub type Selections = Vec<Selection>; #[derive(Debug)] pub struct Order(pub Cow<'static, str>, pub Dir); pub type Orders = Vec<Order>; #[derive(Debug)] pub struct Query<'a>(pub String, pub Vec<&'a ToSql>); #[derive(Debug)] pub struct Limit(pub usize); impl fmt::Display for Limit { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(&self.0, f) } } #[derive(Debug)] pub struct Offset(pub usize); impl fmt::Display for Offset { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(&self.0, f) } } pub trait Statement<'a> { fn into_query(self) -> Query<'a>; } #[derive(Debug)] pub enum Dir { Asc, Desc, } impl fmt::Display for Dir { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { match *self { Dir::Asc => fmt::Display::fmt("ASC", f), Dir::Desc => fmt::Display::fmt("DESC", f), } } }