stateset_embedded/
stock_snapshots.rs1use stateset_core::{
4 CaptureStockSnapshot, Result, StockSnapshot, StockSnapshotFilter, StockSnapshotId,
5};
6use stateset_db::{Database, DatabaseCapability};
7use std::sync::Arc;
8
9pub struct StockSnapshots {
11 db: Arc<dyn Database>,
12}
13
14impl std::fmt::Debug for StockSnapshots {
15 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16 f.debug_struct("StockSnapshots").finish_non_exhaustive()
17 }
18}
19
20impl StockSnapshots {
21 pub(crate) fn new(db: Arc<dyn Database>) -> Self {
22 Self { db }
23 }
24
25 #[must_use]
27 pub fn is_supported(&self) -> bool {
28 self.db.supports_capability(DatabaseCapability::StockSnapshots)
29 }
30
31 fn ensure(&self) -> Result<()> {
32 self.db.ensure_capability(DatabaseCapability::StockSnapshots)
33 }
34
35 pub fn capture(&self, input: CaptureStockSnapshot) -> Result<StockSnapshot> {
37 self.ensure()?;
38 self.db.stock_snapshots().capture(input)
39 }
40
41 pub fn get(&self, id: StockSnapshotId) -> Result<Option<StockSnapshot>> {
43 self.ensure()?;
44 self.db.stock_snapshots().get(id)
45 }
46
47 pub fn latest(&self) -> Result<Option<StockSnapshot>> {
49 self.ensure()?;
50 self.db.stock_snapshots().latest()
51 }
52
53 pub fn list(&self, filter: StockSnapshotFilter) -> Result<Vec<StockSnapshot>> {
55 self.ensure()?;
56 self.db.stock_snapshots().list(filter)
57 }
58
59 pub fn delete(&self, id: StockSnapshotId) -> Result<()> {
61 self.ensure()?;
62 self.db.stock_snapshots().delete(id)
63 }
64}