Files
continuwuity/src/database/map.rs
T

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

102 lines
2.1 KiB
Rust
Raw Normal View History

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;
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;
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;
use std::{
convert::AsRef,
ffi::CStr,
fmt,
fmt::{Debug, Display},
future::Future,
pin::Pin,
sync::Arc,
2024-06-30 23:06:01 +00:00
};
2024-05-28 06:59:50 +00:00
2024-12-14 21:58:01 -05:00
use conduwuit::Result;
use rocksdb::{AsColumnFamilyRef, ColumnFamily, ReadOptions, WriteOptions};
2024-08-08 17:18:30 +00:00
pub(crate) use self::options::{
cache_read_options_default, iter_options_default, read_options_default, write_options_default,
};
2024-09-29 07:37:43 +00:00
use crate::{watchers::Watchers, Engine};
2024-05-28 06:59:50 +00:00
pub struct Map {
name: &'static str,
2024-06-30 23:06:01 +00:00
db: Arc<Engine>,
cf: Arc<ColumnFamily>,
2024-05-28 06:59:50 +00:00
watchers: Watchers,
2024-06-29 03:25:13 +00:00
write_options: WriteOptions,
read_options: ReadOptions,
2024-11-27 06:28:32 +00:00
cache_read_options: ReadOptions,
2024-05-28 06:59:50 +00:00
}
impl Map {
pub(crate) fn open(db: &Arc<Engine>, name: &'static str) -> Result<Arc<Self>> {
2024-05-28 06:59:50 +00:00
Ok(Arc::new(Self {
name,
2024-06-30 23:06:01 +00:00
db: db.clone(),
cf: open::open(db, name),
2024-05-28 06:59:50 +00:00
watchers: Watchers::default(),
2024-06-29 03:25:13 +00:00
write_options: write_options_default(),
read_options: read_options_default(),
2024-11-27 06:28:32 +00:00
cache_read_options: cache_read_options_default(),
2024-05-28 06:59:50 +00:00
}))
}
2024-08-08 17:18:30 +00:00
#[inline]
pub fn watch_prefix<'a, K>(
&'a self,
prefix: &K,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>>
2024-08-08 17:18:30 +00:00
where
K: AsRef<[u8]> + ?Sized + Debug,
{
self.watchers.watch(prefix.as_ref())
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> {
self.db.property_integer(&self.cf(), name)
}
2024-08-08 17:18:30 +00:00
#[inline]
pub fn property(&self, name: &str) -> Result<String> { self.db.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]
pub(crate) fn db(&self) -> &Arc<Engine> { &self.db }
#[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
}