1mod clear;
2pub mod compact;
3mod contains;
4mod count;
5mod del;
6mod del_prefix;
7mod get;
8mod get_batch;
9mod insert;
10mod keys;
11mod keys_from;
12mod keys_prefix;
13mod open;
14mod options;
15mod put;
16mod qry;
17mod qry_batch;
18mod remove;
19mod rev_keys;
20mod rev_keys_from;
21mod rev_keys_prefix;
22mod rev_stream;
23mod rev_stream_from;
24mod rev_stream_prefix;
25mod stream;
26mod stream_from;
27mod stream_prefix;
28mod watch;
29
30use std::{
31 ffi::CStr,
32 fmt,
33 fmt::{Debug, Display},
34 sync::Arc,
35};
36
37use rocksdb::{AsColumnFamilyRef, ColumnFamily, ReadOptions, WriteOptions};
38use tuwunel_core::Result;
39
40pub(crate) use self::options::{
41 cache_iter_options_default, cache_read_options_default, iter_options_default,
42 read_options_default, write_options_default,
43};
44use self::watch::Watch;
45pub use self::{get_batch::Get, qry_batch::Qry};
46use crate::Engine;
47
48pub struct Map {
49 name: &'static str,
50 watch: Watch,
51 cf: Arc<ColumnFamily>,
52 engine: Arc<Engine>,
53 read_options: ReadOptions,
54 cache_read_options: ReadOptions,
55 write_options: WriteOptions,
56}
57
58impl Map {
59 pub(crate) fn open(engine: &Arc<Engine>, name: &'static str) -> Result<Arc<Self>> {
60 Ok(Arc::new(Self {
61 name,
62 watch: Watch::default(),
63 cf: open::open(engine, name),
64 engine: engine.clone(),
65 read_options: read_options_default(engine),
66 cache_read_options: cache_read_options_default(engine),
67 write_options: write_options_default(engine),
68 }))
69 }
70
71 #[inline]
72 pub fn property_integer(&self, name: &CStr) -> Result<u64> {
73 self.engine.property_integer(&self.cf(), name)
74 }
75
76 #[inline]
77 pub fn property(&self, name: &str) -> Result<String> {
78 self.engine.property(&self.cf(), name)
79 }
80
81 #[inline]
82 pub fn name(&self) -> &str { self.name }
83
84 #[inline]
85 pub(crate) fn engine(&self) -> &Arc<Engine> { &self.engine }
86
87 #[inline]
88 pub(crate) fn cf(&self) -> impl AsColumnFamilyRef + '_ { &*self.cf }
89}
90
91impl Debug for Map {
92 fn fmt(&self, out: &mut fmt::Formatter<'_>) -> fmt::Result {
93 write!(out, "Map {{name: {0}}}", self.name)
94 }
95}
96
97impl Display for Map {
98 fn fmt(&self, out: &mut fmt::Formatter<'_>) -> fmt::Result { write!(out, "{0}", self.name) }
99}