From 287d5dee4dab1140ee77306b0a02006055096e79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Fri, 29 Mar 2019 17:01:10 +0100 Subject: [PATCH] feat: Introduce the meilidb-data workspace member --- Cargo.toml | 1 + meilidb-data/Cargo.toml | 8 ++++++++ meilidb-data/src/database.rs | 21 +++++++++++++++++++++ meilidb-data/src/lib.rs | 3 +++ 4 files changed, 33 insertions(+) create mode 100644 meilidb-data/Cargo.toml create mode 100644 meilidb-data/src/database.rs create mode 100644 meilidb-data/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 1d97a68c7..69297052b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ members = [ "meilidb", "meilidb-core", + "meilidb-data", "meilidb-tokenizer", ] diff --git a/meilidb-data/Cargo.toml b/meilidb-data/Cargo.toml new file mode 100644 index 000000000..82d1bd8d4 --- /dev/null +++ b/meilidb-data/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "meilidb-data" +version = "0.1.0" +authors = ["Kerollmops "] +edition = "2018" + +[dependencies] +sled = "0.20.0" diff --git a/meilidb-data/src/database.rs b/meilidb-data/src/database.rs new file mode 100644 index 000000000..7f52dccda --- /dev/null +++ b/meilidb-data/src/database.rs @@ -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>(path: P) -> sled::Result { + sled::Db::start_default(path).map(Database) + } + + pub fn open_index(&self, name: &str) -> sled::Result { + let name = format!("index-{}", name); + let bytes = name.into_bytes(); + + self.0.open_tree(bytes).map(Index) + } +} + +#[derive(Debug, Clone)] +pub struct Index(Arc); diff --git a/meilidb-data/src/lib.rs b/meilidb-data/src/lib.rs new file mode 100644 index 000000000..4308ec6ad --- /dev/null +++ b/meilidb-data/src/lib.rs @@ -0,0 +1,3 @@ +mod database; + +pub use self::database::{Database, Index};