mirror of
https://github.com/Start9Labs/patch-db.git
synced 2026-03-26 10:21:53 +00:00
wip: macros
This commit is contained in:
@@ -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())?;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user