From 8bc6a3a1a5ef5994b0377ebeb2516a02ebee0336 Mon Sep 17 00:00:00 2001 From: Aiden McClelland Date: Tue, 15 Jun 2021 14:39:41 -0600 Subject: [PATCH] dump type --- patch-db/src/patch.rs | 7 +++++++ patch-db/src/store.rs | 11 +++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/patch-db/src/patch.rs b/patch-db/src/patch.rs index cb2f359..fdd44ba 100644 --- a/patch-db/src/patch.rs +++ b/patch-db/src/patch.rs @@ -14,6 +14,13 @@ pub struct Revision { pub expire_id: Option, } +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case")] +pub struct Dump { + pub id: u64, + pub value: Value, +} + #[derive(Debug, Clone, Deserialize, Serialize)] pub struct DiffPatch(Patch); impl DiffPatch { diff --git a/patch-db/src/store.rs b/patch-db/src/store.rs index 0cbe6a6..0241e3e 100644 --- a/patch-db/src/store.rs +++ b/patch-db/src/store.rs @@ -15,7 +15,7 @@ use tokio::fs::File; use tokio::sync::broadcast::{Receiver, Sender}; use tokio::sync::{Mutex, RwLock, RwLockWriteGuard}; -use crate::patch::{diff, DiffPatch, Revision}; +use crate::patch::{diff, DiffPatch, Dump, Revision}; use crate::Error; use crate::{locker::Locker, PatchDbHandle}; @@ -146,8 +146,11 @@ impl Store { ptr.get(self.get_data()?).unwrap_or(&Value::Null).clone(), )?) } - pub(crate) fn dump(&self) -> Value { - self.get_data().unwrap().clone() + pub(crate) fn dump(&self) -> Dump { + Dump { + id: self.revision, + value: self.get_data().unwrap().clone(), + } } pub(crate) async fn put, V: SegList>( &mut self, @@ -214,7 +217,7 @@ impl PatchDb { subscriber: Arc::new(subscriber), }) } - pub async fn dump(&self) -> Value { + pub async fn dump(&self) -> Dump { self.store.read().await.dump() } pub async fn exists, V: SegList>(