storage/indexeddb/engines/
mod.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use std::collections::VecDeque;
6
7use storage_traits::indexeddb_thread::{
8    AsyncOperation, CreateObjectResult, IndexedDBTxnMode, KeyPath,
9};
10use tokio::sync::oneshot;
11
12pub use self::sqlite::SqliteEngine;
13
14mod sqlite;
15
16pub struct KvsOperation {
17    pub store_name: String,
18    pub operation: AsyncOperation,
19}
20
21pub struct KvsTransaction {
22    // Mode could be used by a more optimal implementation of transactions
23    // that has different allocated threadpools for reading and writing
24    pub mode: IndexedDBTxnMode,
25    pub requests: VecDeque<KvsOperation>,
26}
27
28pub trait KvsEngine {
29    type Error: std::error::Error;
30
31    fn create_store(
32        &self,
33        store_name: &str,
34        key_path: Option<KeyPath>,
35        auto_increment: bool,
36    ) -> Result<CreateObjectResult, Self::Error>;
37
38    fn delete_store(&self, store_name: &str) -> Result<(), Self::Error>;
39
40    #[expect(dead_code)]
41    fn close_store(&self, store_name: &str) -> Result<(), Self::Error>;
42
43    fn delete_database(self) -> Result<(), Self::Error>;
44
45    fn process_transaction(
46        &self,
47        transaction: KvsTransaction,
48    ) -> oneshot::Receiver<Option<Vec<u8>>>;
49
50    fn has_key_generator(&self, store_name: &str) -> bool;
51    fn key_path(&self, store_name: &str) -> Option<KeyPath>;
52
53    fn create_index(
54        &self,
55        store_name: &str,
56        index_name: String,
57        key_path: KeyPath,
58        unique: bool,
59        multi_entry: bool,
60    ) -> Result<CreateObjectResult, Self::Error>;
61    fn delete_index(&self, store_name: &str, index_name: String) -> Result<(), Self::Error>;
62
63    fn version(&self) -> Result<u64, Self::Error>;
64    fn set_version(&self, version: u64) -> Result<(), Self::Error>;
65}