A highly Performant SQL Toolkit and Compile time ORM Library. An async, pure Rust SQL crate featuring compile-time Dynamic SQL
It is an ORM, a small compiler, a dynamic SQL languages
- Compatible with most mybatis3 syntax
- No Runtimes,No Garbage Collection,High performance, Based on Future/Tokio
- Zero cost Dynamic SQL, implemented using (proc-macro,compile-time,Cow(Reduce unnecessary cloning)) techniques。 don't need ONGL engine(mybatis)
- JDBC-like driver design, driver use cargo.toml dependency and
Box<dyn Driver>
separation - All database drivers supported
#{arg}
,${arg}
,?
placeholder(pg/mssql auto processing '?' to '$1' and '@P1') - Dynamic SQL(Write code freely in SQL),pagination,
py_sql
query lang andhtml_sql
(Inspired Mybatis). - Dynamic configuration connection pool(Based on the mobc)
- Supports logging, customizable logging based on
log
crate - 100% Safe Rust with
#![forbid(unsafe_code)]
enabled - Support use Trait System Add
py_sql/ html_sql
functions.see - rbatis/example (import into Clion!)
- abs_admin project an complete background user management system( Vue.js+rbatis+actix-web)
- Thanks to
SQLX, mobc, Tiberius, MyBatis,xorm
and so on reference design or code implementation. release of V4.0 is Inspired and supported by these frameworks
Performance
- this bench test is MockTable,MockDriver,MockConnection to Assume that the network I/O time is 0
- run code
MockTable::insert(&mut rbatis.clone(),&t).await;
on benches/fn bench_insert() - use
command
cargo test --release --package rbatis --bench raw_performance bench_insert --no-fail-fast -- --exact -Z unstable-options --show-output
//---- bench_insert stdout ----(win10,cpu-amd5950x)
// use Time: 130.5443ms ,each:1305 ns/op
// use QPS: 765860 QPS/s
//---- bench_insert stdout ----(macos,cpu-M1Max)
//use Time: 128.635666ms ,each:1286 ns/op
//use QPS: 777351 QPS/s
Supported data structures
data structure | is supported |
---|---|
Option | √ |
Vec | √ |
HashMap | √ |
i32,i64,f32,f64,bool,String...more rust type | √ |
rbatis::rbdc::types::{Date,FastDateTime,Time,Timestamp,Decimal,Json} | √ |
rbatis::plugin::page::{Page, PageRequest} | √ |
rbs::Value* | √ |
serde_json::* | √ |
any serde type | √ |
driver type on package (rdbc-mysql/types,rbdc-pg/types,rbdc-sqlite/types) | √ |
Supported database driver
database | crates.io | github_link |
---|---|---|
Mysql | rbdc-mysql | rbatis |
Postgres | rbdc-pg | rbatis |
Sqlite | rbdc-sqlite | rbatis |
Mssql | rbdc-mssql | rbatis |
MariaDB | rbdc-mysql | rbatis |
TiDB | rbdc-mysql | rbatis |
CockroachDB | rbdc-pg | rbatis |
Oracle | rbdc-oracle | chenpengfan |
Supported OS/Platforms by Workflows CI
platform | is supported |
---|---|
Linux(unbutu laster***) | √ |
Apple/MacOS(laster) | √ |
Windows(latest) | √ |
Supported Web Frameworks
- any web Frameworks just like actix-web,axum,hyper*,rocket,tide,warp,salvo...... and more
Quick example: QueryWrapper and common usages (see example/crud_test.rs for details)
- Cargo.toml
# logging(option)
= "0.4"
= "1.5"
# serde/rbs (required)
= { = "1", = ["derive"] }
= { = "0.1"}
= { = "4.0"}
# choose one rbdc drivier
= { = "0.1" }
#rbdc-mysql={version="0.1"}
#rbdc-pg={version="0.1"}
#rbdc-mssql={version="0.1"}
#...other database driver...
//#[macro_use] define in 'root crate' or 'mod.rs' or 'main.rs'
extern crate rbatis;
extern crate rbdc;
use ;
use FastDateTime;
crud!;//crud = insert+select_by_column+update_by_column+delete_by_column
impl_select!;
impl_select!;
impl_update!;
impl_delete!;
impl_select_page!;
async
///...more usage,see crud.rs
macros (new addition)
- Important update (pysql removes runtime, directly compiles to static rust code) This means that the performance of SQL generated using py_sql,html_sql is roughly similar to that of handwritten code.
Because of the compile time, the annotations need to declare the database type to be used.
async
- Added html_sql support, a form of organization similar to MyBatis, to facilitate migration of Java systems to Rust( Note that it is also compiled as Rust code at build time and performs close to handwritten code) this is very faster
Because of the compile time, the annotations need to declare the database type to be used
`select * from biz_activity where `
name like #{name}
///select page must have '?:&PageRequest' arg and return 'Page<?>'
async
use Lazy;
pub static RB: = new;
/// Macro generates execution logic based on method definition, similar to @select dynamic SQL of Java/Mybatis
/// RB is the name referenced locally by Rbatis, for example DAO ::RB, com:: XXX ::RB... Can be
/// The second parameter is the standard driver SQL. Note that the corresponding database parameter mysql is? , pg is $1...
/// macro auto edit method to 'pub async fn select(name: &str) -> rbatis::core::Result<BizActivity> {}'
///
pub async
//or: pub async fn select(name: &str) -> rbatis::core::Result<BizActivity> {}
pub async
Changelog
Roadmap
- sqlite table sync plugin(auto create table/column)
- Static analysis and generate executable test functions
Contact/donation, or click on star rbatis
联系方式/捐赠,或 rbatis 点star
捐赠
联系方式(添加好友请备注'rbatis') 微信群:先加微信,然后拉进群