[−][src]Crate easydb
An interface for working with easydb.io in rust.
Quick start
use easydb::EasyDB; // Create an EasyDB struct to interact with. // Gets information from `./easydb.toml`. let edb: EasyDB = EasyDB::new().unwrap(); // Store some data edb.put("hello", "world").unwrap(); edb.put("goodbye", "earth").unwrap(); // Get a single item let stored_hello: String = edb.get("hello").unwrap(); assert_eq!(&stored_hello, "world"); // Update an item edb.put("goodbye", "dirt").unwrap(); assert_eq!(&edb.get("goodbye").unwrap(), "dirt"); // Get a HashMap of all database entries let resp: HashMap<String, String> = edb.list().unwrap(); assert_eq!(&resp["hello"], "world"); assert_eq!(&resp["goodbye"], "dirt"); // Delete items edb.delete("hello").unwrap(); let deleted_item: String = edb.get("hello").unwrap(); assert_eq!(&deleted_item, "");
Commands
The easiest way to create an EasyDB
is to call EasyDB::new()
.
This generates the struct using data in ./easydb.toml
, which should include the following
information:
UUID = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
Token = "ffffffff-0000-1111-2222-333333333333"
URL = "https://app.easydb.io/database/"
The URL
field is optional and will default to https://app.easydb.io/database/
.
If your toml is not at the default location, you can just
parse
it. For example:
let edb: EasyDB = "UUID = \"aaaa...\"\nToken = \"ffff...\"".parse().unwrap();
If you have individual items, you can initalize an EasyDB
with
from_uuid_token
:
let edb = EasyDB::from_uuid_token("aaaa...".to_string(), "ffff...".to_string(), None);
Using the EasyDB
The four methods get
, put
, delete
, and list
correspond to the four
available APIs in easydb.io
. get
and delete
take one argument: a key. put
takes two
arguments: a key
and a value
. list
takes no arguments. Example usage can be seen in the
Quick start section at the top of this page.
Errors
All network errors as reported by the reqwest
crate are returned in Result
s. Other errors
are documented on their respective methods.
Structs
EasyDB | |
EdbError | The Error type. |
Enums
EdbErrorKind | The kind of an error. |
Traits
EdbResultExt | Additional methods for |
Type Definitions
EdbResult | Convenient wrapper around |