diff --git a/crates/db/src/db.rs b/crates/db/src/db.rs index 2949acdb8372c37373d470708b20a92430108e4e..6f1ac7f59f69fcc64c826d8eed6c19624f04fe27 100644 --- a/crates/db/src/db.rs +++ b/crates/db/src/db.rs @@ -1,3 +1,4 @@ +mod items; mod kvp; mod migrations; diff --git a/crates/db/src/items.rs b/crates/db/src/items.rs index 87edbd2c00f93d157358caa0ed6f331310b7edc0..ed4a4f85e31ed869980496fd8aa20980faf1847d 100644 --- a/crates/db/src/items.rs +++ b/crates/db/src/items.rs @@ -148,38 +148,18 @@ impl Db { let tx = lock.transaction()?; - // When working with transactions in rusqlite, need to make this kind of scope - // To make the borrow stuff work correctly. Don't know why, rust is wild. - let result = { - let mut read_editors = tx - .prepare_cached( - r#" + // When working with transactions in rusqlite, need to make this kind of scope + // To make the borrow stuff work correctly. Don't know why, rust is wild. + let result = { + let mut editors_stmt = tx.prepare_cached( + r#" SELECT items.id, item_path.path FROM items LEFT JOIN item_path - ON items.id = item_path.item_id - WHERE items.kind = "Editor"; - "#r, - )? - .query_map([], |row| { - let buf: Vec = row.get(2)?; - let path: PathBuf = OsStr::from_bytes(&buf).into(); - - Ok(SerializedItem::Editor(id, path)) - })?; - - let mut read_stmt = tx.prepare_cached( - " - SELECT items.id, items.kind, item_path.path, item_query.query - FROM items - LEFT JOIN item_path - ON items.id = item_path.item_id - LEFT JOIN item_query - ON items.id = item_query.item_id - WHERE - ORDER BY items.id; - ", - )?; + ON items.id = item_path.item_id + WHERE items.kind = ?; + "#, + )?; let editors_iter = editors_stmt.query_map( [SerializedItemKind::Editor.to_string()], diff --git a/crates/db/src/migrations.rs b/crates/db/src/migrations.rs index 1000543d8ddde8829320de1b0c3e4f630635d3e8..40e5d28b80db2c0a7a40d3811d6dd4e65411d301 100644 --- a/crates/db/src/migrations.rs +++ b/crates/db/src/migrations.rs @@ -1,7 +1,7 @@ use rusqlite_migration::{Migrations, M}; // use crate::items::ITEMS_M_1; -use crate::kvp::KVP_M_1_UP; +use crate::{items::ITEMS_M_1, kvp::KVP_M_1_UP}; // This must be ordered by development time! Only ever add new migrations to the end!! // Bad things will probably happen if you don't monotonically edit this vec!!!! @@ -10,6 +10,6 @@ use crate::kvp::KVP_M_1_UP; lazy_static::lazy_static! { pub static ref MIGRATIONS: Migrations<'static> = Migrations::new(vec![ M::up(KVP_M_1_UP), - // M::up(ITEMS_M_1), + M::up(ITEMS_M_1), ]); }