dump type

This commit is contained in:
Aiden McClelland
2021-06-15 14:39:41 -06:00
parent 3e9e5741f0
commit a42247a2bb
2 changed files with 14 additions and 4 deletions

View File

@@ -14,6 +14,13 @@ pub struct Revision {
pub expire_id: Option<String>,
}
#[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 {

View File

@@ -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<T: Serialize + ?Sized, S: AsRef<str>, 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<S: AsRef<str>, V: SegList>(