derive_sql/traits/
table.rs

1use super::*;
2
3/// Specify table handling statement using the SQL Flavor
4pub trait TableFlavoredStatement {
5  /// Create table statement
6  fn create_stmt<C, R>(&self, conn: &C) -> Result<String> where C: Connection<R>, R: Row;
7
8  /// Create table statement if it does not exists
9  fn create_if_not_exist_stmt<C, R>(&self, conn: &C) -> Result<String> where C: Connection<R>, R: Row;
10
11  /// Drop table statemetn
12  fn drop_stmt<C, R>(&self, conn: &C) -> Result<String> where C: Connection<R>, R: Row;
13}
14
15/// [Deprecated] Specify table handling SQL statement
16pub trait TableStatement {
17  fn create_stmt(&self) -> Result<String>;
18  fn create_if_not_exist_stmt(&self) -> Result<String>;
19  fn drop_stmt(&self) -> Result<String>;
20}
21
22/// [Deprecated] Blanket statement converting legacy implementation
23impl<S> TableFlavoredStatement for S
24where S: TableStatement
25{
26  fn create_stmt<C, R>(&self, _: &C) -> Result<String> where C: Connection<R>, R: Row {
27    TableStatement::create_stmt(self)
28  }
29  fn create_if_not_exist_stmt<C, R>(&self, _: &C) -> Result<String> where C: Connection<R>, R: Row {
30    TableStatement::create_if_not_exist_stmt(self)
31  }
32  fn drop_stmt<C, R>(&self, _: &C) -> Result<String> where C: Connection<R>, R: Row {
33    TableStatement::drop_stmt(self)
34  }
35}
36
37/// Trait to manage table - create, check if exists, and drop
38pub trait Table<C, R>
39where C: Connection<R>,
40      R: Row,
41{
42  /// Create a table. Error if the table already exists
43  fn create(&self, conn: &mut C) -> Result<()>;
44
45  /// Create a table if it does not already exist
46  fn create_if_not_exist(&self, conn: &mut C) -> Result<()>;
47
48  /// Delete the table
49  fn drop(&self, conn: &mut C) -> Result<()>;
50}