this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 93 lines 3.2 kB view raw
1use async_trait::async_trait; 2use crate::{NodeId, RelationshipId, Node, Relationship, Result}; 3 4pub mod memory_store; 5pub mod persistent_store; 6pub mod page; 7pub mod btree; 8pub mod wal; 9#[cfg(feature = "rocksdb-storage")] 10pub mod rocksdb_store; 11 12pub use memory_store::MemoryStore; 13pub use persistent_store::PersistentStore; 14#[cfg(feature = "rocksdb-storage")] 15pub use rocksdb_store::RocksDBStore; 16 17#[async_trait] 18pub trait StorageEngine: Send + Sync { 19 async fn put_node(&self, node: &Node) -> Result<()>; 20 async fn get_node(&self, id: NodeId) -> Result<Option<Node>>; 21 async fn delete_node(&self, id: NodeId) -> Result<()>; 22 23 async fn put_relationship(&self, rel: &Relationship) -> Result<()>; 24 async fn get_relationship(&self, id: RelationshipId) -> Result<Option<Relationship>>; 25 async fn delete_relationship(&self, id: RelationshipId) -> Result<()>; 26 27 async fn put_node_relationships(&self, node_id: NodeId, relationships: &[RelationshipId]) -> Result<()>; 28 async fn get_node_relationships(&self, node_id: NodeId) -> Result<Vec<RelationshipId>>; 29 30 // Index persistence methods 31 async fn put_index_config(&self, name: &str, config_data: &[u8]) -> Result<()>; 32 async fn get_index_config(&self, name: &str) -> Result<Option<Vec<u8>>>; 33 async fn delete_index_config(&self, name: &str) -> Result<()>; 34 async fn list_index_configs(&self) -> Result<Vec<String>>; 35 36 async fn put_index_data(&self, index_key: &str, data: &[u8]) -> Result<()>; 37 async fn get_index_data(&self, index_key: &str) -> Result<Option<Vec<u8>>>; 38 async fn delete_index_data(&self, index_key: &str) -> Result<()>; 39 async fn list_index_data_keys(&self, prefix: &str) -> Result<Vec<String>>; 40 41 async fn put_raw(&self, key: &[u8], value: &[u8]) -> Result<()>; 42 async fn get_raw(&self, key: &[u8]) -> Result<Option<Vec<u8>>>; 43 async fn delete_raw(&self, key: &[u8]) -> Result<()>; 44 45 async fn flush(&self) -> Result<()>; 46 async fn compact(&self) -> Result<()>; 47} 48 49#[derive(Debug, Clone, Copy)] 50pub enum KeyPrefix { 51 Node = 0, 52 Relationship = 1, 53 NodeRelationships = 2, 54 Index = 3, 55 Schema = 4, 56 Transaction = 5, 57} 58 59impl KeyPrefix { 60 pub fn as_byte(&self) -> u8 { 61 *self as u8 62 } 63} 64 65pub fn encode_node_key(id: NodeId) -> Vec<u8> { 66 let mut key = vec![KeyPrefix::Node.as_byte()]; 67 key.extend_from_slice(&id.0.to_be_bytes()); 68 key 69} 70 71pub fn encode_relationship_key(id: RelationshipId) -> Vec<u8> { 72 let mut key = vec![KeyPrefix::Relationship.as_byte()]; 73 key.extend_from_slice(&id.0.to_be_bytes()); 74 key 75} 76 77pub fn encode_node_relationships_key(node_id: NodeId) -> Vec<u8> { 78 let mut key = vec![KeyPrefix::NodeRelationships.as_byte()]; 79 key.extend_from_slice(&node_id.0.to_be_bytes()); 80 key 81} 82 83pub fn encode_index_config_key(name: &str) -> Vec<u8> { 84 let mut key = vec![KeyPrefix::Index.as_byte(), 0]; // 0 for config 85 key.extend_from_slice(name.as_bytes()); 86 key 87} 88 89pub fn encode_index_data_key(index_key: &str) -> Vec<u8> { 90 let mut key = vec![KeyPrefix::Index.as_byte(), 1]; // 1 for data 91 key.extend_from_slice(index_key.as_bytes()); 92 key 93}