|
@@ -1,5 +1,4 @@
|
|
use crate::model::{Entity, EntityColumns, EntityID};
|
|
use crate::model::{Entity, EntityColumns, EntityID};
|
|
-use crate::DB;
|
|
|
|
|
|
|
|
// pub mod condition;
|
|
// pub mod condition;
|
|
|
|
|
|
@@ -101,11 +100,11 @@ impl<'l> QueryInterface<'l> {
|
|
|
|
|
|
val.bind_to(&mut prepared, 1).ok()?;
|
|
val.bind_to(&mut prepared, 1).ok()?;
|
|
|
|
|
|
- return self.expect_one_result(&mut prepared, &mut |stmt| {
|
|
|
|
|
|
+ self.expect_one_result(&mut prepared, &mut |stmt| {
|
|
let id: i64 = stmt.read(0).ok()?;
|
|
let id: i64 = stmt.read(0).ok()?;
|
|
- let mut rd = crate::model::load::RowDeserializer::from_row(&stmt);
|
|
|
|
- return Some(WithID::wrap(T::deserialize(&mut rd).ok()?, id));
|
|
|
|
- });
|
|
|
|
|
|
+ let mut rd = crate::model::load::RowDeserializer::from_row(stmt);
|
|
|
|
+ Some(WithID::wrap(T::deserialize(&mut rd).ok()?, id))
|
|
|
|
+ })
|
|
}
|
|
}
|
|
|
|
|
|
/// Search for an entity by ID
|
|
/// Search for an entity by ID
|
|
@@ -119,11 +118,11 @@ impl<'l> QueryInterface<'l> {
|
|
|
|
|
|
id.bind_to(&mut prepared, 1).ok()?;
|
|
id.bind_to(&mut prepared, 1).ok()?;
|
|
|
|
|
|
- return self.expect_one_result(&mut prepared, &mut |stmt| {
|
|
|
|
|
|
+ self.expect_one_result(&mut prepared, &mut |stmt| {
|
|
let id: i64 = stmt.read(0).ok()?;
|
|
let id: i64 = stmt.read(0).ok()?;
|
|
- let mut rd = crate::model::load::RowDeserializer::from_row(&stmt);
|
|
|
|
|
|
+ let mut rd = crate::model::load::RowDeserializer::from_row(stmt);
|
|
return Some(WithID::wrap(T::deserialize(&mut rd).ok()?, id));
|
|
return Some(WithID::wrap(T::deserialize(&mut rd).ok()?, id));
|
|
- });
|
|
|
|
|
|
+ })
|
|
}
|
|
}
|
|
|
|
|
|
/// Search for all entities matching a property
|
|
/// Search for all entities matching a property
|
|
@@ -168,7 +167,7 @@ impl<'l> QueryInterface<'l> {
|
|
/// Add an entity to its table
|
|
/// Add an entity to its table
|
|
pub fn add<T: Entity + serde::Serialize>(&self, m: &T) -> Option<<T as Entity>::ID> {
|
|
pub fn add<T: Entity + serde::Serialize>(&self, m: &T) -> Option<<T as Entity>::ID> {
|
|
let placeholders = (0..(<T as Entity>::column_count() - 1))
|
|
let placeholders = (0..(<T as Entity>::column_count() - 1))
|
|
- .map(|n| "?".to_string())
|
|
|
|
|
|
+ .map(|_| "?".to_string())
|
|
.collect::<Vec<_>>()
|
|
.collect::<Vec<_>>()
|
|
.join(",");
|
|
.join(",");
|
|
|
|
|
|
@@ -211,38 +210,3 @@ impl<'l> QueryInterface<'l> {
|
|
Some(<T as Entity>::ID::from_raw_id(id))*/
|
|
Some(<T as Entity>::ID::from_raw_id(id))*/
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-/// Search for all entities matching a property
|
|
|
|
-pub fn get_all_by<T: Entity<Column = C>, C: EntityColumns<Entity = T>, V: sqlite::Bindable>(
|
|
|
|
- db: &DB,
|
|
|
|
- c: C,
|
|
|
|
- val: V,
|
|
|
|
-) -> Option<Vec<WithID<T>>> {
|
|
|
|
- let table_name = <T as Entity>::table_name();
|
|
|
|
- let column_name = <T as Entity>::name(c);
|
|
|
|
-
|
|
|
|
- todo!();
|
|
|
|
-
|
|
|
|
- /*
|
|
|
|
-
|
|
|
|
- let mut prepared = db
|
|
|
|
- .conn
|
|
|
|
- .prepare(&format!(
|
|
|
|
- "SELECT * FROM \"{}\" WHERE \"{}\" = ?1",
|
|
|
|
- table_name, column_name
|
|
|
|
- ))
|
|
|
|
- .ok()?;
|
|
|
|
-
|
|
|
|
- let rows = prepared
|
|
|
|
- .query_map([&val], |row| {
|
|
|
|
- let mut deser = crate::model::load::RowDeserializer::from_row(row);
|
|
|
|
- Ok(WithID::wrap(
|
|
|
|
- T::deserialize(&mut deser)?,
|
|
|
|
- row.get(0).expect("can get rowid"),
|
|
|
|
- ))
|
|
|
|
- })
|
|
|
|
- .ok()?;
|
|
|
|
-
|
|
|
|
- Some(rows.map(|x| x.unwrap()).collect())
|
|
|
|
- */
|
|
|
|
-}
|
|
|