refactor database engine/options; add column descriptors
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
02f19cf951
commit
6a0f9add0c
21 changed files with 1358 additions and 965 deletions
|
@ -1,5 +1,11 @@
|
|||
extern crate conduwuit_core as conduwuit;
|
||||
extern crate rust_rocksdb as rocksdb;
|
||||
|
||||
conduwuit::mod_ctor! {}
|
||||
conduwuit::mod_dtor! {}
|
||||
conduwuit::rustc_flags_capture! {}
|
||||
|
||||
mod cork;
|
||||
mod database;
|
||||
mod de;
|
||||
mod deserialized;
|
||||
mod engine;
|
||||
|
@ -7,7 +13,6 @@ mod handle;
|
|||
pub mod keyval;
|
||||
mod map;
|
||||
pub mod maps;
|
||||
mod opts;
|
||||
mod pool;
|
||||
mod ser;
|
||||
mod stream;
|
||||
|
@ -16,16 +21,11 @@ mod tests;
|
|||
pub(crate) mod util;
|
||||
mod watchers;
|
||||
|
||||
pub(crate) use self::{
|
||||
engine::Engine,
|
||||
util::{or_else, result},
|
||||
};
|
||||
use std::{ops::Index, sync::Arc};
|
||||
|
||||
extern crate conduwuit_core as conduwuit;
|
||||
extern crate rust_rocksdb as rocksdb;
|
||||
use conduwuit::{err, Result, Server};
|
||||
|
||||
pub use self::{
|
||||
database::Database,
|
||||
de::{Ignore, IgnoreAll},
|
||||
deserialized::Deserialized,
|
||||
handle::Handle,
|
||||
|
@ -33,7 +33,60 @@ pub use self::{
|
|||
map::Map,
|
||||
ser::{serialize, serialize_to, serialize_to_vec, Interfix, Json, Separator, SEP},
|
||||
};
|
||||
pub(crate) use self::{
|
||||
engine::{context::Context, Engine},
|
||||
util::{or_else, result},
|
||||
};
|
||||
use crate::maps::{Maps, MapsKey, MapsVal};
|
||||
|
||||
conduwuit::mod_ctor! {}
|
||||
conduwuit::mod_dtor! {}
|
||||
conduwuit::rustc_flags_capture! {}
|
||||
pub struct Database {
|
||||
maps: Maps,
|
||||
pub db: Arc<Engine>,
|
||||
pub(crate) _ctx: Arc<Context>,
|
||||
}
|
||||
|
||||
impl Database {
|
||||
/// Load an existing database or create a new one.
|
||||
pub async fn open(server: &Arc<Server>) -> Result<Arc<Self>> {
|
||||
let ctx = Context::new(server)?;
|
||||
let db = Engine::open(ctx.clone(), maps::MAPS).await?;
|
||||
Ok(Arc::new(Self {
|
||||
maps: maps::open(&db)?,
|
||||
db: db.clone(),
|
||||
_ctx: ctx,
|
||||
}))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get(&self, name: &str) -> Result<&Arc<Map>> {
|
||||
self.maps
|
||||
.get(name)
|
||||
.ok_or_else(|| err!(Request(NotFound("column not found"))))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn iter(&self) -> impl Iterator<Item = (&MapsKey, &MapsVal)> + Send + '_ {
|
||||
self.maps.iter()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn keys(&self) -> impl Iterator<Item = &MapsKey> + Send + '_ { self.maps.keys() }
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn is_read_only(&self) -> bool { self.db.is_read_only() }
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn is_secondary(&self) -> bool { self.db.is_secondary() }
|
||||
}
|
||||
|
||||
impl Index<&str> for Database {
|
||||
type Output = Arc<Map>;
|
||||
|
||||
fn index(&self, name: &str) -> &Self::Output {
|
||||
self.maps
|
||||
.get(name)
|
||||
.expect("column in database does not exist")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue