Struct cuppa::database::DataBase [−][src]
pub struct DataBase {
pub host: &'static str,
pub port: u16,
pub db: &'static str,
pub user: &'static str,
pub pass: &'static str,
pub pool: Pool,
}
Fields
host: &'static str
port: u16
db: &'static str
user: &'static str
pass: &'static str
pool: Pool
Implementations
EXAMPLE
let db = DataBase::new("localhost", 3306, "rust", "root", "");
Mix of Insert / Update: The method checks if a row already exists and update it; otherwise, insert a new record. Both cases return the affected row.
EXAMPLE
let mut data = Map::new();
data.insert("name".to_string(), json!("Zulay"));
let row = db.add("users".to_string(), data, "id = 333".to_string(), "".to_string());
println!("{:?}", row);
Example
let mut data = Map::new();
data.insert("name".to_string(), json!("Francisco"));
let row = db.insert("users".to_string(), data, "".to_string());
println!("{:?}", row);
Example
let mut data = Map::new();
data.insert("name".to_string(), json!("Francisco"));
let row = db.update("users".to_string(), data, "id = 1".to_string(), "".to_string());
println!("{:?}", row);
Example
let rows = db.get_list("users".to_string(), "".to_string(), "10".to_string(), "id ASC".to_string(), "id, name".to_string());
println!("{:?}", rows);
Example
let total_rows = db.get_total_rows("users".to_string(), "".to_string());
println!("{:?}", total_rows);
Example
let row = db.get_row("users".to_string(), "id = 1".to_string(), "".to_string(), "".to_string());
println!("{:?}", row);
Example
let rows = db.sql("SELECT * from users".to_string()).unwrap();
println!("{:?}", rows);