/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use std::collections::VecDeque; use net_traits::indexeddb_thread::{AsyncOperation, CreateObjectResult, IndexedDBTxnMode, KeyPath}; use tokio::sync::oneshot; pub use self::sqlite::SqliteEngine; mod sqlite; pub struct KvsOperation { pub store_name: String, pub operation: AsyncOperation, } pub struct KvsTransaction { // Mode could be used by a more optimal implementation of transactions // that has different allocated threadpools for reading and writing #[allow(unused)] pub mode: IndexedDBTxnMode, pub requests: VecDeque, } pub trait KvsEngine { type Error: std::error::Error; fn create_store( &self, store_name: &str, key_path: Option, auto_increment: bool, ) -> Result; fn delete_store(&self, store_name: &str) -> Result<(), Self::Error>; fn close_store(&self, store_name: &str) -> Result<(), Self::Error>; fn delete_database(self) -> Result<(), Self::Error>; fn process_transaction( &self, transaction: KvsTransaction, ) -> oneshot::Receiver>>; fn has_key_generator(&self, store_name: &str) -> bool; fn key_path(&self, store_name: &str) -> Option; fn create_index( &self, store_name: &str, index_name: String, key_path: KeyPath, unique: bool, multi_entry: bool, ) -> Result; fn delete_index(&self, store_name: &str, index_name: String) -> Result<(), Self::Error>; fn version(&self) -> Result; fn set_version(&self, version: u64) -> Result<(), Self::Error>; }