Files
tuwunel/src/database/map.rs
Jason Volk e58ef326d4 Refactor legacy database watcher system.
Signed-off-by: Jason Volk <jason@zemos.net>
2025-07-25 20:07:21 +00:00

97 lines
2.0 KiB
Rust

mod clear;
pub mod compact;
mod contains;
mod count;
mod del;
mod get;
mod get_batch;
mod insert;
mod keys;
mod keys_from;
mod keys_prefix;
mod open;
mod options;
mod put;
mod qry;
mod qry_batch;
mod remove;
mod rev_keys;
mod rev_keys_from;
mod rev_keys_prefix;
mod rev_stream;
mod rev_stream_from;
mod rev_stream_prefix;
mod stream;
mod stream_from;
mod stream_prefix;
mod watch;
use std::{
ffi::CStr,
fmt,
fmt::{Debug, Display},
sync::Arc,
};
use rocksdb::{AsColumnFamilyRef, ColumnFamily, ReadOptions, WriteOptions};
use tuwunel_core::Result;
pub(crate) use self::options::{
cache_iter_options_default, cache_read_options_default, iter_options_default,
read_options_default, write_options_default,
};
use self::watch::Watch;
pub use self::{get_batch::Get, qry_batch::Qry};
use crate::Engine;
pub struct Map {
name: &'static str,
watch: Watch,
cf: Arc<ColumnFamily>,
db: Arc<Engine>,
read_options: ReadOptions,
cache_read_options: ReadOptions,
write_options: WriteOptions,
}
impl Map {
pub(crate) fn open(db: &Arc<Engine>, name: &'static str) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
name,
watch: Watch::default(),
cf: open::open(db, name),
db: db.clone(),
read_options: read_options_default(db),
cache_read_options: cache_read_options_default(db),
write_options: write_options_default(db),
}))
}
#[inline]
pub fn property_integer(&self, name: &CStr) -> Result<u64> {
self.db.property_integer(&self.cf(), name)
}
#[inline]
pub fn property(&self, name: &str) -> Result<String> { self.db.property(&self.cf(), name) }
#[inline]
pub fn name(&self) -> &str { self.name }
#[inline]
pub(crate) fn db(&self) -> &Arc<Engine> { &self.db }
#[inline]
pub(crate) fn cf(&self) -> impl AsColumnFamilyRef + '_ { &*self.cf }
}
impl Debug for Map {
fn fmt(&self, out: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(out, "Map {{name: {0}}}", self.name)
}
}
impl Display for Map {
fn fmt(&self, out: &mut fmt::Formatter<'_>) -> fmt::Result { write!(out, "{0}", self.name) }
}