vantage_dataset/im/
mod.rs1use indexmap::IndexMap;
4use std::collections::HashMap;
5use std::sync::{Arc, Mutex};
6use vantage_types::Record;
7
8pub mod dataset_insertable;
9pub mod dataset_readable;
10pub mod dataset_writable;
11pub mod im_table;
12
13pub mod valueset_insertable;
14pub mod valueset_readable;
15pub mod valueset_writable;
16pub use im_table::ImTable;
17
18type TableStorage = Arc<Mutex<HashMap<String, IndexMap<String, Record<serde_json::Value>>>>>;
20
21#[derive(Debug, Clone)]
23pub struct ImDataSource {
24 tables: TableStorage,
26}
27
28impl ImDataSource {
29 pub fn new() -> Self {
30 Self {
31 tables: Arc::new(Mutex::new(HashMap::new())),
32 }
33 }
34
35 fn get_or_create_table(&self, table_name: &str) -> IndexMap<String, Record<serde_json::Value>> {
36 let mut tables = self.tables.lock().unwrap();
37 tables.entry(table_name.to_string()).or_default().clone()
38 }
39
40 fn update_table(&self, table_name: &str, table: IndexMap<String, Record<serde_json::Value>>) {
41 let mut tables = self.tables.lock().unwrap();
42 tables.insert(table_name.to_string(), table);
43 }
44}
45
46impl Default for ImDataSource {
47 fn default() -> Self {
48 Self::new()
49 }
50}