2022-11-19 23:14:13 +00:00
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
|
2022-11-21 06:41:10 +00:00
|
|
|
use db::{connection, exec_method, indoc, select_row_method, sqlez::domain::Domain};
|
|
|
|
|
2022-11-19 23:14:13 +00:00
|
|
|
use workspace::{ItemId, Workspace, WorkspaceId};
|
|
|
|
|
|
|
|
use crate::Terminal;
|
|
|
|
|
|
|
|
connection!(TERMINAL_CONNECTION: TerminalDb<(Workspace, Terminal)>);
|
|
|
|
|
|
|
|
impl Domain for Terminal {
|
|
|
|
fn name() -> &'static str {
|
|
|
|
"terminal"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn migrations() -> &'static [&'static str] {
|
|
|
|
&[indoc! {"
|
|
|
|
CREATE TABLE terminals (
|
|
|
|
workspace_id BLOB,
|
2022-11-21 06:41:10 +00:00
|
|
|
item_id INTEGER,
|
2022-11-19 23:14:13 +00:00
|
|
|
working_directory BLOB,
|
2022-11-21 06:41:10 +00:00
|
|
|
PRIMARY KEY(workspace_id, item_id),
|
2022-11-19 23:14:13 +00:00
|
|
|
FOREIGN KEY(workspace_id) REFERENCES workspaces(workspace_id)
|
|
|
|
ON DELETE CASCADE
|
|
|
|
) STRICT;
|
|
|
|
"}]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TerminalDb {
|
2022-11-21 03:19:42 +00:00
|
|
|
exec_method!(
|
2022-11-21 06:41:10 +00:00
|
|
|
save_working_directory(model_id: ItemId, workspace_id: WorkspaceId, working_directory: &Path):
|
2022-11-21 03:19:42 +00:00
|
|
|
"INSERT OR REPLACE INTO terminals(item_id, workspace_id, working_directory)
|
2022-11-21 06:41:10 +00:00
|
|
|
VALUES (?1, ?2, ?3)"
|
2022-11-21 03:19:42 +00:00
|
|
|
);
|
2022-11-19 23:14:13 +00:00
|
|
|
|
2022-11-21 03:19:42 +00:00
|
|
|
select_row_method!(
|
2022-11-21 06:41:10 +00:00
|
|
|
get_working_directory(item_id: ItemId, workspace_id: WorkspaceId) -> PathBuf:
|
2022-11-21 03:19:42 +00:00
|
|
|
"SELECT working_directory
|
|
|
|
FROM terminals
|
2022-11-21 06:41:10 +00:00
|
|
|
WHERE item_id = ? AND workspace_id = ?"
|
2022-11-21 03:19:42 +00:00
|
|
|
);
|
2022-11-19 23:14:13 +00:00
|
|
|
}
|