derive_sql/traits/
update.rs1use super::*;
2
3pub trait UpdateFlavoredStatement {
4 fn update_stmt<C, R>(&self, conn: &C) -> Result<String>
5 where C: Connection<R>, R: Row;
6
7 fn update_with_filter_stmt<C, R, F>(&self, conn: &C, filter: &F) -> Result<String>
8 where C: Connection<R>, R: Row, F: traits::FlavoredFilter
9 {
10 statement_with_conn_filter_order_limit_offset_options::<_, _, _, structs::order::None>(self.update_stmt(conn)?,
11 conn, Some(filter), None, None, None)
12 }
13
14 fn update_with_filter_order_limit_offset_stmt<C, R, F, O>(&self, conn: &C, filter: &F, order: &O, limit: usize, offset: usize) -> Result<String>
15 where C: Connection<R>, R: Row, F: FlavoredFilter, O: FlavoredOrder,
16 {
17 statement_with_conn_filter_order_limit_offset_options(self.update_stmt(conn)?,
18 conn, Some(filter), Some(order), Some(limit), Some(offset))
19 }
20}
21
22pub trait UpdateStatement {
23 fn update_stmt(&self) -> Result<String>;
24
25 fn update_with_filter_stmt<F>(&self, filter: &F) -> Result<String>
26 where F: Filter
27 {
28 statement_with_filter_order_limit_offset_options::<_, structs::order::None>(self.update_stmt()?,
29 Some(filter), None, None, None)
30 }
31
32 fn update_with_filter_order_limit_offset_stmt<F, O>(&self, filter: &F, order: &O, limit: usize, offset: usize) -> Result<String>
33 where F: Filter, O: Order,
34 {
35 statement_with_filter_order_limit_offset_options(self.update_stmt()?,
36 Some(filter), Some(order), Some(limit), Some(offset))
37 }
38}
39
40impl<U> UpdateFlavoredStatement for U
41where U: UpdateStatement
42{
43 fn update_stmt<C, R>(&self, _conn: &C) -> Result<String>
44 where C: Connection<R>, R: Row
45 {
46 UpdateStatement::update_stmt(self)
47 }
48}
49
50pub trait Update<C, R, T>
51where C: Connection<R>,
52 R: Row,
53{
54 fn update(&self, conn: &mut C, object: &T) -> Result<()>;
55
56 fn update_with_filter<F>(&self, conn: &mut C, filter: &F, object: &T) -> Result<()>
57 where F: traits::FlavoredFilter;
58
59 fn update_with_filter_order_limit_offset<F, O>(&self, conn: &mut C, filter: &F, order: &O, limit: usize, offset: usize, object: &T) -> Result<()>
60 where F: traits::FlavoredFilter, O: FlavoredOrder;
61
62}