[−][src]Struct easydb::EasyDB
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]
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);
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]
pub fn get_json(&self, key: &str) -> EdbResult<Json>
[src]
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]
pub fn clear(&self) -> EdbResult<()>
[src]
pub fn get_writer<W>(&self, key: &str, value: &mut W) -> EdbResult<u16> where
W: Write,
[src]
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: ""
.
pub fn list_writer<W>(&self, list: &mut W) -> EdbResult<u16> where
W: Write,
[src]
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
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]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<'de> Deserialize<'de> for EasyDB
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
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]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
impl<'a, T> TryFrom<&'a str> for T where
T: FromStr,
T: FromStr,
type Err = <T as FromStr>::Err
fn try_from(string: &'a str) -> Result<T, <T as TryFrom<&'a str>>::Err>
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
U: TryFrom<T>,