|
@@ -2,14 +2,7 @@ use crate::DB;
|
|
|
|
|
|
pub mod condition;
|
|
|
|
|
|
-#[derive(Clone, Copy, Debug, serde::Serialize, serde::Deserialize)]
|
|
|
-pub struct ID { id: i64 }
|
|
|
-
|
|
|
-impl rusqlite::ToSql for ID {
|
|
|
- fn to_sql(&self) -> Result<rusqlite::types::ToSqlOutput<'_>, rusqlite::Error> {
|
|
|
- self.id.to_sql()
|
|
|
- }
|
|
|
-}
|
|
|
+pub type ID = i64;
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
pub struct WithID<T: crate::model::Entity> {
|
|
@@ -21,7 +14,7 @@ impl<T: crate::model::Entity> WithID<T> {
|
|
|
fn wrap(what: T, raw_id: i64) -> Self {
|
|
|
Self {
|
|
|
wrap: what,
|
|
|
- id: ID { id: raw_id }
|
|
|
+ id: raw_id
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -62,7 +55,7 @@ pub fn get_one_by<T: crate::model::Entity<Column = C>, C: crate::model::EntityCo
|
|
|
let mut prepared = db
|
|
|
.conn
|
|
|
.prepare(&format!(
|
|
|
- "SELECT rowid, tbl.* FROM {} tbl WHERE {} = ?1",
|
|
|
+ "SELECT rowid, tbl.* FROM \"{}\" tbl WHERE \"{}\" = ?1",
|
|
|
table_name, column_name
|
|
|
))
|
|
|
.ok()?;
|
|
@@ -86,13 +79,13 @@ pub fn get_all_by<T: crate::model::Entity<Column = C>, C: crate::model::EntityCo
|
|
|
|
|
|
let table_name = <T as crate::model::Entity>::table_name();
|
|
|
let column_name = <T as crate::model::Entity>::name(c);
|
|
|
+
|
|
|
let mut prepared = db
|
|
|
.conn
|
|
|
.prepare(&format!(
|
|
|
- "SELECT rowid, tbl.* FROM {} tbl WHERE {} = ?1",
|
|
|
+ "SELECT rowid, tbl.* FROM \"{}\" tbl WHERE \"{}\" = ?1",
|
|
|
table_name, column_name
|
|
|
- ))
|
|
|
- .ok()?;
|
|
|
+ )).ok()?;
|
|
|
|
|
|
let rows = prepared.query_map([&val], |row| {
|
|
|
let mut deser = crate::model::load::RowDeserializer::from_row(row);
|
|
@@ -114,7 +107,7 @@ pub fn get_one_by_id<T: crate::model::Entity>(
|
|
|
let mut prepared = db
|
|
|
.conn
|
|
|
.prepare(&format!(
|
|
|
- "SELECT rowid, tbl.* FROM {} tbl WHERE rowid = ?1",
|
|
|
+ "SELECT rowid, tbl.* FROM \"{}\" tbl WHERE rowid = ?1",
|
|
|
table_name
|
|
|
))
|
|
|
.ok()?;
|
|
@@ -140,7 +133,7 @@ pub fn add<T: crate::model::Entity + serde::Serialize>(db: &DB, m: &T) -> Option
|
|
|
.join(",");
|
|
|
|
|
|
let res = db.conn.prepare(&format!(
|
|
|
- "INSERT INTO {} VALUES ({})",
|
|
|
+ "INSERT INTO \"{}\" VALUES ({})",
|
|
|
<T as crate::model::Entity>::table_name(),
|
|
|
placeholders
|
|
|
));
|
|
@@ -150,5 +143,5 @@ pub fn add<T: crate::model::Entity + serde::Serialize>(db: &DB, m: &T) -> Option
|
|
|
assert_eq!(row.len(), <T as crate::model::Entity>::column_count());
|
|
|
|
|
|
let id = prepared.insert(rusqlite::params_from_iter(row)).ok()?;
|
|
|
- Some(ID {id})
|
|
|
+ Some(id)
|
|
|
}
|