cdbc

Coroutine Database driver Connectivity.based on may

Database Support:

Supported functions

use example:

cargo.toml ```toml

must dep

cdbc = {version = "*"}

optional dep

cdbc-mysql = {version = ""} cdbc-pg = {version = ""} cdbc-sqlite = {version = "*"} * row_scan macro rust use std::fs::File; use cdbc::Executor; use cdbc_sqlite::SqlitePool;

fn main() -> cdbc::Result<()> { let pool = makesqlite()?; #[derive(Debug)] pub struct BizActivity { pub id: Option, pub name: Option, pub deleteflag: Option, }

//execute
let data = pool.acquire()?.execute("update biz_activity set delete_flag where id = \"1\"")?;
println!("{:?}", data.rows_affected());

//fetch_all
let query = cdbc::query("select * from biz_activity where id = ?")
    .bind("1");
let row = pool.acquire()?.fetch_all(query)?;
let data = cdbc::row_scans!(row,BizActivity{id:None,name:None,delete_flag:None})?;
println!("{:?}", data);

//fetch_one
let data = cdbc::row_scan!(
    cdbc::query("select * from biz_activity where id = ?")
    .bind("1")
    .fetch_one(pool)?,
    BizActivity{id:None,name:None,delete_flag:None})?;
println!("{:?}", data);
Ok(())

}

fn makesqlite() -> cdbc::Result { //first. create sqlite dir/file std::fs::createdirall("target/db/"); File::create("../../../target/db/sqlite.db"); //next create table and query result let pool = SqlitePool::connect("sqlite://target/db/sqlite.db")?; let mut conn = pool.acquire()?; conn.execute("CREATE TABLE bizactivity( id string, name string,age int, deleteflag int) "); conn.execute("INSERT INTO bizactivity (id,name,age,delete_flag) values (\"1\",\"1\",1,0)"); Ok(pool) } ```

fn teststreamsqlite() -> cdbc::Result<()> { //first. create sqlite dir/file let pool = makesqlite().unwrap(); //next create table and query result let mut conn = pool.acquire()?; let mut data: ChanStream = conn.fetch("select * from bizactivity;"); data.tryforeach(|item| { let mut m = BTreeMap::new(); for column in item.columns() { let v = item.trygetraw(column.name())?; let r: Option = Decode::<', Sqlite>::decode(v)?; m.insert(column.name().tostring(), r); } println!("{:?}", m); drop(m); Ok(()) })?; Ok(()) } ```