cdbc
Coroutine Database driver Connectivity.based on cogo
- High concurrency,based on coroutine
- No
Future<'q,Output=*>,Noasync fn, No.await, no Poll* func,NoPin - Optimize the trait system so that it has intelligent hints of the base method
- NativeTls and TCP connections are supported
- Low coupling,The database driver and the abstraction layer are designed separately
- Lightweight, no over-design, only have macro with intelligent tips
- Inspired by golang, cogo, sqlx
Why cdbc ?
| 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 py_sql,html_sql | x | tokio, async_std, smol |
| sqlx | Future(tokio) | lower | x | only sqlite | only derive(StructOpt) | x | tokio, async_std, smol |
| diesel | Native Thread | lower | x | all-libc | derive(Queryable) | x | native thread |
concurrency benchmark performance(Compare the SQLX/Tokio/Async-std)
| crates | Requests/sec | Mem | CpuLoad |
|---|---|---|---|
| cdbc-cogo-http | 4606 | 30MB | 6% |
| sqlx-axum-tokio | 4560 | 17MB | 8% |
| sqlx-actix-async-std | 559.00 | 22MB | 2% |
| diesel | * | * | * |
- benchmark with wrk(docker run -it --net=host --rm williamyeh/wrk -t12 -c400 -d30s http://192.168.28.235:8000)
- see detail benchmark
Database Support:
cdbcThe driver abstraction lib.cdbc-mysqlCDBC mysql driver librarycdbc-pgCDBC postgres driver librarycdbc-sqliteCDBC sqlite driver library
Supported functions
- execute: Execute the query and return the total number of rows affected.
- execute_many: Execute multiple queries and return the rows affected from each query, in a stream.
- fetch: Execute the query and return the generated results as a stream.
- fetch_many: Execute multiple queries and return the generated results as a stream,from each query, in a stream.
- fetch_all: Execute the query and return all the generated results, collected into a [
Vec]. - fetch_one: Execute the query and returns exactly one row.
- fetch_optional: Execute the query and returns at most one row.
- prepare: Prepare the SQL query to inspect the type information of its parameters and results
- prepare_with: Prepare the SQL query, with parameter type information, to inspect the type information about its parameters and results.
Supported transaction
- Pool: begin(),commit(),rollback()
- Connection: begin(),commit(),rollback()
use example:
cargo.toml
#must dep
= { = "0.1"}
#optional dep
= { = "0.1"}
= { = "0.1"}
= { = "0.1"}
- row_scan macro
use File;
use Executor;
use SqlitePool;
- Processing read streams
main.rs
use BTreeMap;
use ;
use ;
use ;
use cratemake_sqlite;