Struct JsonDB

Source
pub struct JsonDB { /* private fields */ }
Expand description

Database struct (does not use ::new instead uses ::init)

§Examples

let db = JsonDB::init("your db name")?;

§Note:

Does not handle errors in version “0.1.0” just passes on to user

Implementations§

Source§

impl JsonDB

Source

pub fn init(path: &str) -> Result<JsonDB, Box<dyn Error>>

Init function (takes the place of ::new)

§Examples
let db = JsonDB::init("your db name")?;
Source

pub fn create_collection<S>( self, collection_path: S, ) -> Result<JsonDB, Box<dyn Error>>
where S: Into<String>,

Creates a new collection either in your database or in another collection

§Examples
db.create_collection("your collection path")?;
Source

pub fn write<J, S>( self, collection_path: S, document: S, data: J, ) -> Result<JsonDB, Box<dyn Error>>
where J: Serialize, S: Into<String>,

Writes (or rewrites) data to document in collection

§Examples
db.write("your collection path", "your document", "struct that derives serde::serialize")?;
Source

pub fn read<D, S>( self, collection_path: S, document: S, ) -> Result<D, Box<dyn Error>>
where for<'a> D: Deserialize<'a>, S: Into<String>,

Reads data from document in collection

let data: impl serde::Deserialize = db.read("your collection path", "your document")?;
Source

pub fn delete<S>( self, collection_path: S, document: S, ) -> Result<JsonDB, Box<dyn Error>>
where S: Into<String>,

Deletes document in collection

§Examples
db.delete("your collection path", "your document")?;
Source

pub fn list<S>(self, collection_path: S) -> Result<Vec<String>, Box<dyn Error>>
where S: Into<String>,

List all document in a collection

§Examples
let list: Vec<String> = db.list("your collection path")?;

Auto Trait Implementations§

§

impl Freeze for JsonDB

§

impl RefUnwindSafe for JsonDB

§

impl Send for JsonDB

§

impl Sync for JsonDB

§

impl Unpin for JsonDB

§

impl UnwindSafe for JsonDB

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.