Crates.io | dengine |
lib.rs | dengine |
version | 0.1.3 |
source | src |
created_at | 2018-09-22 17:36:03.531845 |
updated_at | 2018-09-29 09:39:55.89772 |
description | mysql/sqlite abstraction lib |
homepage | |
repository | https://github.com/hrishimk/dengine |
max_upload_size | |
id | 86011 |
size | 46,484 |
A RUST API over MYSQL and SQLITE APIs.
// extern crate dengine;
// #[macro_use]
// extern crate dengine_derive;
use dengine::Connectionable;
use dengine::Queryable;
use dengine::Row;
type DbCon = dengine::sqlite::Connection;
#[derive(Debug, Queryable)]
struct User {
id: u64,
name: String,
}
let con = DbCon::new(":memory:").unwrap();
let sql = "CREATE TABLE user (id INTEGER NOT NULL, name TEXT NOT NULL)";
con.execute(sql, ()).unwrap();
let sql = "INSERT INTO user (id, name) VALUES (?, ?), (?, ?)";
con.execute(sql, (1, "name1", 2, "name2")).unwrap();
let sql = "SELECT * from user";
let res: Vec<User> = con.array(sql, (), false).unwrap();
println!("{:?}", res);
//[User { id: 1, name: "name1" }, User { id: 2, name: "name2" }]
Important: Use https://github.com/diesel-rs/diesel instead of this lib
This library is created only because I am too stupid too understand the diesel documentation.