Crate replit_db

Source
Expand description

§replit_db

An unofficial database adapater for Replit Database for Rust!

§Usage

You need to import Database, Config, and a trait (Synchronous, Asynchronous). Then initialize Database::new() with Config::new() then database will give you function in either synchronously or asynchronously based on trait you imported in to the scope.

§Possible Exceptions

Error struct contain useful informations and both std::fmt::Display and std::error::Error (support “?”). Also there’s different error kinds that can happens, here’s the list of them.

§Examples

§Example (Synchronous)

use replit_db::{Synchronous, Error};

fn main() -> Result<(), Error> {

    let db = replit_db::Database::new(replit_db::Config::new().unwrap());
    db.get("Hello")?; // Get a value from key's name.
    db.set("Hello", "World")?; // Set a value to that key
    db.delete("Hello")?; // Delete a key
    db.list(replit_db::STRING_NONE)?; // List all keys
    db.list(Some("H"))?; // List keys with "H" prefix
    return Ok(())
}

§Example (Asynchronous)

use replit_db::{Asynchronous, Error};

use tokio;

#[tokio::main]
async fn main() -> Result<(), Error> {

    let db = replit_db::Database::new(replit_db::Config::new().unwrap());
    db.get("Hello").await?; // Get a value from key's name.
    db.set("Hello", "World").await?; // Set a value to that key
    db.delete("Hello").await?; // Delete a key
    db.list(replit_db::STRING_NONE).await?; // List all keys
    db.list(Some("H")).await?; // List keys with "H" prefix
    return Ok(())
}

Structs§

Config
Configuration struct that contains information needed for Database.
Database
Database main struct. Please use this database with traits. (Availables are Synchronous and Asynchronous)
Error
Error struct for giving useful information about what goes wrong.

Enums§

ErrorKind
Error kind. (Http Error, No Item Found Error, Decode String Error)

Constants§

STRING_NONE
This type is a shorthand for Option<&str>::None or None::<&str>.

Traits§

Asynchronous
Asynchronous support for Database struct. Use this trait by import it then use it right away!
Synchronous
Synchronous support for Database struct. Use this trait by import it then use it right away!