rabetbase
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRabetbase CLI
Rabetbase CLI
前置条件: 使用任何 API 命令前,需完成认证和配置(见下方)。 执行前必做: 执行任何命令前,必须先阅读对应命令的 reference 文档,再调用命令。 命名约定: 统一使用格式。 输出格式: AI Agent 必须使用rabetbase <service> <command> [flags]获取结构化输出。--format json
Prerequisites: Before using any API command, you need to complete authentication and configuration (see below). Mandatory before execution: Before executing any command, you must first read the reference documentation for the corresponding command before invoking it. Naming convention: Uniformly use theformat. Output format: AI Agent must userabetbase <service> <command> [flags]to get structured output.--format json
前置条件
Prerequisites
- 认证:通过浏览器完成 OAuth 登录
rabetbase auth - AppCode:确保 中设置了
.rabetbase.json(单应用)或appcode(多应用),或通过apps/--appcode <code>传入(旧名--app <name>仍可读).lovrabet.json - 配置文件:初始化
rabetbase project init(旧名仍兼容读取).rabetbase.json - 多应用场景:一个项目有多个应用时,先 配置各应用,再用
rabetbase app add或--app <name>切换rabetbase app use <name>
- Authentication: Complete OAuth login via browser with
rabetbase auth - AppCode: Ensure (single app) or
appcode(multiple apps) is set inapps, or pass it via.rabetbase.json/--appcode <code>(the old name--app <name>is still readable).lovrabet.json - Configuration file: Initialize with
.rabetbase.json(old name is still compatible for reading)rabetbase project init - Multi-app scenario: When a project has multiple apps, first configure each app with , then switch with
rabetbase app addor--app <name>rabetbase app use <name>
Agent 快速执行顺序
Agent Quick Execution Sequence
- 判断需求类型
- 标准数据 CRUD → SDK filter/getOne/create/update/delete
- 简单聚合 → SDK aggregate
- 复杂 JOIN / 数据库函数 → 自定义 SQL
- 外部系统调用 / 跨表事务 / 复杂业务编排 → BFF
- 先拿元数据,再写代码
- 至少先查 获取表结构
rabetbase dataset detail --code xxx --format json - 跨表场景还需查目标表的结构
- 需要了解数据模型关系时用
rabetbase dataset links --format json
- 至少先查
- SQL 工作流严格分步
- 查现有 → 确认字段 → 编写 → 校验() → 保存(
sql validate) → 测试(sql save)sql exec
- 查现有 → 确认字段 → 编写 → 校验(
- BFF 工作流严格分步
- 查现有 → 确认字段 → 查公共函数 → 编写 → 预览() → 保存(
--dry-run)bff save --yes
- 查现有 → 确认字段 → 查公共函数 → 编写 → 预览(
- Determine requirement type
- Standard data CRUD → SDK filter/getOne/create/update/delete
- Simple aggregation → SDK aggregate
- Complex JOIN / database functions → Custom SQL
- External system call / cross-table transaction / complex business orchestration → BFF
- Get metadata first, then write code
- At least query first to get table structure
rabetbase dataset detail --code xxx --format json - For cross-table scenarios, you also need to query the structure of the target table
- Use when you need to understand data model relationships
rabetbase dataset links --format json
- At least query
- SQL workflow strictly in steps
- Check existing → Confirm fields → Write → Validate() → Save(
sql validate) → Test(sql save)sql exec
- Check existing → Confirm fields → Write → Validate(
- BFF workflow strictly in steps
- Check existing → Confirm fields → Check public functions → Write → Preview() → Save(
--dry-run)bff save --yes
- Check existing → Confirm fields → Check public functions → Write → Preview(
Agent 禁止行为
Agent Prohibited Behaviors
- 不要猜字段名 — 必须从 返回值获取真实字段名、类型、枚举值
dataset detail - 不要跳过 validate — SQL 保存前必须通过 或
sql validate校验sql save --dry-run - 不要手动拼 API URL — 所有操作通过 CLI 命令完成,不要直接调 HTTP 接口
- 不要臆测 sqlCode / id — 从 或
sql list获取真实标识bff list - 不要含糊处理保存失败 — /
sql save返回bff save时必须明确告知用户blocked - 不要在不确认表结构时就写 SQL — 先 ,后写 SQL
dataset detail - 不要循环单条查询 — 用 SDK 批量查询,不要 N+1
filter + $in - 不要把 MCP 工具名当 CLI 命令 — 使用 ,不是
rabetbase sql listlist_sql_queries
- Don't guess field names — Must get real field names, types, enumeration values from the return value of
dataset detail - Don't skip validate — SQL must be validated via or
sql validatebefore savingsql save --dry-run - Don't manually splice API URLs — All operations are done via CLI commands, don't call HTTP interfaces directly
- Don't guess sqlCode / id — Get real identifiers from or
sql listbff list - Don't handle save failures vaguely — Must explicitly inform the user when /
sql savereturnsbff saveblocked - Don't write SQL without confirming the table structure — Run first, then write SQL
dataset detail - Don't loop single queries — Use SDK for batch queries, avoid N+1
filter + $in - Don't use MCP tool names as CLI commands — Use , not
rabetbase sql listlist_sql_queries
接口选型优先级
Interface Selection Priority
遇到新需求时按优先级选择实现方式:
- 标准 SDK 接口(filter/getOne/create 等)— 能用就不写 SQL
- Aggregate 聚合接口 — 简单分组汇总
- 自定义 SQL — 复杂 JOIN、数据库函数、跨表统计
- BFF — 外部系统调用、跨表事务、复杂业务编排
When encountering new requirements, select the implementation method according to priority:
- Standard SDK interface (filter/getOne/create, etc.) — Use it if available instead of writing SQL
- Aggregate interface — For simple grouping and aggregation
- Custom SQL — For complex JOIN, database functions, cross-table statistics
- BFF — For external system calls, cross-table transactions, complex business orchestration
SDK 核心规则
SDK Core Rules
初始化
Initialization
typescript
import { createClient } from "@lovrabet/sdk";
const client = createClient({
appCode: "your-app-code",
accessKey: process.env.RABETBASE_ACCESS_KEY,
models: [{ tableName: "users", datasetCode: "abc123", alias: "users" }],
});typescript
import { createClient } from "@lovrabet/sdk";
const client = createClient({
appCode: "your-app-code",
accessKey: process.env.RABETBASE_ACCESS_KEY,
models: [{ tableName: "users", datasetCode: "abc123", alias: "users" }],
});Filter 查询(最常用)
Filter Query (most commonly used)
typescript
const result = await client.models.users.filter({
where: { status: { $eq: "active" } },
select: ["id", "name"],
orderBy: [{ createTime: "desc" }],
currentPage: 1,
pageSize: 20,
});参数名强制约束:(非 fields)、(非 sort)、/(非 page/limit)
selectorderBycurrentPagepageSizewhere 条件强制使用操作符:
$eq$ne$gte$lte$gt$lt$in$contain$startWith$endWithtypescript
const result = await client.models.users.filter({
where: { status: { $eq: "active" } },
select: ["id", "name"],
orderBy: [{ createTime: "desc" }],
currentPage: 1,
pageSize: 20,
});Parameter name mandatory constraints: (not fields), (not sort), / (not page/limit)
selectorderBycurrentPagepageSizeWhere conditions mandatory use operators:
$eq$ne$gte$lte$gt$lt$in$contain$startWith$endWithSQL 调用
SQL Call
typescript
const data = await client.sql.execute<MyRow>({ sqlCode: "xxx", params: { key: "val" } });
if (data.execSuccess && data.execResult) {
console.log(data.execResult);
}typescript
const data = await client.sql.execute<MyRow>({ sqlCode: "xxx", params: { key: "val" } });
if (data.execSuccess && data.execResult) {
console.log(data.execResult);
}BFF 调用
BFF Call
typescript
const result = await client.bff.execute<DashboardData>({
scriptName: "getUserDashboard",
params: { userId: "123" },
});typescript
const result = await client.bff.execute<DashboardData>({
scriptName: "getUserDashboard",
params: { userId: "123" },
});前端 vs BFF 关键差异
Key Differences between Frontend and BFF
| 前端 SDK | BFF (context.client) | |
|---|---|---|
| SQL 返回值 | | 直接返回数组 |
| 单条查询 | | |
| 调 BFF | | — |
| Frontend SDK | BFF (context.client) | |
|---|---|---|
| SQL return value | | Directly return array |
| Single query | | |
| Call BFF | | — |
意图 → 命令索引
Intent → Command Index
| 意图 | 推荐命令 | 备注 |
|---|---|---|
| 查找数据集 | | 服务端模糊匹配;也可 |
| 查看表结构和字段 | | 含字段定义和操作列表 |
| 查看 Dataset 操作定义 | | 获取 filter/getOne/create 等参数定义 |
| 查看数据模型关系 | | 跨表 JOIN 关系图 |
| 查看现有 SQL | | 分页,按名称过滤 |
| 查看 SQL 详情 | | 含完整 SQL 内容和参数定义 |
| 校验 SQL 内容 | | 类型检测、危险语句检查、参数提取 |
| 保存/更新 SQL | | 内置校验,不可跳过 |
| 执行 SQL 查询 | | 支持 |
| 查看现有 BFF | | 按类型和名称过滤 |
| 查看 BFF 详情 | | 含完整脚本内容 |
| 保存/更新 BFF | | high-risk-write,需 |
| 生成 SDK 代码 | | 按操作生成 TypeScript |
| 生成 SQL 调用代码 | | sdk/bff 两种 target |
| 列出已配置应用 | | 多应用模式 |
| 切换默认应用 | | 持久修改 defaultApp |
| 添加应用 | | 首个自动设为 default |
| 移除应用 | | 移除后自动切换 default |
| 临时切换应用执行 | 任何命令加 | 不修改配置文件 |
| Intent | Recommended Command | Remarks |
|---|---|---|
| Find datasets | | Server-side fuzzy matching; you can also use |
| View table structure and fields | | Includes field definitions and operation list |
| View Dataset operation definitions | | Get parameter definitions for filter/getOne/create, etc. |
| View data model relationships | | Cross-table JOIN relationship diagram |
| View existing SQL | | Pagination, filter by name |
| View SQL details | | Includes complete SQL content and parameter definitions |
| Validate SQL content | | Type detection, dangerous statement check, parameter extraction |
| Save/update SQL | | Built-in validation, cannot be skipped |
| Execute SQL query | | Supports |
| View existing BFF | | Filter by type and name |
| View BFF details | | Includes complete script content |
| Save/update BFF | | high-risk-write, requires |
| Generate SDK code | | Generate TypeScript by operation |
| Generate SQL call code | | Two targets: sdk/bff |
| List configured apps | | Multi-app mode |
| Switch default app | | Persistently modify defaultApp |
| Add app | | The first one is automatically set as default |
| Remove app | | Automatically switch default after removal |
| Temporarily switch app for execution | Add | Does not modify configuration file |
命令分组
Command Groups
执行前必做: 从下表定位到命令后,务必先阅读对应命令的 reference 文档,再调用命令。
| 命令分组 | 说明 |
|---|---|
| app commands | |
| dataset commands | |
| sql commands | |
| bff commands | |
| codegen commands | |
Mandatory before execution: After locating the command from the table below, be sure to read the reference documentation for the corresponding command first before invoking it.
| Command Group | Description |
|---|---|
| app commands | |
| dataset commands | |
| sql commands | |
| bff commands | |
| codegen commands | |
风险控制
Risk Control
所有声明式命令有 risk level:
| 级别 | 含义 | 使用方式 |
|---|---|---|
| 只读查询,随时可执行 | 直接执行 |
| 修改数据,如 | 先 |
| 影响运行时行为,如 | 必须 |
sql savesql validate配置 可限制允许执行的最高风险等级( 或 ;旧名 仍可读)。
riskLevel.rabetbase.jsonRABETBASE_RISK_LEVEL.lovrabet.jsonAll declarative commands have a risk level:
| Level | Meaning | Usage |
|---|---|---|
| Read-only query, can be executed at any time | Execute directly |
| Modify data, e.g. | Preview with |
| Affect runtime behavior, e.g. | Must confirm with |
sql savesql validateConfiguring can limit the highest risk level allowed for execution ( or ; old name is still readable).
riskLevel.rabetbase.jsonRABETBASE_RISK_LEVEL.lovrabet.json输出格式
Output Format
| 格式 | 用途 | 示例 |
|---|---|---|
| AI Agent / 程序解析 | |
| 人类阅读(默认) | 彩色文本输出 |
| 列表数据展示 | 表格输出 |
| Format | Purpose | Example |
|---|---|---|
| AI Agent / program parsing | |
| Human reading (default) | Colored text output |
| List data display | Table output |
常见错误速查
Common Error Quick Check
| 错误类型 | 含义 | 解决方案 |
|---|---|---|
| 未登录 | 执行 |
| 未配置 appcode | |
| 缺少必填参数 | 检查 reference 文档确认必填 flags |
| 输入校验失败(含 SQL 类型阻止) | 检查 SQL 内容或参数格式 |
| 后端 API 错误 | 检查 appcode、网络、权限 |
| 用户取消高风险操作 | 用 |
| 平台冲突检测 | 告知用户手动在平台操作,写本地草稿 |
| Error Type | Meaning | Solution |
|---|---|---|
| Not logged in | Execute |
| appcode not configured | Run |
| Missing required parameters | Check reference documentation to confirm required flags |
| Input validation failed (including SQL type blocking) | Check SQL content or parameter format |
| Backend API error | Check appcode, network, permissions |
| User cancelled high-risk operation | Use |
| Platform conflict detection | Inform user to operate manually on the platform, write local draft |
冲突处理
Conflict Handling
sql savebff saveblocked: true- 告知用户手动在平台操作
- 将内容写入本地草稿文件(/
.draft.sql).draft.js - 禁止重试、禁止绕过
- 未保存成功时必须明确告知用户,禁止含糊带过
When / returns :
sql savebff saveblocked: true- Inform the user to operate manually on the platform
- Write the content to a local draft file (/
.draft.sql).draft.js - Prohibit retrying, prohibit bypassing
- Must explicitly inform the user when saving is not successful, prohibit vague handling
前端页面规则
Frontend Page Rules
- CLI 生成的页面顶部注释必须保留,追加说明用
@modified - 页面组件设置
displayName - 写页面前必须 确认字段和关系
dataset detail - 禁止 emoji、AI 味文案、感叹号、花哨颜色;文案简洁专业
- 图标用 ,颜色用 AntD token
@ant-design/icons
- The top comment of the page generated by CLI must be retained, use for additional notes
@modified - Set for page components
displayName - Must run to confirm fields and relationships before writing pages
dataset detail - Prohibit emojis, AI-style copy, exclamation marks, fancy colors; copy should be concise and professional
- Use for icons, use AntD token for colors
@ant-design/icons
深入指南
In-depth Guides
以下 guide 文件提供各主题的详细说明、完整示例和边界情况:
| 主题 | Guide |
|---|---|
| SDK 完整参数与返回值 | |
| SQL MyBatis 语法与动态 SQL | |
| 前端页面开发约束 | |
| 故障诊断手册 | |
| BFF 脚本编写规范 | |
| 数据接口访问规范 | |
| SQL 创建工作流细则 | |
| BFF 创建工作流细则 | |
| 冲突检测与处理 | |
| 开发质量与最佳实践 | |
The following guide files provide detailed descriptions, complete examples and boundary cases for each topic:
| Topic | Guide |
|---|---|
| SDK full parameters and return values | |
| SQL MyBatis syntax and dynamic SQL | |
| Frontend page development constraints | |
| Troubleshooting manual | |
| BFF script writing specifications | |
| Data interface access specifications | |
| SQL creation workflow details | |
| BFF creation workflow details | |
| Conflict detection and handling | |
| Development quality and best practices | |