Skip to content
@rbatis-plus

Rbatis-Plus

💾 RBatis ORM 增强生态 —— 为 RBatis 提供 MyBatis-Plus 风格的 Mapper / Service / Wrapper / 二级缓存 / 类型处理器,让 Rust ORM 拥有企业级工程能力。

Rbatis-Plus

Rbatis-Plus

RBatis 增强生态 —— MyBatis-Plus 风格的 Mapper / Service / Wrapper / 缓存 / 类型处理器,为 Rust ORM 提供企业级工程能力

Repos Architecture Tools Ecosystem License


关于我们

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 —— 多数据库驱动集合

二级缓存(Cache SPI)

⚠️ 重要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"] }

定义实体 + Wrapper 查询

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 的能力对照

能力 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 智能体生态

贡献指南

欢迎贡献新的增强能力!

  1. Fork 目标仓库
  2. 创建特性分支
  3. 遵循既有 API 风格(Builder / Wrapper / trait)
  4. 补充单元测试、文档与 CHANGELOG
  5. 提交 Pull Request

重大设计变更请先在 Discussions 发起 RFC。


联系我们


让 Rust ORM 拥有 MyBatis-Plus 一样的工程体验

Made with ❤️ by PartMe AI Team

Popular repositories Loading

  1. rbatis rbatis Public

    Forked from rbatis/rbatis

    Compile Time Async Dynamic SQL ORM

    Rust

  2. rbatis-cache rbatis-cache Public

    Second-level cache SPI for RBatis

    Rust

  3. rbatis-moka rbatis-moka Public

    Moka-backed in-process second-level cache for RBatis

    Rust

  4. rbatis-redis rbatis-redis Public

    Redis second-level cache backend for RBatis

    Rust

  5. rbatis-typehandlers-jsr310 rbatis-typehandlers-jsr310 Public

    Java time compatibility types for RBatis

    Rust

  6. rbatis-memcached rbatis-memcached Public

    Memcached second-level cache backend for RBatis

    Rust

Repositories

Showing 10 of 10 repositories

People

This organization has no public members. You must be a member to see who’s a part of this organization.

Top languages

Loading…

Most used topics

Loading…