storage/indexeddb/engines/
mod.rs1use std::collections::VecDeque;
6
7use malloc_size_of::MallocSizeOf;
8use malloc_size_of_derive::MallocSizeOf;
9use storage_traits::indexeddb::{
10 AsyncOperation, CreateObjectResult, IndexedDBIndex, IndexedDBTxnMode, KeyPath,
11};
12
13pub use self::sqlite::SqliteEngine;
14
15mod sqlite;
16
17#[derive(MallocSizeOf)]
18pub struct KvsOperation {
19 pub store_name: String,
20 pub operation: AsyncOperation,
21}
22
23#[derive(MallocSizeOf)]
24pub struct KvsTransaction {
25 pub mode: IndexedDBTxnMode,
28 pub requests: VecDeque<KvsOperation>,
29}
30
31pub trait KvsEngine: MallocSizeOf {
32 type Error: std::error::Error;
33
34 fn create_store(
35 &self,
36 store_name: &str,
37 key_path: Option<KeyPath>,
38 auto_increment: bool,
39 ) -> Result<CreateObjectResult, Self::Error>;
40
41 fn delete_store(&self, store_name: &str) -> Result<(), Self::Error>;
42
43 #[expect(dead_code)]
44 fn close_store(&self, store_name: &str) -> Result<(), Self::Error>;
45
46 fn delete_database(self) -> Result<(), Self::Error>;
47
48 fn process_transaction(
49 &self,
50 transaction: KvsTransaction,
51 on_complete: Box<dyn FnOnce() + Send + 'static>,
52 );
53
54 fn key_generator_current_number(&self, store_name: &str) -> Option<i32>;
55 fn key_path(&self, store_name: &str) -> Option<KeyPath>;
56 fn object_store_names(&self) -> Result<Vec<String>, Self::Error>;
57 fn indexes(&self, store_name: &str) -> Result<Vec<IndexedDBIndex>, Self::Error>;
58
59 fn create_index(
60 &self,
61 store_name: &str,
62 index_name: String,
63 key_path: KeyPath,
64 unique: bool,
65 multi_entry: bool,
66 ) -> Result<CreateObjectResult, Self::Error>;
67 fn delete_index(&self, store_name: &str, index_name: String) -> Result<(), Self::Error>;
68
69 fn version(&self) -> Result<u64, Self::Error>;
70 fn set_version(&self, version: u64) -> Result<(), Self::Error>;
71}