derive_sql/sqlable.rs
1/// Definition of `Sqlable` trait to be implemented to allow interaction with SQL tables.
2pub trait Sqlable {
3 /// Defines the struct corresponding to the items in the SQL table
4 type Item;
5 /// Defines the struct used for returning errors
6 type Error;
7 /// Defines the struct used for providing selection, filtering to the implementation of the trait
8 type Selector;
9
10 /// Count the number of items in the table meeting the selector requirements
11 fn count(&self, s: Self::Selector) -> Result<usize, Self::Error>;
12 /// Retrieve the array of items in the table meeting the selector requirements
13 fn select(&self, s: Self::Selector) -> Result<Vec<Self::Item>, Self::Error>;
14 /// Insert a new item in the table and returned the inserted item.
15 fn insert(&mut self, item: Self::Item) -> Result<Self::Item, Self::Error>;
16 /// Update items meeting the selector requirements with the values of the provided item. Returns
17 /// the array of items modified with their updated value
18 fn update(&mut self, s: Self::Selector, item: Self::Item) -> Result<Self::Item, Self::Error>;
19 /// Delete items in the table meeting the selector requirements
20 fn delete(&mut self, s: Self::Selector) -> Result<(), Self::Error>;
21 /// Delete the table from the database
22 fn delete_table(&mut self) -> Result<(), Self::Error>;
23}
24