RBatis 增强生态 —— MyBatis-Plus 风格的 Mapper / Service / Wrapper / 缓存 / 类型处理器,为 Rust ORM 提供企业级工程能力
Rbatis-Plus 是 partme-ai 开源生态旗下的 RBatis ORM 增强组织,专注于为 RBatis(编译期 async 动态 SQL ORM)提供 MyBatis-Plus 风格的工程化能力。
我们的核心理念是:
让 Rust 开发者拥有和 MyBatis-Plus 一样顺手的数据访问体验 —— 强类型 Wrapper、自动 CRUD、二级缓存、多数据源、零样板代码。
- 🧩 Wrapper 优先 — 链式构造 SQL,强类型条件,零字符串拼接
- 🗄️ 多数据库 — 通过
rbatis+rbdc统一访问 MySQL / PostgreSQL / SQLite / MSSQL / 达梦 / 金仓 / 神通 - ⚡ 二级缓存 — Redis / Memcached / Caffeine / in-process SPI 可插拔
- 🕒 JSR-310 兼容 —
LocalDateTime/Instant/ZonedDateTime原生支持 - 🚀 编译期优化 — 借助 RBatis 的编译期 SQL 解析,零运行时反射
| 仓库 | 说明 |
|---|---|
| rbatis | 编译期 async 动态 SQL ORM(fork & 增强) |
| rbatis-plus | MyBatis-Plus 风格 mapper / service / wrapper 主库 |
| rbdc | rbdc-drivers —— 多数据库驱动集合 |
⚠️ 重要:rbatis 核心库本身不支持缓存(与 MyBatis 不同)。要使用二级缓存,必须 依赖rbatis-cache提供 SPI,然后再选一个后端实现。
| 仓库 | 说明 |
|---|---|
| rbatis-cache | 二级缓存 SPI 接口层 —— 必装 |
| rbatis-redis | Redis 二级缓存实现 |
| rbatis-memcached | Memcached 二级缓存实现 |
| rbatis-moka | Moka 内存缓存实现(进程内) |
| 仓库 | 说明 |
|---|---|
| rbatis-typehandlers-jsr310 | JSR-310(Java Time)兼容类型处理器 |
┌─────────────────────────────────────────────────────────────┐
│ 应用层 (Application Layer) │
│ Service · Mapper · Wrapper · Page · LambdaQuery │
└──────────────────────────┬──────────────────────────────────┘
│
┌──────────────────────────▼──────────────────────────────────┐
│ rbatis-plus (核心增强) │
│ ActiveRecord · BaseMapper · IService · Wrapper · Tenant │
└──────────────────────────┬──────────────────────────────────┘
│
┌──────────────────────────▼──────────────────────────────────┐
│ rbatis (编译期 SQL 解析 / 执行) │
└──────────────────────────┬──────────────────────────────────┘
│
┌──────────────────┼──────────────────┐
│ │ │
┌───────▼──────┐ ┌────────▼────────┐ ┌──────▼───────┐
│ rbdc-drivers │ │ rbatis-cache │ │ typehandlers │
│ MySQL/PG/... │ │ Redis/Mem/... │ │ JSR-310/... │
└──────────────┘ └─────────────────┘ └──────────────┘
[dependencies]
# 核心 ORM(编译期 SQL)
rbatis = "4"
# 增强生态
rbatis-plus = "0.1"
rbdc = "0.1"
# 二级缓存(任选)
rbatis-redis = { version = "0.1", optional = true }
rbatis-moka = { version = "0.1", optional = true }
# 数据库驱动
sqlx = { version = "0.7", features = ["mysql", "runtime-tokio-rustls"] }
# 运行时
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }use rbatis_plus::prelude::*;
use serde::{Serialize, Deserialize};
#[derive(Clone, Debug, Serialize, Deserialize, BaseMapper)]
#[table_name = "t_user")]
pub struct User {
pub id: i64,
pub name: String,
pub email: String,
pub age: Option<i32>,
pub created_at: chrono::DateTime<Utc>,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let rb = Rbatis::new();
rb.link("mysql://user:pass@localhost/db").await?;
// 链式 Wrapper
let users: Vec<User> = User::select_chain()
.eq("age", 18)
.like("name", "%张%")
.order_by("created_at", false)
.page(1, 20)
.fetch(&rb)
.await?;
println!("found {} users", users.len());
Ok(())
}use rbatis_plus::cache::CacheConfig;
CacheConfig::builder()
.backend(rbatis_redis::RedisBackend::new("redis://localhost:6379"))
.ttl(300) // 5 min
.build()
.install(&rb)?;| 能力 | MyBatis-Plus (Java) | Rbatis-Plus (Rust) |
|---|---|---|
| 通用 CRUD | BaseMapper<T> |
BaseMapper trait |
| 链式 Wrapper | LambdaQueryWrapper |
select_chain() |
| 分页 | Page<T> |
page(page, size) |
| 多租户 | TenantLineInnerInterceptor |
Tenant filter |
| 二级缓存 | Spring Cache | rbatis-cache SPI |
| 类型处理器 | BaseTypeHandler |
typehandlers-jsr310 |
| 逻辑删除 | @TableLogic |
soft_delete() |
| 自动填充 | MetaObjectHandler |
AutoFill derive |
| 多数据源 | DynamicDataSource |
多 Rbatis 实例 |
| 组织 | 说明 |
|---|---|
| 🏛️ ddd-4-rust | DDD 基础构件(Repository 实现层) |
| 🧰 easy-4-rust | 业务工具集 |
| 🧰 easy-4-java | Java 工具集 |
| 🧠 partme-ai | 顶层 AI 智能体生态 |
欢迎贡献新的增强能力!
- Fork 目标仓库
- 创建特性分支
- 遵循既有 API 风格(Builder / Wrapper / trait)
- 补充单元测试、文档与 CHANGELOG
- 提交 Pull Request
重大设计变更请先在 Discussions 发起 RFC。
- Email: partmeai@gmail.com
- GitHub: github.com/rbatis-plus
让 Rust ORM 拥有 MyBatis-Plus 一样的工程体验
Made with ❤️ by PartMe AI Team