42 lines
1.5 KiB
Rust
42 lines
1.5 KiB
Rust
use std::path::Path;
|
|
|
|
use anyhow::Result;
|
|
use fjall::{Config, Keyspace, PartitionCreateOptions, PartitionHandle};
|
|
|
|
/// Contains the handles needed to reference key-value data.
|
|
///
|
|
/// This contains both the Keyspace and multiple PartitionHandle.
|
|
/// The Keyspace allows operational control and reporting at the top level,
|
|
/// while each PartitionHandle controls reading, writing, and removing from a
|
|
/// particular partition of the data.
|
|
///
|
|
/// All fields are public, because this is meant to be used internally as a
|
|
/// wrapper to pass everything around, instead of passing each handle around by
|
|
/// itself.
|
|
#[derive(Clone)]
|
|
pub struct KvHandle {
|
|
pub keyspace: Keyspace,
|
|
|
|
pub project: PartitionHandle,
|
|
pub document: PartitionHandle,
|
|
pub permissions: PartitionHandle,
|
|
}
|
|
|
|
impl KvHandle {
|
|
pub fn open<P: AsRef<Path>>(p: P) -> Result<KvHandle> {
|
|
// TODO: those should probably be configurable, or like, not just hard coded.
|
|
let config = Config::new(p).flush_workers(4).compaction_workers(4);
|
|
let keyspace = Keyspace::open(config)?;
|
|
|
|
let project = keyspace.open_partition("project", PartitionCreateOptions::default())?;
|
|
let document = keyspace.open_partition("document", PartitionCreateOptions::default())?;
|
|
let permissions = keyspace.open_partition("permissions", PartitionCreateOptions::default())?;
|
|
|
|
Ok(KvHandle {
|
|
keyspace,
|
|
project,
|
|
document,
|
|
permissions,
|
|
})
|
|
}
|
|
}
|