Files
continuwuity/src/database/map.rs
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

98 lines
2.0 KiB
Rust
Raw Normal View History

2025-03-15 02:35:10 +00:00
mod clear;
2025-01-18 12:05:07 +00:00
pub mod compact;
2024-10-24 06:03:45 +00:00
mod contains;
2024-08-08 17:18:30 +00:00
mod count;
mod del;
2024-09-29 07:37:43 +00:00
mod get;
2024-12-03 10:42:52 +00:00
mod get_batch;
2024-09-29 07:37:43 +00:00
mod insert;
2024-08-08 17:18:30 +00:00
mod keys;
mod keys_from;
mod keys_prefix;
mod open;
mod options;
mod put;
2025-01-26 03:30:34 +00:00
mod qry;
mod qry_batch;
2024-09-29 07:37:43 +00:00
mod remove;
2024-08-08 17:18:30 +00:00
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;
2025-07-25 09:17:54 +00:00
mod watch;
2024-05-28 06:59:50 +00:00
2024-08-08 17:18:30 +00:00
use std::{
ffi::CStr,
fmt,
fmt::{Debug, Display},
sync::Arc,
2024-06-30 23:06:01 +00:00
};
2024-05-28 06:59:50 +00:00
use rocksdb::{AsColumnFamilyRef, ColumnFamily, ReadOptions, WriteOptions};
2025-04-22 01:41:02 +00:00
use tuwunel_core::Result;
2024-08-08 17:18:30 +00:00
pub(crate) use self::options::{
cache_iter_options_default, cache_read_options_default, iter_options_default,
read_options_default, write_options_default,
};
2025-07-25 09:17:54 +00:00
use self::watch::Watch;
2025-01-26 03:30:34 +00:00
pub use self::{get_batch::Get, qry_batch::Qry};
2025-07-25 09:17:54 +00:00
use crate::Engine;
2024-05-28 06:59:50 +00:00
pub struct Map {
name: &'static str,
2025-07-25 09:17:54 +00:00
watch: Watch,
2025-02-01 23:41:05 +00:00
cf: Arc<ColumnFamily>,
2025-09-09 18:12:38 +05:00
engine: Arc<Engine>,
2024-06-29 03:25:13 +00:00
read_options: ReadOptions,
2024-11-27 06:28:32 +00:00
cache_read_options: ReadOptions,
2025-02-01 23:41:05 +00:00
write_options: WriteOptions,
2024-05-28 06:59:50 +00:00
}
impl Map {
2025-09-09 18:12:38 +05:00
pub(crate) fn open(engine: &Arc<Engine>, name: &'static str) -> Result<Arc<Self>> {
2024-05-28 06:59:50 +00:00
Ok(Arc::new(Self {
name,
2025-07-25 09:17:54 +00:00
watch: Watch::default(),
2025-09-09 18:12:38 +05:00
cf: open::open(engine, name),
engine: engine.clone(),
read_options: read_options_default(engine),
cache_read_options: cache_read_options_default(engine),
write_options: write_options_default(engine),
2024-05-28 06:59:50 +00:00
}))
}
2024-08-08 17:18:30 +00:00
#[inline]
pub fn property_integer(&self, name: &CStr) -> Result<u64> {
2025-09-09 18:12:38 +05:00
self.engine.property_integer(&self.cf(), name)
}
2024-08-08 17:18:30 +00:00
#[inline]
2025-09-09 18:12:38 +05:00
pub fn property(&self, name: &str) -> Result<String> {
self.engine.property(&self.cf(), name)
}
2024-06-30 23:06:01 +00:00
#[inline]
pub fn name(&self) -> &str { self.name }
2024-06-30 23:06:01 +00:00
#[inline]
2025-09-09 18:12:38 +05:00
pub(crate) fn engine(&self) -> &Arc<Engine> { &self.engine }
#[inline]
pub(crate) fn cf(&self) -> impl AsColumnFamilyRef + '_ { &*self.cf }
2024-05-28 06:59:50 +00:00
}
2024-08-08 17:18:30 +00:00
impl Debug for Map {
fn fmt(&self, out: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(out, "Map {{name: {0}}}", self.name)
}
2024-08-08 17:18:30 +00:00
}
2024-05-28 06:59:50 +00:00
2024-08-08 17:18:30 +00:00
impl Display for Map {
fn fmt(&self, out: &mut fmt::Formatter<'_>) -> fmt::Result { write!(out, "{0}", self.name) }
2024-05-28 06:59:50 +00:00
}