Struct EasyDB

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

The main type for dealing with easydb.

Create an EasyDB using new or from_uuid_token.

Implementations§

Source§

impl EasyDB

Source

pub fn new() -> EdbResult<Self>

Creates an EasyDB using the easydb.toml in the current directory.

§Errors

Will fail if the file cannot be read (e.g. when it doesn’t exist), or if the UUID or URL does not form a valid URL.

§Example
let edb = EasyDB::new()?;
Source

pub fn from_uuid_token( uuid: String, token: String, url: Option<String>, ) -> EdbResult<Self>

Creates an EasyDB using a UUID, Token, and optional URL (defaults to https://app.easydb.io/database/).

§Errors

Will fail if url or uuid don’t form a valid URL.

§Example
let edb = EasyDB::from_uuid_token("aaaa...".to_string(), "bbbb...".to_string(), None);
Source

pub fn uuid(&self) -> &str

Returns the stored UUID.

Source

pub fn token(&self) -> &str

Returns the stored token.

Source

pub fn url(&self) -> &str

Returns the stored URL.

Source

pub fn get(&self, key: &str) -> EdbResult<String>

Gets the value associated with key.

§Example
let s = edb.get("somekey")?;
Source

pub fn get_json(&self, key: &str) -> EdbResult<Json>

Gets the value associated with key in json format.

§Example
let json = edb.get_json("somekey")?;
Source

pub fn put(&self, key: &str, value: &str) -> EdbResult<u16>

Assigns value to key and returns the status code.

§Example
let status = edb.put("somekey", "somevalue")?;
Source

pub fn put_json(&self, key: &str, value: Json) -> EdbResult<u16>

Assigns a json value to key and returns the status code.

§Example
let status = edb.put_json("somekey", json!({"a": "b"}))?;
Source

pub fn delete(&self, key: &str) -> EdbResult<u16>

Deletes the value associated with key and returns the status code.

§Example
let status = edb.delete("somekey")?;
Source

pub fn list(&self) -> EdbResult<HashMap<String, String>>

Returns a HashMap<String, String> of all the data in this database.

§Errors

Will fail if any of the values are not strings.

§Example
let map = edb.list()?;
Source

pub fn list_json(&self) -> EdbResult<HashMap<String, Json>>

Returns a HashMap<String, Json> of all the data in this database.

§Example
let map = edb.list()?;
Source

pub fn clear(&self) -> EdbResult<()>

Clears the database.

§Example
edb.clear()?;
assert_eq!(edb.list()?.len(), 0);
Source

pub fn get_writer<W>(&self, key: &str, value: &mut W) -> EdbResult<u16>
where W: Write,

An alternative to get() that works with a writer. Fetches data associated with key and writes into value, returning the status code.

The response should have the value that was originally set in JSON form. If the key was never set, was deleted, or has no data, the response will be an empty string: "".

Source

pub fn list_writer<W>(&self, list: &mut W) -> EdbResult<u16>
where W: Write,

An alternative to list() that works with a writer. Fetches all the data in the database and writes it to list, returning the status code.

Trait Implementations§

Source§

impl Debug for EasyDB

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for EasyDB

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl FromStr for EasyDB

Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Create an EasyDB from a &str in the TOML format.

§Example
let s = r#"
UUID = "abcd"
Token = "efgh"
"#;
let edb: EasyDB = s.parse()?;
assert_eq!(edb.uuid(), "abcd");
assert_eq!(edb.token(), "efgh");
Source§

type Err = EdbError

The associated error which can be returned from parsing.
Source§

impl Serialize for EasyDB

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for EasyDB

§

impl !RefUnwindSafe for EasyDB

§

impl Send for EasyDB

§

impl Sync for EasyDB

§

impl Unpin for EasyDB

§

impl !UnwindSafe for EasyDB

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<'a, T> TryFrom<&'a str> for T
where T: FromStr,

Source§

type Err = <T as FromStr>::Err

Source§

fn try_from(string: &'a str) -> Result<T, <T as TryFrom<&'a str>>::Err>

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.
Source§

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

Source§

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

Source§

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

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,