From 076e7818102297e3d50095202c8054546d235e41 Mon Sep 17 00:00:00 2001 From: Quentin de Quelen Date: Tue, 19 Nov 2019 16:04:16 +0100 Subject: [PATCH] Add name, created_at and updated_at informations into main index --- meilidb-core/src/store/main.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/meilidb-core/src/store/main.rs b/meilidb-core/src/store/main.rs index eeb04d21f..d35189ea9 100644 --- a/meilidb-core/src/store/main.rs +++ b/meilidb-core/src/store/main.rs @@ -1,17 +1,22 @@ +use chrono::{DateTime, Utc}; use crate::RankedMap; -use heed::types::{ByteSlice, OwnedType, SerdeBincode, Str}; use heed::Result as ZResult; +use heed::types::{ByteSlice, OwnedType, SerdeBincode, Str}; use meilidb_schema::Schema; use std::sync::Arc; +const CREATED_AT: &str = "created-at"; const CUSTOMS_KEY: &str = "customs-key"; +const NAME: &str = "name"; const NUMBER_OF_DOCUMENTS_KEY: &str = "number-of-documents"; const RANKED_MAP_KEY: &str = "ranked-map"; const SCHEMA_KEY: &str = "schema"; -const SYNONYMS_KEY: &str = "synonyms"; const STOP_WORDS_KEY: &str = "stop-words"; +const SYNONYMS_KEY: &str = "synonyms"; const WORDS_KEY: &str = "words"; +type SerdeDatetime = SerdeBincode>; + #[derive(Copy, Clone)] pub struct Main { pub(crate) main: heed::PolyDatabase, @@ -22,6 +27,22 @@ impl Main { self.main.clear(writer) } + pub fn name(self, reader: &heed::RoTxn) -> ZResult> { + Ok(self.main.get::(reader, NAME)?.map(|name| name.to_owned())) + } + + pub fn put_name(self, writer: &mut heed::RwTxn, name: &str) -> ZResult<()> { + self.main.put::(writer, NAME, name) + } + + pub fn created_at(self, reader: &heed::RoTxn) -> ZResult>> { + self.main.get::(reader, CREATED_AT) + } + + pub fn put_created_at(self, writer: &mut heed::RwTxn) -> ZResult<()> { + self.main.put::(writer, CREATED_AT, &Utc::now()) + } + pub fn put_words_fst(self, writer: &mut heed::RwTxn, fst: &fst::Set) -> ZResult<()> { let bytes = fst.as_fst().as_bytes(); self.main.put::(writer, WORDS_KEY, bytes)