mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 20:15:07 +08:00
feat: Introduce the meilidb-data workspace member
This commit is contained in:
parent
77405cc103
commit
287d5dee4d
@ -2,6 +2,7 @@
|
||||
members = [
|
||||
"meilidb",
|
||||
"meilidb-core",
|
||||
"meilidb-data",
|
||||
"meilidb-tokenizer",
|
||||
]
|
||||
|
||||
|
8
meilidb-data/Cargo.toml
Normal file
8
meilidb-data/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "meilidb-data"
|
||||
version = "0.1.0"
|
||||
authors = ["Kerollmops <renault.cle@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
sled = "0.20.0"
|
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};
|
Loading…
Reference in New Issue
Block a user