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#[derive(Debug, PartialEq, Eq)]
69pub struct ItemId {
70 pub item_id: usize,
71}
72
73// enum SerializedItemKind {
74// Editor,
75// Diagnostics,
76// ProjectSearch,
77// Terminal,
78// }
79
80// struct SerializedItemRow {
81// kind: SerializedItemKind,
82// item_id: usize,
83// path: Option<Arc<Path>>,
84// query: Option<String>,
85// }
86
87// #[derive(Debug, PartialEq, Eq)]
88// pub enum SerializedItem {
89// Editor { item_id: usize, path: Arc<Path> },
90// Diagnostics { item_id: usize },
91// ProjectSearch { item_id: usize, query: String },
92// Terminal { item_id: usize },
93// }
94
95// impl SerializedItem {
96// pub fn item_id(&self) -> usize {
97// match self {
98// SerializedItem::Editor { item_id, .. } => *item_id,
99// SerializedItem::Diagnostics { item_id } => *item_id,
100// SerializedItem::ProjectSearch { item_id, .. } => *item_id,
101// SerializedItem::Terminal { item_id } => *item_id,
102// }
103// }
104// }
105
106// impl Db {
107// pub fn get_item(&self, item_id: ItemId) -> SerializedItem {
108// unimplemented!()
109// }
110
111// pub fn save_item(&self, workspace_id: WorkspaceId, item: &SerializedItem) {}
112
113// pub fn close_item(&self, item_id: ItemId) {}
114// }