stateset_embedded/
search_config.rs1use stateset_core::{
22 CreateSearchConfig, Result, SearchConfig, SearchConfigFilter, SearchConfigId,
23 UpdateSearchConfig,
24};
25use stateset_db::{Database, DatabaseCapability};
26use std::sync::Arc;
27
28pub struct SearchConfigs {
30 db: Arc<dyn Database>,
31}
32
33impl std::fmt::Debug for SearchConfigs {
34 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35 f.debug_struct("SearchConfigs").finish_non_exhaustive()
36 }
37}
38
39impl SearchConfigs {
40 pub(crate) fn new(db: Arc<dyn Database>) -> Self {
41 Self { db }
42 }
43
44 #[must_use]
46 pub fn is_supported(&self) -> bool {
47 self.db.supports_capability(DatabaseCapability::SearchConfigs)
48 }
49
50 fn ensure_supported(&self) -> Result<()> {
51 self.db.ensure_capability(DatabaseCapability::SearchConfigs)
52 }
53
54 pub fn create(&self, input: CreateSearchConfig) -> Result<SearchConfig> {
70 self.ensure_supported()?;
71 self.db.search_configs().create(input)
72 }
73
74 pub fn get(&self, id: SearchConfigId) -> Result<Option<SearchConfig>> {
76 self.ensure_supported()?;
77 self.db.search_configs().get(id)
78 }
79
80 pub fn update(&self, id: SearchConfigId, input: UpdateSearchConfig) -> Result<SearchConfig> {
82 self.ensure_supported()?;
83 self.db.search_configs().update(id, input)
84 }
85
86 pub fn list(&self, filter: SearchConfigFilter) -> Result<Vec<SearchConfig>> {
88 self.ensure_supported()?;
89 self.db.search_configs().list(filter)
90 }
91
92 pub fn delete(&self, id: SearchConfigId) -> Result<()> {
94 self.ensure_supported()?;
95 self.db.search_configs().delete(id)
96 }
97
98 pub fn get_active(&self) -> Result<Option<SearchConfig>> {
100 self.ensure_supported()?;
101 self.db.search_configs().get_active()
102 }
103
104 pub fn set_active(&self, id: SearchConfigId) -> Result<SearchConfig> {
106 self.ensure_supported()?;
107 self.db.search_configs().set_active(id)
108 }
109}