mirror of
https://github.com/Start9Labs/patch-db.git
synced 2026-03-26 10:21:53 +00:00
Submodule json-patch updated: b92c0a0d53...1a18bb258f
2
json-ptr
2
json-ptr
Submodule json-ptr updated: 2415675acd...963405175a
@@ -239,23 +239,23 @@ fn impl_fns(children: &[ChildInfo]) -> Fns {
|
|||||||
if optional {
|
if optional {
|
||||||
impl_fns.extend(quote_spanned! { name.span() =>
|
impl_fns.extend(quote_spanned! { name.span() =>
|
||||||
#vis fn #name (&self) -> patch_db::OptionModel<#model_ty> {
|
#vis fn #name (&self) -> patch_db::OptionModel<#model_ty> {
|
||||||
<patch_db::OptionModel::<#model_ty> as patch_db::Model>::new((&**self) #accessor .clone())
|
<patch_db::OptionModel::<#model_ty> as patch_db::Model>::new((**self) #accessor .clone())
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
impl_mut_fns.extend(quote_spanned! { name.span() =>
|
impl_mut_fns.extend(quote_spanned! { name.span() =>
|
||||||
#vis fn #name (&self) -> patch_db::OptionModelMut<'a, #model_mut_ty> {
|
#vis fn #name (&'a mut self) -> patch_db::OptionModelMut<'a, #model_mut_ty> {
|
||||||
<patch_db::OptionModelMut::<'a, #model_mut_ty> as patch_db::ModelMut<'a>>::new(&mut (&mut **self) #accessor)
|
<patch_db::OptionModelMut::<'a, #model_mut_ty> as patch_db::ModelMut<'a>>::new(&mut (**self) #accessor)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
impl_fns.extend(quote_spanned! { name.span() =>
|
impl_fns.extend(quote_spanned! { name.span() =>
|
||||||
#vis fn #name (&self) -> #model_ty {
|
#vis fn #name (&self) -> #model_ty {
|
||||||
<#model_ty as patch_db::Model>::new((&**self) #accessor .clone())
|
<#model_ty as patch_db::Model>::new((**self) #accessor .clone())
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
impl_mut_fns.extend(quote_spanned! { name.span() =>
|
impl_mut_fns.extend(quote_spanned! { name.span() =>
|
||||||
#vis fn #name (&mut self) -> #model_mut_ty {
|
#vis fn #name (&'a mut self) -> #model_mut_ty {
|
||||||
<#model_mut_ty as patch_db::ModelMut<'a>>::new(&mut (&mut **self) #accessor)
|
<#model_mut_ty as patch_db::ModelMut<'a>>::new(&mut (**self) #accessor)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use std::path::{Path, PathBuf};
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use fd_lock_rs::FdLock;
|
use fd_lock_rs::FdLock;
|
||||||
use imbl_value::Value;
|
use imbl_value::{InternedString, Value};
|
||||||
use json_patch::PatchError;
|
use json_patch::PatchError;
|
||||||
use json_ptr::{JsonPointer, SegList};
|
use json_ptr::{JsonPointer, SegList};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
@@ -159,7 +159,7 @@ impl Store {
|
|||||||
pub(crate) fn keys<S: AsRef<str>, V: SegList>(
|
pub(crate) fn keys<S: AsRef<str>, V: SegList>(
|
||||||
&self,
|
&self,
|
||||||
ptr: &JsonPointer<S, V>,
|
ptr: &JsonPointer<S, V>,
|
||||||
) -> BTreeSet<Arc<String>> {
|
) -> BTreeSet<InternedString> {
|
||||||
match ptr.get(&self.persistent).unwrap_or(&Value::Null) {
|
match ptr.get(&self.persistent).unwrap_or(&Value::Null) {
|
||||||
Value::Object(o) => o.keys().cloned().collect(),
|
Value::Object(o) => o.keys().cloned().collect(),
|
||||||
_ => BTreeSet::new(),
|
_ => BTreeSet::new(),
|
||||||
@@ -326,7 +326,7 @@ impl PatchDb {
|
|||||||
pub async fn keys<S: AsRef<str>, V: SegList>(
|
pub async fn keys<S: AsRef<str>, V: SegList>(
|
||||||
&self,
|
&self,
|
||||||
ptr: &JsonPointer<S, V>,
|
ptr: &JsonPointer<S, V>,
|
||||||
) -> BTreeSet<Arc<String>> {
|
) -> BTreeSet<InternedString> {
|
||||||
self.store.read().await.keys(ptr)
|
self.store.read().await.keys(ptr)
|
||||||
}
|
}
|
||||||
pub async fn get_value<S: AsRef<str>, V: SegList>(&self, ptr: &JsonPointer<S, V>) -> Value {
|
pub async fn get_value<S: AsRef<str>, V: SegList>(&self, ptr: &JsonPointer<S, V>) -> Value {
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use imbl_value::Value;
|
||||||
use json_ptr::JsonPointer;
|
use json_ptr::JsonPointer;
|
||||||
use patch_db::{HasModel, PatchDb, Revision};
|
use patch_db::{HasModel, PatchDb, Revision};
|
||||||
use proptest::prelude::*;
|
use proptest::prelude::*;
|
||||||
use serde_json::Value;
|
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
use tokio::runtime::Builder;
|
use tokio::runtime::Builder;
|
||||||
|
|
||||||
use crate::{self as patch_db, DbHandle, LockType};
|
use crate::{self as patch_db};
|
||||||
|
|
||||||
async fn init_db(db_name: String) -> PatchDb {
|
async fn init_db(db_name: String) -> PatchDb {
|
||||||
cleanup_db(&db_name).await;
|
cleanup_db(&db_name).await;
|
||||||
@@ -45,23 +45,10 @@ async fn basic() {
|
|||||||
let db = init_db("test.db".to_string()).await;
|
let db = init_db("test.db".to_string()).await;
|
||||||
let ptr: JsonPointer = "/b/b".parse().unwrap();
|
let ptr: JsonPointer = "/b/b".parse().unwrap();
|
||||||
let mut get_res: Value = db.get(&ptr).await.unwrap();
|
let mut get_res: Value = db.get(&ptr).await.unwrap();
|
||||||
assert_eq!(get_res, 1);
|
assert_eq!(get_res.as_u64(), Some(1));
|
||||||
db.put(&ptr, "hello").await.unwrap();
|
db.put(&ptr, "hello").await.unwrap();
|
||||||
get_res = db.get(&ptr).await.unwrap();
|
get_res = db.get(&ptr).await.unwrap();
|
||||||
assert_eq!(get_res, "hello");
|
assert_eq!(get_res.as_str(), Some("hello"));
|
||||||
cleanup_db("test.db").await;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn transaction() {
|
|
||||||
let db = init_db("test.db".to_string()).await;
|
|
||||||
let mut handle = db.handle();
|
|
||||||
let mut tx = handle.begin().await.unwrap();
|
|
||||||
let ptr: JsonPointer = "/b/b".parse().unwrap();
|
|
||||||
tx.put(&ptr, &(2 as usize)).await.unwrap();
|
|
||||||
tx.put(&ptr, &(1 as usize)).await.unwrap();
|
|
||||||
let _res = tx.commit().await.unwrap();
|
|
||||||
println!("res = {:?}", _res);
|
|
||||||
cleanup_db("test.db").await;
|
cleanup_db("test.db").await;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,16 +87,3 @@ pub struct Child {
|
|||||||
|
|
||||||
#[derive(Debug, serde::Deserialize, serde::Serialize, HasModel)]
|
#[derive(Debug, serde::Deserialize, serde::Serialize, HasModel)]
|
||||||
pub struct NewType(Option<Box<Sample>>);
|
pub struct NewType(Option<Box<Sample>>);
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn locks_dropped_from_enforcer_on_tx_save() {
|
|
||||||
let db = init_db("test.db".to_string()).await;
|
|
||||||
let mut handle = db.handle();
|
|
||||||
let mut tx = handle.begin().await.unwrap();
|
|
||||||
let ptr_a: JsonPointer = "/a".parse().unwrap();
|
|
||||||
let ptr_b: JsonPointer = "/b".parse().unwrap();
|
|
||||||
tx.lock(ptr_b.into(), LockType::Write).await.unwrap();
|
|
||||||
tx.save().await.unwrap();
|
|
||||||
handle.lock(ptr_a.into(), LockType::Write).await.unwrap();
|
|
||||||
cleanup_db("test.db").await;
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user