pub struct JsonDatabase<T> { /* private fields */ }
Expand description
A simple JSON file-based database ORM for Rust.
Implementations§
Source§impl<T> JsonDatabase<T>
impl<T> JsonDatabase<T>
Sourcepub fn create_model(&self, data: T)
pub fn create_model(&self, data: T)
Sourcepub fn create(&self, id: &str, data: T)
pub fn create(&self, id: &str, data: T)
Creates a new record in the database.
§Arguments
id
- The ID of the record.data
- The data to create.
Sourcepub fn find_by_id(&self, id: &str) -> Option<T>
pub fn find_by_id(&self, id: &str) -> Option<T>
Sourcepub fn update_by_id(&self, id: &str, data: Value)
pub fn update_by_id(&self, id: &str, data: Value)
Sourcepub fn delete_by_id(&self, id: &str)
pub fn delete_by_id(&self, id: &str)
Sourcepub fn update_many(&self, condition: &Value, data: &Value)
pub fn update_many(&self, condition: &Value, data: &Value)
Updates multiple records matching a condition.
§Arguments
condition
- The condition to match.data
- The data to update.
Sourcepub fn delete_many(&self, condition: &Value)
pub fn delete_many(&self, condition: &Value)
Sourcepub fn push(&self, condition: &Value, array_path: &str, element: &Value)
pub fn push(&self, condition: &Value, array_path: &str, element: &Value)
Adds an element to an array in records matching a condition.
§Arguments
condition
- The condition to match.array_path
- The path to the array.element
- The element to add.
Sourcepub fn pull(&self, condition: &Value, array_path: &str, pull_condition: &Value)
pub fn pull(&self, condition: &Value, array_path: &str, pull_condition: &Value)
Removes elements from an array in records matching a condition.
§Arguments
condition
- The condition to match.array_path
- The path to the array.pull_condition
- The condition to match elements to remove.
Sourcepub fn update_array(
&self,
condition: &Value,
array_path: &str,
array_condition: &Value,
updates: &Value,
)
pub fn update_array( &self, condition: &Value, array_path: &str, array_condition: &Value, updates: &Value, )
Updates elements in an array in records matching a condition.
§Arguments
condition
- The condition to match.array_path
- The path to the array.array_condition
- The condition to match array elements.updates
- The updates to apply to matching elements.
Source§impl JsonDatabase<()>
impl JsonDatabase<()>
Sourcepub fn set_base_dir(base_dir: &str)
pub fn set_base_dir(base_dir: &str)
Trait Implementations§
Source§impl<T: Clone> Clone for JsonDatabase<T>
impl<T: Clone> Clone for JsonDatabase<T>
Source§fn clone(&self) -> JsonDatabase<T>
fn clone(&self) -> JsonDatabase<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl<T> Freeze for JsonDatabase<T>
impl<T> RefUnwindSafe for JsonDatabase<T>where
T: RefUnwindSafe,
impl<T> Send for JsonDatabase<T>where
T: Send,
impl<T> Sync for JsonDatabase<T>where
T: Sync,
impl<T> Unpin for JsonDatabase<T>where
T: Unpin,
impl<T> UnwindSafe for JsonDatabase<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more