cuppa

Crates.iocuppa
lib.rscuppa
version0.0.18
sourcesrc
created_at2021-06-02 21:34:18.377938
updated_at2021-11-19 21:50:02.471294
descriptionStandard library with usefull methods to boots the development
homepage
repositoryhttps://github.com/cloudbit-interactive/cuppars.git
max_upload_size
id405489
size51,522
Tufik Chediak Sanchez (tufik2)

documentation

README

DataBase

Add next dependencies to your Cargo.toml

[dependencies]
mysql = "20.1.0"
serde_json = "1.0.64"
serde = { version = "1.0.126", features = ["derive"] }
serde_derive = "1.0.126"

Example

use cuppa::database::DataBase;
use serde_json::{json, Map};

fn main() { 
    // CREATE CONNECTION
    let db = DataBase::new("localhost", 3306, "rust", "root", "");

    // ADD: IF ROW EXIST UPDATE IT, OTHERWISE INSERT A NEW ROW
    let mut data = Map::new();
        data.insert("name".to_string(), json!("Francisco"));
    let row = db.update("users".to_string(), data, "id = 3".to_string(), "".to_string());
    println!("{:?}", row);

    // INSERT
    let mut data = Map::new();
        data.insert("name".to_string(), json!("Francisco"));

    let row = db.update("users".to_string(), data, "id = 3".to_string(), "".to_string());
    println!("{:?}", row);

    // UPDATE
    let mut data = Map::new();
        data.insert("name".to_string(), json!("Francisco"));

    let row = db.update("users".to_string(), data, "id = 3".to_string(), "".to_string());
    println!("{:?}", row);

    // GET ROW
    let row = db.get_row("users".to_string(), "id = 99".to_string(), "".to_string(), "".to_string());
    println!("{:?}", row);

    // GET LIST
    let rows = db.get_list("users".to_string(), "".to_string(), "10".to_string(), "id ASC".to_string(), "id, name".to_string());
    println!("{:?}", rows);

    // SQL QUERY
    let rows = db.sql("SELECT * from users".to_string()).unwrap();
    println!("{:?}", rows);
}
Commit count: 29

cargo fmt