Database driver abstraction layer for Rust, providing a unified interface for rbatis.
Features
- Safe:
#![forbid(unsafe_code)]- 100% safe Rust - Async: Native async support based on Tokio
- Extensible: Simple trait definitions for easy driver implementation
Supported Databases
| Database | Driver |
|---|---|
| MySQL | rbdc-mysql |
| PostgreSQL | rbdc-pg |
| SQLite | rbdc-sqlite |
| MSSQL | rbdc-mssql |
| Truso | rbdc-turso |
Quick Start
use rbdc_sqlite::SqliteDriver; use rbdc_pool_fast::FastPool; #[tokio::main] async fn main() -> Result<(), rbdc::Error> { let pool = FastPool::new_url(SqliteDriver {},"sqlite://target/test.db")?; let mut conn = pool.get().await?; let v = conn.get_values("SELECT * FROM sqlite_master", vec![]).await?; println!("{}", v); //if need decode use `let result:Vec<Table> = rbs::from_value(v)?;` Ok(()) }
Implement Custom Driver
Implement these 6 traits:
use rbdc::db::{Driver, MetaData, Row, Connection, ConnectOptions, Placeholder}; impl Driver for YourDriver {} impl MetaData for YourMetaData { //TODO imple methods } impl Row for YourRow { //TODO imple methods } impl Connection for YourConnection { //TODO imple methods } impl ConnectOptions for YourConnectOptions { //TODO imple methods } impl Placeholder for YourPlaceholder { //TODO imple methods } /// use your driver #[tokio::main] async fn main() -> Result<(), rbdc::Error> { let uri = "YourDriver://****"; let pool = FastPool::new_url(YourDriver{}, uri)?; let mut conn = pool.get().await?; let v = conn.get_values("SELECT 1", vec![]).await?; println!("{}", v); }
For databases with blocking APIs, refer to rbdc-sqlite which uses the flume channel library.
See examples for more.
License
MIT