Skip to main content

datasources_memory/
driver.rs

1use crate::connection::MemoryConnection;
2use crate::transaction::MemoryTransaction;
3use datasources::{
4    downcast_connection, Command, Connection, Driver, IsolationLevel, Transaction, TypeConverter,
5    Value,
6};
7use std::collections::HashMap;
8use std::sync::Arc;
9
10pub struct MemoryDriver;
11
12impl Driver for MemoryDriver {
13    fn connection(&self, options: Option<&HashMap<String, String>>) -> Arc<dyn Connection> {
14        MemoryConnection::from_options(options)
15    }
16
17    fn command(&self, connection: Arc<dyn Connection>) -> Arc<dyn Command> {
18        connection.create_command()
19    }
20
21    fn transaction(
22        &self,
23        connection: Arc<dyn Connection>,
24        isolation: IsolationLevel,
25    ) -> Arc<dyn Transaction> {
26        let conn = downcast_connection::<MemoryConnection>(connection).expect("memory");
27        Arc::new(MemoryTransaction::new(conn.state.clone(), isolation))
28    }
29
30    fn row_type_converters(
31        &self,
32    ) -> HashMap<String, Box<dyn TypeConverter<Value, Value> + Send + Sync>> {
33        HashMap::new()
34    }
35}
36
37datasources::export_driver!(datasources_memory_driver, MemoryDriver);