Rebase fix - Reworking approach to sql for take

Mikayla Maki created

Change summary

crates/db/src/db.rs         |  1 +
crates/db/src/items.rs      | 38 +++++++++-----------------------------
crates/db/src/migrations.rs |  4 ++--
3 files changed, 12 insertions(+), 31 deletions(-)

Detailed changes

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<u8> = 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()],

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),
     ]);
 }