mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-08-02 19:59:58 +00:00
feat: Introduce the meilidb-data workspace member
This commit is contained in:
21
meilidb-data/src/database.rs
Normal file
21
meilidb-data/src/database.rs
Normal file
@ -0,0 +1,21 @@
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Database(sled::Db);
|
||||
|
||||
impl Database {
|
||||
pub fn start_default<P: AsRef<Path>>(path: P) -> sled::Result<Database> {
|
||||
sled::Db::start_default(path).map(Database)
|
||||
}
|
||||
|
||||
pub fn open_index(&self, name: &str) -> sled::Result<Index> {
|
||||
let name = format!("index-{}", name);
|
||||
let bytes = name.into_bytes();
|
||||
|
||||
self.0.open_tree(bytes).map(Index)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Index(Arc<sled::Tree>);
|
3
meilidb-data/src/lib.rs
Normal file
3
meilidb-data/src/lib.rs
Normal file
@ -0,0 +1,3 @@
|
||||
mod database;
|
||||
|
||||
pub use self::database::{Database, Index};
|
Reference in New Issue
Block a user