Coroutine Database driver Connectivity.based on cogo
Future<'q,Output=*>
,No async fn
, No .await
, no Poll* func,No Pin
| crates | Concurrency | feature level | All Smart tips | Libc
| have proc macro | separation driver | support env/crates |
|--------|---------------|---------------|----------------|------------|----------------------|----------------------|----------------------------------------------------------------------------------|
| cdbc | CSP(cogo) | lower | √ | only sqlite | Don't need | √ | cogo
, cogo/std/http
, native-thread
,tokio-spawn_blocking
|
| rbatis | Future(tokio) | heavy-weight | √ | only sqlite | only pysql,htmlsql | x | tokio, asyncstd, smol |
| sqlx | Future(tokio) | lower | x | only sqlite | only derive(StructOpt) | x | tokio, asyncstd, smol |
| diesel | Native Thread | lower | x | all-libc | derive(Queryable) | x | native thread |
| crates | Requests/sec | Mem | CpuLoad |
|------------------|--------------|------|--------|
| cdbc-cogo-http | 4237.31 | 28MB | 6% |
| sqlx-axum-tokio | 4024.23 | 17MB | 8% |
| sqlx-actix-async-std | 559.00 | 22MB | 2% |
| diesel | * | * | * |
cdbc
The driver abstraction lib.cdbc-mysql
CDBC mysql driver librarycdbc-pg
CDBC postgres driver librarycdbc-sqlite
CDBC sqlite driver libraryVec
].use example:
cargo.toml ```toml
must dep
cdbc = {version = "0.1"}
cdbc-mysql = {version = "0.1"}
cdbc-pg = {version = "0.1"}
cdbc-sqlite = {version = "0.1"}
* 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
//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);
//transaction
let mut tx = pool.acquire()?.begin()?;
let data=tx.execute("update biz_activity set delete_flag where id = \"1\"")?;
println!("{:?}", data.rows_affected());
tx.commit()?;
Ok(())
}
fn makesqlite() -> cdbc::Result
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