dab add
将数据库对象(表、视图、存储过程)添加到配置文件的 entities 节中,使其通过 API 对外暴露。
语法
bash
dab add <entity-name> [options]实体名区分大小写,直接决定 REST 路径(/api/<entity-name>)和 GraphQL 类型名。
选项
源(Source)选项
| 选项 | 说明 | 默认值 |
|---|---|---|
--source | 数据库对象名称,格式 schema.name | — |
--source.type | 对象类型:table、view、stored-procedure | table |
--source.object-description | 数据库对象的人类可读描述 | — |
权限选项
| 选项 | 说明 |
|---|---|
--permissions | 实体权限,格式 "role:actions",多个角色用逗号分隔。例如 "anonymous:read,authenticated:*" |
字段选项
| 选项 | 说明 |
|---|---|
--fields.name | 数据库字段名 |
--fields.alias | API 层字段别名 |
--fields.description | 字段描述 |
--fields.primary-key | 标记为视图主键(true / false) |
--fields.include | 允许暴露的字段列表 |
--fields.exclude | 排除的字段列表 |
REST 选项
| 选项 | 说明 | 默认值 |
|---|---|---|
--rest.enabled | 是否生成 REST 端点 | true |
--rest.path | 自定义 REST 路径 | 实体名 |
--rest.methods | 允许的 HTTP 方法(仅存储过程):GET、POST | ["POST"] |
GraphQL 选项
| 选项 | 说明 | 默认值 |
|---|---|---|
--graphql.enabled | 是否出现在 GraphQL 架构中 | true |
--graphql.type.singular | GraphQL 单数类型名 | — |
--graphql.type.plural | GraphQL 复数类型名 | — |
--graphql.operation | 存储过程挂载位置:query / mutation | mutation |
缓存选项
| 选项 | 说明 | 默认值 |
|---|---|---|
--cache.enabled | 是否启用缓存 | false |
--cache.ttl-seconds | 缓存 TTL(秒) | — |
--cache.level | 缓存级别:L1 / L1L2 | L1L2 |
MCP 选项
| 选项 | 说明 | 默认值 |
|---|---|---|
--mcp.dml-tools | 是否暴露 MCP DML 工具 | true |
--mcp.custom-tool | 是否注册为 MCP 自定义工具(仅存储过程) | false |
存储过程参数选项
| 选项 | 说明 |
|---|---|
--parameters.name | 参数名列表(逗号分隔) |
--parameters.required | 是否必需(true,false,...) |
--parameters.default | 默认值列表(逗号分隔) |
--parameters.description | 参数描述列表(逗号分隔) |
其他
| 选项 | 说明 |
|---|---|
--description | 实体的人类可读描述 |
--health.enabled | 是否启用实体健康检查 |
-c, --config | 配置文件路径 |
示例
添加表实体
bash
dab add Book \
--source "dbo.Books" \
--source.type "table" \
--permissions "anonymous:read,authenticated:*" \
--description "图书信息表"添加视图实体
bash
dab add BookDetail \
--source "dbo.vw_Books_Details" \
--source.type "view" \
--fields.name "id" \
--fields.primary-key "true" \
--permissions "anonymous:read"添加存储过程实体
bash
dab add GetBookById \
--source "dbo.get_book_by_id" \
--source.type "stored-procedure" \
--permissions "anonymous:execute" \
--rest.methods "GET" \
--graphql.operation "query" \
--mcp.custom-tool true添加带字段描述的实体
bash
dab add Product \
--source "dbo.Products" \
--permissions "anonymous:read" \
--description "产品目录" \
--fields.name "ProductID" \
--fields.description "产品唯一标识符" \
--fields.primary-key "true"权限格式
"角色:操作1,操作2"
操作值:read、create、update、delete、execute、*
示例:
"anonymous:read"
"authenticated:read,create,update"
"admin:*"多个角色用逗号分隔:"anonymous:read,authenticated:*"。
下一步
- dab update — 修改已有实体配置。
- dab configure — 配置运行时设置。
