[][src]Struct easydb::EasyDB

pub struct EasyDB { /* fields omitted */ }

The main type for dealing with easydb.

Create an EasyDB using new or from_uuid_token.

Methods

impl EasyDB[src]

pub fn new() -> EdbResult<Self>[src]

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()?;

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

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);

pub fn uuid(&self) -> &str[src]

Returns the stored UUID.

pub fn token(&self) -> &str[src]

Returns the stored token.

pub fn url(&self) -> &str[src]

Returns the stored URL.

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

Gets the value associated with key.

Example

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

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

Gets the value associated with key in json format.

Example

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

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

Assigns value to key and returns the status code.

Example

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

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

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

Example

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

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

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

Example

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

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

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()?;

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

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

Example

let map = edb.list()?;

pub fn clear(&self) -> EdbResult<()>[src]

Clears the database.

Example

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

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

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: "".

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

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

impl Debug for EasyDB[src]

impl FromStr for EasyDB[src]

type Err = EdbError

The associated error which can be returned from parsing.

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

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");

impl Serialize for EasyDB[src]

impl<'de> Deserialize<'de> for EasyDB[src]

Auto Trait Implementations

impl Send for EasyDB

impl Sync for EasyDB

impl Unpin for EasyDB

impl !UnwindSafe for EasyDB

impl !RefUnwindSafe for EasyDB

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

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

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

type Err = <T as FromStr>::Err

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

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