Skip to main content

linkrs_server/web/
storage.rs

1//! Metadata Storage Module
2//!
3//! Provides SQLite-based storage for:
4//! - Query history
5//! - Query favorites
6
7use async_trait::async_trait;
8
9use crate::web::error::WebResult;
10use crate::web::models::metadata::{FavoriteItem, HistoryItem};
11
12mod sqlite;
13
14pub use sqlite::SqliteStorage;
15
16/// Metadata storage trait
17#[async_trait]
18pub trait MetadataStorage: Send + Sync {
19    /// Add a history item
20    async fn add_history(&self, item: &HistoryItem) -> WebResult<()>;
21
22    /// Get history items for a session
23    async fn get_history(
24        &self,
25        session_id: &str,
26        limit: usize,
27        offset: usize,
28    ) -> WebResult<(Vec<HistoryItem>, i64)>;
29
30    /// Delete a history item
31    async fn delete_history(&self, id: &str, session_id: &str) -> WebResult<()>;
32
33    /// Clear all history for a session
34    async fn clear_history(&self, session_id: &str) -> WebResult<()>;
35
36    /// Add a favorite item
37    async fn add_favorite(&self, item: &FavoriteItem) -> WebResult<()>;
38
39    /// Get all favorites for a session
40    async fn get_favorites(&self, session_id: &str) -> WebResult<Vec<FavoriteItem>>;
41
42    /// Get a favorite by ID
43    async fn get_favorite(&self, id: &str, session_id: &str) -> WebResult<FavoriteItem>;
44
45    /// Update a favorite
46    async fn update_favorite(
47        &self,
48        id: &str,
49        session_id: &str,
50        item: &FavoriteItem,
51    ) -> WebResult<()>;
52
53    /// Delete a favorite
54    async fn delete_favorite(&self, id: &str, session_id: &str) -> WebResult<()>;
55
56    /// Delete all favorites for a session
57    async fn delete_all_favorites(&self, session_id: &str) -> WebResult<()>;
58}