items.rs

  1// use std::{
  2//     ffi::OsStr,
  3//     fmt::Display,
  4//     hash::Hash,
  5//     os::unix::prelude::OsStrExt,
  6//     path::{Path, PathBuf},
  7//     sync::Arc,
  8// };
  9
 10// use anyhow::Result;
 11// use collections::HashSet;
 12// use rusqlite::{named_params, params, types::FromSql};
 13
 14// use crate::workspace::WorkspaceId;
 15
 16// use super::Db;
 17
 18// /// Current design makes the cut at the item level,
 19// ///   - Maybe A little more bottom up, serialize 'Terminals' and 'Editors' directly, and then make a seperate
 20// ///   - items table, with a kind, and an integer that acts as a key to one of these other tables
 21// /// This column is a foreign key to ONE OF: editors, terminals, searches
 22// ///   -
 23
 24// // (workspace_id, item_id)
 25// // kind -> ::Editor::
 26
 27// // ->
 28// // At the workspace level
 29// // -> (Workspace_ID, item_id)
 30// // -> One shot, big query, load everything up:
 31
 32// // -> SerializedWorkspace::deserialize(tx, itemKey)
 33// //     -> SerializedEditor::deserialize(tx, itemKey)
 34
 35// //         ->
 36// // -> Workspace::new(SerializedWorkspace)
 37// //     -> Editor::new(serialized_workspace[???]serializedEditor)
 38
 39// // //Pros: Keeps sql out of every body elese, makes changing it easier (e.g. for loading from a network or RocksDB)
 40// // //Cons: DB has to know the internals of the entire rest of the app
 41
 42// // Workspace
 43// // Worktree roots
 44// // Pane groups
 45// // Dock
 46// // Items
 47// // Sidebars
 48
 49// // Things I'm doing: finding about nullability for foreign keys
 50// pub(crate) const ITEMS_M_1: &str = "
 51// CREATE TABLE project_searches(
 52//     workspace_id INTEGER,
 53//     item_id INTEGER,
 54//     query TEXT,
 55//     PRIMARY KEY (workspace_id, item_id)
 56//     FOREIGN KEY(workspace_id) REFERENCES workspace_ids(workspace_id)
 57// ) STRICT;
 58
 59// CREATE TABLE editors(
 60//     workspace_id INTEGER,
 61//     item_id INTEGER,
 62//     path BLOB NOT NULL,
 63//     PRIMARY KEY (workspace_id, item_id)
 64//     FOREIGN KEY(workspace_id) REFERENCES workspace_ids(workspace_id)
 65// ) STRICT;
 66// ";
 67
 68// enum SerializedItemKind {
 69//     Editor,
 70//     Diagnostics,
 71//     ProjectSearch,
 72//     Terminal,
 73// }
 74
 75// struct SerializedItemRow {
 76//     kind: SerializedItemKind,
 77//     item_id: usize,
 78//     path: Option<Arc<Path>>,
 79//     query: Option<String>,
 80// }
 81
 82// #[derive(Debug, PartialEq, Eq)]
 83// pub enum SerializedItem {
 84//     Editor { item_id: usize, path: Arc<Path> },
 85//     Diagnostics { item_id: usize },
 86//     ProjectSearch { item_id: usize, query: String },
 87//     Terminal { item_id: usize },
 88// }
 89
 90// impl SerializedItem {
 91//     pub fn item_id(&self) -> usize {
 92//         match self {
 93//             SerializedItem::Editor { item_id, .. } => *item_id,
 94//             SerializedItem::Diagnostics { item_id } => *item_id,
 95//             SerializedItem::ProjectSearch { item_id, .. } => *item_id,
 96//             SerializedItem::Terminal { item_id } => *item_id,
 97//         }
 98//     }
 99// }
100
101// impl Db {
102//     pub fn get_item(&self, item_id: ItemId) -> SerializedItem {
103//         unimplemented!()
104//     }
105
106//     pub fn save_item(&self, workspace_id: WorkspaceId, item: &SerializedItem) {}
107
108//     pub fn close_item(&self, item_id: ItemId) {}
109// }