amadeus_utils/
database.rs

1use async_trait::async_trait;
2use thiserror::Error;
3
4#[derive(Debug, Error)]
5pub enum DatabaseError {
6    #[error("Database error: {0}")]
7    Generic(String),
8    #[error("Key not found: {0}")]
9    NotFound(String),
10    #[error(transparent)]
11    Io(#[from] std::io::Error),
12}
13
14/// Database trait for abstracting storage operations
15/// Implementations can use RocksDB, in-memory storage, or other backends
16#[async_trait]
17pub trait Database: Send + Sync {
18    /// Get a value from the database
19    fn get(&self, column_family: &str, key: &[u8]) -> Result<Option<Vec<u8>>, DatabaseError>;
20
21    /// Put a key-value pair into the database
22    fn put(&self, column_family: &str, key: &[u8], value: &[u8]) -> Result<(), DatabaseError>;
23
24    /// Delete a key from the database
25    fn delete(&self, column_family: &str, key: &[u8]) -> Result<(), DatabaseError>;
26
27    /// Iterate over keys with a given prefix
28    fn iter_prefix(&self, column_family: &str, prefix: &[u8]) -> Result<Vec<(Vec<u8>, Vec<u8>)>, DatabaseError>;
29}
30
31pub fn pad_integer(key: u64) -> String {
32    format!("{:012}", key)
33}
34
35pub fn pad_integer_20(key: u64) -> String {
36    format!("{:020}", key)
37}