更新数据 API 生成器配置文件中的现有实体定义。 使用此命令在添加实体后调整源元数据、权限、公开(REST/GraphQL)、策略、缓存、关系、映射和描述性元数据。
小窍门
用于 dab add 创建新实体并 dab update 对其进行改进。 字段名称重新映射 () 仅在
Syntax
dab update <entity-name> [options]
快速浏览
| 选项 | 概要 |
|---|---|
<entity-name> |
必需的位置参数。 逻辑实体名称。 |
-c, --config |
配置文件的路径。 如果省略,则默认解析适用。 |
--description |
替换实体说明。 |
缓存
| 选项 | 概要 |
|---|---|
--cache.enabled |
启用或禁用实体缓存。 |
--cache.ttl |
缓存生存时间(以秒为单位)。 |
Fields
| 选项 | 概要 |
|---|---|
--fields.exclude |
已排除字段的逗号分隔列表。 |
--fields.include |
包含字段的逗号分隔列表(* = 全部)。 |
-m, --map |
字段映射对 name:alias。 替换整个集。 |
GraphQL
| 选项 | 概要 |
|---|---|
--graphql |
GraphQL 曝光: false、 true、 singular或 singular:plural。 |
--graphql.operation |
仅存储过程: query 或 mutation (默认突变)。 |
权限和策略
| 选项 | 概要 |
|---|---|
--permissions |
一对或多 role:actions 对。 替换现有列表。 |
--policy-database |
在 DB 查询中注入的 OData 样式筛选器。 |
--policy-request |
数据库前请求筛选器。 |
Relationships
| 选项 | 概要 |
|---|---|
--relationship |
关系名称。 与关系选项一起使用。 |
--relationship.fields |
直接关系的字段映射。 |
REST
| 选项 | 概要 |
|---|---|
--rest |
REST 曝光: false、 true或自定义路径。 |
--rest.methods |
仅存储过程。 替换允许的 HTTP 谓词。 |
来源
| 选项 | 概要 |
|---|---|
-s, --source |
基础数据库对象名称。 |
--source.key-fields |
视图或非 PK 表是必需的。 |
--source.params |
仅存储过程。 替换默认参数。 |
--source.type |
源类型: table、 view或 stored-procedure。 |
--cache.enabled
启用或禁用此实体的缓存。
Example
dab update Book --cache.enabled true
生成的配置
{
"entities": {
"Book": {
"cache": {
"enabled": true
}
}
}
}
--cache.ttl
设置缓存生存时间(以秒为单位)。 仅当启用缓存时才有效。
Example
dab update Book --cache.ttl 600
生成的配置
{
"entities": {
"Book": {
"cache": {
"ttl-seconds": 600
}
}
}
}
注释
禁用缓存时提供 TTL 在启用缓存之前不起作用。
--description
替换实体说明。
Example
dab update Book --description "Updated description"
生成的配置
{
"entities": {
"Book": {
"description": "Updated description"
}
}
}
--fields.exclude
要排除的字段的逗号分隔列表。
Example
dab update Book --fields.exclude "internal_flag,secret_note"
生成的配置
{
"entities": {
"Book": {
"graphql": {
"fields": {
"exclude": [ "internal_flag", "secret_note" ]
}
}
}
}
}
--fields.include
要包含的字段的逗号分隔列表。
* 包括所有字段。 替换现有包含列表。
Example
dab update Book --fields.include "id,title,author"
生成的配置
{
"entities": {
"Book": {
"graphql": {
"fields": {
"include": [ "id", "title", "author" ]
}
}
}
}
}
--graphql
控制 GraphQL 公开。
Example
dab update Book --graphql book:books
生成的配置
{
"entities": {
"Book": {
"graphql": {
"singular": "book",
"plural": "books"
}
}
}
}
--graphql.operation
仅存储过程。 设置作类型。 默认值为 mutation。
Example
dab update RunReport --graphql.operation query
生成的配置
{
"entities": {
"RunReport": {
"graphql": {
"operation": "query"
}
}
}
}
注释
--graphql.operation忽略为表或视图提供。
-m, --map
将数据库字段映射到公开的名称。 替换整个映射集。
Example
dab update Book --map "id:bookId,title:bookTitle"
生成的配置
{
"entities": {
"Book": {
"mappings": {
"id": "bookId",
"title": "bookTitle"
}
}
}
}
重要
覆盖任何现有映射。 重述要保留的所有映射。
--permissions
将所有权限替换为新的角色/作集。 对多个角色重复标记。
Example
dab update Book --permissions "anonymous:read" --permissions "authenticated:create,read,update"
生成的配置
{
"entities": {
"Book": {
"permissions": [
{
"role": "anonymous",
"actions": [ "read" ]
},
{
"role": "authenticated",
"actions": [ "create", "read", "update" ]
}
]
}
}
}
重要
权限将替换现有列表。 放弃以前的权限。
--policy-database
追加到 DB 查询的 OData 样式筛选器。
Example
dab update Book --policy-database "region eq 'US'"
生成的配置
{
"entities": {
"Book": {
"policies": {
"database": "region eq 'US'"
}
}
}
}
--policy-request
在达到数据库之前评估的请求级别策略。
Example
dab update Book --policy-request "@claims.role == 'admin'"
生成的配置
{
"entities": {
"Book": {
"policies": {
"request": "@claims.role == 'admin'"
}
}
}
}
--relationship
定义或更新关系。 与其他关系选项一起使用。
Example
dab update Book --relationship publisher --cardinality one --target.entity Publisher --relationship.fields "publisher_id:id"
生成的配置
{
"entities": {
"Book": {
"relationships": {
"publisher": {
"cardinality": "one",
"target.entity": "Publisher",
"fields": {
"publisher_id": "id"
}
}
}
}
}
}
--relationship.fields
直接关系的冒号分隔字段映射。
Example
dab update Book --relationship author --cardinality one --target.entity Author --relationship.fields "author_id:id"
生成的配置
{
"entities": {
"Book": {
"relationships": {
"author": {
"cardinality": "one",
"target.entity": "Author",
"fields": {
"author_id": "id"
}
}
}
}
}
}
--rest
控制 REST 曝光。
Example
dab update Book --rest BooksApi
生成的配置
{
"entities": {
"Book": {
"rest": {
"path": "BooksApi"
}
}
}
}
--rest.methods
仅存储过程。 替换允许的 HTTP 方法。 默认为 POST。
Example
dab update RunReport --rest true --rest.methods GET,POST
生成的配置
{
"entities": {
"RunReport": {
"rest": {
"path": "RunReport",
"methods": [ "GET", "POST" ]
}
}
}
}
注释
--rest.methods禁用 REST 时提供不起作用。
-s, --source
更新基础数据库对象。
Example
dab update Book --source dbo.Books
生成的配置
{
"entities": {
"Book": {
"source": {
"type": "table",
"object": "dbo.Books"
}
}
}
}
--source.key-fields
对于没有推断的 PK 的视图或表。 替换现有密钥。 对存储过程无效。
Example
dab update SalesSummary --source.type view --source.key-fields "year,region"
生成的配置
{
"entities": {
"SalesSummary": {
"source": {
"type": "view",
"object": "SalesSummary",
"keyFields": [ "year", "region" ]
}
}
}
}
注释
不允许与存储过程一 --source.key-fields 起使用。
--source.params
仅存储过程。 替换参数默认值。
Example
dab update RunReport --source.type stored-procedure --source.params "year:2024,region:west"
生成的配置
{
"entities": {
"RunReport": {
"source": {
"type": "stored-procedure",
"object": "RunReport",
"params": {
"year": 2024,
"region": "west"
}
}
}
}
}
注释
不允许与表或视图一起使用 --source.params 。
--source.type
更改源对象类型。
Example
dab update Book --source.type view
生成的配置
{
"entities": {
"Book": {
"source": {
"type": "view",
"object": "Book"
}
}
}
}
重要
更改源类型可能会使其他属性失效。 例如,视图始终需要键字段;存储过程无法定义键字段。