2022-11-23 09:53:58 +00:00
|
|
|
use std::path::PathBuf;
|
2022-11-19 23:14:13 +00:00
|
|
|
|
2022-12-02 02:31:05 +00:00
|
|
|
use db::{define_connection, query, sqlez_macros::sql};
|
2022-12-08 23:18:24 +00:00
|
|
|
use workspace::{ItemId, WorkspaceDb, WorkspaceId};
|
2022-11-19 23:14:13 +00:00
|
|
|
|
2022-12-02 02:31:05 +00:00
|
|
|
define_connection! {
|
2022-12-08 18:48:28 +00:00
|
|
|
pub static ref TERMINAL_DB: TerminalDb<WorkspaceDb> =
|
2022-11-29 01:42:18 +00:00
|
|
|
&[sql!(
|
2022-11-19 23:14:13 +00:00
|
|
|
CREATE TABLE terminals (
|
2022-11-21 07:44:30 +00:00
|
|
|
workspace_id INTEGER,
|
2022-12-08 23:18:24 +00:00
|
|
|
item_id INTEGER UNIQUE,
|
2022-11-19 23:14:13 +00:00
|
|
|
working_directory BLOB,
|
2022-12-08 23:18:24 +00:00
|
|
|
PRIMARY KEY(workspace_id, item_id),
|
2022-11-19 23:14:13 +00:00
|
|
|
FOREIGN KEY(workspace_id) REFERENCES workspaces(workspace_id)
|
2022-12-08 23:18:24 +00:00
|
|
|
ON DELETE CASCADE
|
2022-11-19 23:14:13 +00:00
|
|
|
) STRICT;
|
2022-12-02 02:31:05 +00:00
|
|
|
)];
|
2022-11-19 23:14:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl TerminalDb {
|
2022-11-24 08:02:07 +00:00
|
|
|
query! {
|
|
|
|
pub async fn update_workspace_id(
|
2022-11-23 09:53:58 +00:00
|
|
|
new_id: WorkspaceId,
|
|
|
|
old_id: WorkspaceId,
|
2022-12-08 23:18:24 +00:00
|
|
|
item_id: ItemId
|
2022-11-24 08:02:07 +00:00
|
|
|
) -> Result<()> {
|
2022-11-29 01:42:18 +00:00
|
|
|
UPDATE terminals
|
|
|
|
SET workspace_id = ?
|
|
|
|
WHERE workspace_id = ? AND item_id = ?
|
2022-11-24 08:02:07 +00:00
|
|
|
}
|
2022-11-21 18:38:16 +00:00
|
|
|
}
|
2022-11-19 23:14:13 +00:00
|
|
|
|
2022-11-24 08:02:07 +00:00
|
|
|
query! {
|
|
|
|
pub async fn save_working_directory(
|
2022-12-08 23:18:24 +00:00
|
|
|
item_id: ItemId,
|
|
|
|
workspace_id: WorkspaceId,
|
2022-11-24 08:02:07 +00:00
|
|
|
working_directory: PathBuf
|
|
|
|
) -> Result<()> {
|
2022-11-29 01:42:18 +00:00
|
|
|
INSERT OR REPLACE INTO terminals(item_id, workspace_id, working_directory)
|
|
|
|
VALUES (?, ?, ?)
|
2022-11-24 08:02:07 +00:00
|
|
|
}
|
2022-11-23 09:53:58 +00:00
|
|
|
}
|
|
|
|
|
2022-11-24 08:02:07 +00:00
|
|
|
query! {
|
2023-01-09 18:54:13 +00:00
|
|
|
pub fn get_working_directory(item_id: ItemId, workspace_id: WorkspaceId) -> Result<Option<PathBuf>> {
|
|
|
|
SELECT working_directory
|
|
|
|
FROM terminals
|
2022-11-29 01:42:18 +00:00
|
|
|
WHERE item_id = ? AND workspace_id = ?
|
2022-11-24 08:02:07 +00:00
|
|
|
}
|
2022-11-21 18:38:16 +00:00
|
|
|
}
|
2022-11-19 23:14:13 +00:00
|
|
|
}
|