wip: macros

This commit is contained in:
Aiden McClelland
2021-03-23 18:10:22 -06:00
parent 4e96c64c1b
commit 2c3fd8159e
9 changed files with 148 additions and 68 deletions

View File

@@ -1025,7 +1025,7 @@ where
Ok(ModelData(tx.get(&self.ptr, LockType::Read).await?))
}
pub async fn get_mut<Tx: Checkpoint>(&mut self, tx: &mut Tx) -> Result<ModelDataMut<T>, Error> {
pub async fn get_mut<Tx: Checkpoint>(&self, tx: &mut Tx) -> Result<ModelDataMut<T>, Error> {
self.lock(tx, LockType::Write).await;
let original = tx.get_value(&self.ptr, None).await?;
let current = serde_json::from_value(original.clone())?;

View File

@@ -3,7 +3,18 @@ use super::*;
#[tokio::test]
async fn basic() {
let db = PatchDb::open("test.db").await.unwrap();
db.put(&JsonPointer::<&'static str>::default(), &Sample{a: "test1".to_string(), b: Child{a: "test2".to_string(), b: 4} }).await.unwrap();
db.put(
&JsonPointer::<&'static str>::default(),
&Sample {
a: "test1".to_string(),
b: Child {
a: "test2".to_string(),
b: 4,
},
},
)
.await
.unwrap();
let ptr: JsonPointer = "/b/b".parse().unwrap();
db.put(&ptr, &"hello").await.unwrap();
let get_res: Value = db.get(&ptr).await.unwrap();
@@ -17,6 +28,12 @@ pub struct Sample {
}
pub struct SampleModel(Model<Sample>);
impl core::ops::Deref for SampleModel {
type Target = Model<Sample>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Child {