stint_core/storage/
mod.rs1pub mod error;
4pub mod sqlite;
5
6use std::path::Path;
7use time::OffsetDateTime;
8
9use crate::models::entry::{EntryFilter, TimeEntry};
10use crate::models::project::{Project, ProjectStatus};
11use crate::models::session::ShellSession;
12use crate::models::types::{EntryId, ProjectId, SessionId};
13
14use self::error::StorageError;
15
16pub use self::sqlite::SqliteStorage;
17
18pub trait Storage {
20 fn create_project(&self, project: &Project) -> Result<(), StorageError>;
24
25 fn get_project(&self, id: &ProjectId) -> Result<Option<Project>, StorageError>;
27
28 fn get_project_by_name(&self, name: &str) -> Result<Option<Project>, StorageError>;
30
31 fn get_project_by_path(&self, path: &Path) -> Result<Option<Project>, StorageError>;
33
34 fn list_projects(&self, status: Option<ProjectStatus>) -> Result<Vec<Project>, StorageError>;
36
37 fn update_project(&self, project: &Project) -> Result<(), StorageError>;
39
40 fn delete_project(&self, id: &ProjectId) -> Result<(), StorageError>;
42
43 fn create_entry(&self, entry: &TimeEntry) -> Result<(), StorageError>;
47
48 fn get_entry(&self, id: &EntryId) -> Result<Option<TimeEntry>, StorageError>;
50
51 fn get_running_entry(&self, project_id: &ProjectId) -> Result<Option<TimeEntry>, StorageError>;
53
54 fn get_running_hook_entry(
56 &self,
57 project_id: &ProjectId,
58 ) -> Result<Option<TimeEntry>, StorageError>;
59
60 fn get_any_running_entry(&self) -> Result<Option<TimeEntry>, StorageError>;
62
63 fn list_entries(&self, filter: &EntryFilter) -> Result<Vec<TimeEntry>, StorageError>;
65
66 fn get_last_entry(&self) -> Result<Option<TimeEntry>, StorageError>;
68
69 fn update_entry(&self, entry: &TimeEntry) -> Result<(), StorageError>;
71
72 fn delete_entry(&self, id: &EntryId) -> Result<(), StorageError>;
74
75 fn upsert_session(&self, session: &ShellSession) -> Result<(), StorageError>;
79
80 fn get_session(&self, id: &SessionId) -> Result<Option<ShellSession>, StorageError>;
82
83 fn get_session_by_pid(&self, pid: u32) -> Result<Option<ShellSession>, StorageError>;
85
86 fn end_session(&self, id: &SessionId, ended_at: OffsetDateTime) -> Result<(), StorageError>;
88
89 fn count_active_sessions_for_project(
91 &self,
92 project_id: &ProjectId,
93 exclude_session_id: &SessionId,
94 ) -> Result<usize, StorageError>;
95
96 fn get_stale_sessions(
98 &self,
99 older_than: OffsetDateTime,
100 ) -> Result<Vec<ShellSession>, StorageError>;
101
102 fn add_ignored_path(&self, path: &Path) -> Result<(), StorageError>;
106
107 fn remove_ignored_path(&self, path: &Path) -> Result<bool, StorageError>;
109
110 fn is_path_ignored(&self, path: &Path) -> Result<bool, StorageError>;
112
113 fn list_ignored_paths(&self) -> Result<Vec<std::path::PathBuf>, StorageError>;
115}