net/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 net_traits::indexeddb_thread::{AsyncOperation, CreateObjectResult, IndexedDBTxnMode, KeyPath};
8use tokio::sync::oneshot;
9
10pub use self::sqlite::SqliteEngine;
11
12mod sqlite;
13
14pub struct KvsOperation {
15    pub store_name: String,
16    pub operation: AsyncOperation,
17}
18
19pub struct KvsTransaction {
20    // Mode could be used by a more optimal implementation of transactions
21    // that has different allocated threadpools for reading and writing
22    #[allow(unused)]
23    pub mode: IndexedDBTxnMode,
24    pub requests: VecDeque<KvsOperation>,
25}
26
27pub trait KvsEngine {
28    type Error: std::error::Error;
29
30    fn create_store(
31        &self,
32        store_name: &str,
33        key_path: Option<KeyPath>,
34        auto_increment: bool,
35    ) -> Result<CreateObjectResult, Self::Error>;
36
37    fn delete_store(&self, store_name: &str) -> Result<(), Self::Error>;
38
39    fn close_store(&self, store_name: &str) -> Result<(), Self::Error>;
40
41    fn delete_database(self) -> Result<(), Self::Error>;
42
43    fn process_transaction(
44        &self,
45        transaction: KvsTransaction,
46    ) -> oneshot::Receiver<Option<Vec<u8>>>;
47
48    fn has_key_generator(&self, store_name: &str) -> bool;
49    fn key_path(&self, store_name: &str) -> Option<KeyPath>;
50
51    fn create_index(
52        &self,
53        store_name: &str,
54        index_name: String,
55        key_path: KeyPath,
56        unique: bool,
57        multi_entry: bool,
58    ) -> Result<CreateObjectResult, Self::Error>;
59    fn delete_index(&self, store_name: &str, index_name: String) -> Result<(), Self::Error>;
60
61    fn version(&self) -> Result<u64, Self::Error>;
62    fn set_version(&self, version: u64) -> Result<(), Self::Error>;
63}