diff --git a/weaponry/src/database.rs b/weaponry/src/database.rs index ac67e3c..a372c66 100644 --- a/weaponry/src/database.rs +++ b/weaponry/src/database.rs @@ -11,11 +11,12 @@ use serde::de::DeserializeOwned; pub fn get_data( conn: &rusqlite::Connection, table_name: &str, + filter: Option<&str>, ) -> Result, serde_rusqlite::Error> where T: DeserializeOwned + more_fields::FieldsAsSlice, { - let mut query_result = conn.prepare(&generate_select_query::(table_name, None))?; + let mut query_result = conn.prepare(&generate_select_query::(table_name, filter))?; Ok(serde_rusqlite::from_rows::(query_result.query([])?) .filter_map(|s| s.ok()) .collect()) @@ -106,7 +107,7 @@ mod test { let filename = "test.db"; let conn = mock_set_up(filename); let result = conn - .serialize_vec_from_table::("TestStruct") + .serialize_vec_from_table::("TestStruct", None) .unwrap(); tear_down(filename, conn.conn); assert_eq!( diff --git a/weaponry/src/interfaces.rs b/weaponry/src/interfaces.rs index 4ef187a..9e5f02c 100644 --- a/weaponry/src/interfaces.rs +++ b/weaponry/src/interfaces.rs @@ -164,17 +164,11 @@ pub trait RecipeDatabase { where Self: std::marker::Sized; - /// Serialize a vector of objects of the given type in the specified table of the underlying database + /// Serialize a vector of objects of the given type in the specified table with an optional filter of the underlying database fn serialize_vec_from_table( &self, table: &str, - ) -> std::result::Result, FatalEquipementError>; - - /// Serialize a specified vector of objects of the given type with an additionnal restriction - fn serialize_vec_from_table_with_query( - &self, - table: &str, - query: &str, + filter: Option<&str>, ) -> std::result::Result, FatalEquipementError>; /// Initialize an empty database & table diff --git a/weaponry/src/weaponry_structs/equipement_impl_database.rs b/weaponry/src/weaponry_structs/equipement_impl_database.rs index 1e4bd3b..6123195 100644 --- a/weaponry/src/weaponry_structs/equipement_impl_database.rs +++ b/weaponry/src/weaponry_structs/equipement_impl_database.rs @@ -22,18 +22,9 @@ impl RecipeDatabase for EquipementDatabase { fn serialize_vec_from_table( &self, table: &str, + filter: Option<&str>, ) -> Result, crate::error::FatalEquipementError> { - Ok(get_data(&self.conn, table)?) - } - - fn serialize_vec_from_table_with_query( - &self, - table: &str, - query: &str, - ) -> Result, crate::error::FatalEquipementError> { - let _ = table; - let _ = query; - todo!() + Ok(get_data(&self.conn, table, filter)?) } /// Checks if database exists, and returns a rusqlite::Connection. If not, opens database in memory. @@ -48,7 +39,6 @@ impl RecipeDatabase for EquipementDatabase { ) -> Result<(), crate::error::EquipementError> { // A vector of let _attr_map = T::attributes_slice(); - let _ = table; todo!() } diff --git a/weaponry/src/weaponry_structs/equipement_scenario.rs b/weaponry/src/weaponry_structs/equipement_scenario.rs index c343129..19f96bf 100644 --- a/weaponry/src/weaponry_structs/equipement_scenario.rs +++ b/weaponry/src/weaponry_structs/equipement_scenario.rs @@ -23,18 +23,10 @@ impl RecipeDatabase for DatabaseMock { fn serialize_vec_from_table( &self, table: &str, + filter: Option<&str>, ) -> std::result::Result, crate::error::FatalEquipementError> { let _ = table; - unimplemented!() - } - - fn serialize_vec_from_table_with_query( - &self, - table: &str, - query: &str, - ) -> std::result::Result, FatalEquipementError> { - let _ = table; - let _ = query; + let _ = filter; unimplemented!() } @@ -95,10 +87,7 @@ impl Scenario for CrossRecipeScenario { fn generate_refined_recipes(&self) -> Self::FinalListType { let _all_parts = &self .database - .serialize_vec_from_table_with_query::( - "bob", - "WHERE CATEGOTY == 'Bobitty'", - ); + .serialize_vec_from_table::("bob", Some("CATEGOTY == 'Bobitty'")); todo!() }