將新的實體定義新增至現有的資料 API 產生器組態檔。 您必須已經使用 建立的組態 dab init。 用於 dab update 在建立後修改圖元。
小提示
用於 dab add 建立新實體,並 dab update 進化它們。
語法
dab add <entity-name> [options]
快速瀏覽
| Option | 總結 |
|---|---|
<entity-name> |
必要的位置引數。 邏輯實體名稱。 |
-c, --config |
組態檔路徑。 預設 dab-config.json。 |
--cache.enabled |
啟用/停用實體的快取。 |
--cache.ttl |
快取存留時間 (以秒為單位)。 |
--description |
實體的自由格式描述。 |
--fields.exclude |
以逗號分隔的排除欄位。 |
--fields.include |
以逗號分隔的允許欄位 (* = all)。 |
--fields.name |
欄位名稱可描述(可重複或逗號分隔)。 |
--fields.alias |
欄位別名(逗號分隔,對齊至 --fields.name)。 |
--fields.description |
場描述(逗號分隔,對齊於 --fields.name)。 |
--fields.primary-key |
主鍵旗標(逗號分隔,對齊於 --fields.name)。 |
--graphql |
GraphQL 曝光: false、 true、 singular或 singular:plural。 |
--graphql.operation |
僅限預存程序。
Query 或 Mutation (預設突變)。 |
--permissions |
必須的。
role:actions 只是一個角色。 |
--policy-database |
資料庫查詢中套用的 OData 樣式篩選。 |
--policy-request |
在資料庫呼叫之前評估的要求原則。 |
--parameters.name |
僅限預存程序。 參數名稱(逗號分隔)。 |
--parameters.description |
僅限預存程序。 參數描述。 |
--parameters.required |
僅限預存程序。 參數需要標記。 |
--parameters.default |
僅限預存程序。 參數預設值。 |
--rest |
REST 暴露: false、 true或自訂路由。 |
--rest.methods |
僅限預存程序。 允許的動詞:GET, POST, , PUTPATCHDELETE, , 。 預設 POST。 |
-s, --source |
必須的。 資料庫物件名稱 (資料表、檢視或預存程序)。 |
--source.key-fields |
作為主鍵的欄位。 |
--source.params |
僅限預存程序。 預設參數值。 |
--source.type |
來源類型: table、 view、 stored-procedure (預設資料表)。 |
--help |
顯示此說明畫面。 |
--version |
顯示版本資訊。 |
<entity-name>
配置中實體的邏輯名稱。區分大小寫。
表格、檢視與儲存程序的快速範例
新增數據表
dab add Book \
--source dbo.Books \
--source.type table \
--permissions "anonymous:read" \
--description "Example for managing book inventory"
新增檢視
dab add BookView \
--source dbo.MyView \
--source.type view \
--source.key-fields "id,region" \
--permissions "anonymous:read" \
--description "Example for managing book inventory from view"
新增儲存程序
dab add BookProc \
--source dbo.MyProc \
--source.type stored-procedure \
--source.params "year:2024,active:true" \
--permissions "anonymous:execute" \
--graphql.operation query \
--description "Example for executing a stored procedure"
-c, --config
組態檔路徑。 預設值為 dab-config.json。
Example
dab add Book \
--config ./dab-config.mssql.json \
--source dbo.Books \
--permissions "anonymous:read"
--cache.enabled
啟用或停用快取。
Example
dab add Book \
--source dbo.Books \
--permissions "anonymous:read" \
--cache.enabled true
產生的設定
{
"entities": {
"Book": {
"source": {
"type": "table",
"object": "dbo.Books"
},
"permissions": [
{ "role": "anonymous", "actions": [ { "action": "read" } ] }
],
"cache": {
"enabled": true
}
}
}
}
--cache.ttl
快取存留時間 (以秒為單位)。
Example
產生的設定
{
"entities": {
"Book": {
"source": {
"type": "table",
"object": "dbo.Books"
},
"permissions": [
{ "role": "anonymous", "actions": [ { "action": "read" } ] }
],
"cache": {
"enabled": false,
"ttl-seconds": 300
}
}
}
}
--description
實體的自由文字描述。
備註
此選項僅在 v1.7 預發布 CLI(目前為 RC)中提供。 安裝時用 dotnet tool install microsoft.dataapibuilder --prerelease.
Example
dab add Book \
--source dbo.Books \
--permissions "anonymous:read" \
--description "Entity for managing book inventory"
產生的設定
{
"entities": {
"Book": {
"source": {
"type": "table",
"object": "dbo.Books"
},
"permissions": [
{ "role": "anonymous", "actions": [ { "action": "read" } ] }
],
"description": "Entity for managing book inventory"
}
}
}
--fields.exclude
要排除的欄位以逗號分隔的清單。
Example
dab add Book \
--source dbo.Books \
--permissions "anonymous:read" \
--fields.exclude "internal_flag,secret_note"
產生的設定
{
"entities": {
"Book": {
"source": { "type": "table", "object": "dbo.Books" },
"permissions": [
{
"role": "anonymous",
"actions": [
{
"action": "read",
"fields": {
"exclude": [ "internal_flag", "secret_note" ]
}
}
]
}
]
}
}
}
--fields.include
要公開的欄位以逗號分隔的清單。
Example
dab add Book \
--source dbo.Books \
--permissions "anonymous:read" \
--fields.include "id,title,price"
產生的設定
{
"entities": {
"Book": {
"source": { "type": "table", "object": "dbo.Books" },
"permissions": [
{
"role": "anonymous",
"actions": [
{
"action": "read",
"fields": {
"include": [ "id", "title", "price" ]
}
}
]
}
]
}
}
}
--graphql
控制 GraphQL 曝光。
Example
dab add Book \
--source dbo.Books \
--permissions "anonymous:read" \
--graphql book:books
產生的設定
{
"entities": {
"Book": {
"source": { "type": "table", "object": "dbo.Books" },
"permissions": [
{ "role": "anonymous", "actions": [ { "action": "read" } ] }
],
"graphql": {
"enabled": true,
"type": {
"singular": "book",
"plural": "books"
}
}
}
}
}
--graphql.operation
僅限預存程序。 GraphQL 作業類型。 預設值為 mutation。
Example
dab add BookProc \
--source dbo.MyProc \
--source.type stored-procedure \
--permissions "admin:execute" \
--graphql.operation Query
產生的設定
{
"entities": {
"BookProc": {
"source": { "type": "stored-procedure", "object": "dbo.MyProc" },
"permissions": [
{ "role": "admin", "actions": [ { "action": "execute" } ] }
],
"graphql": {
"enabled": true,
"operation": "query"
}
}
}
}
--permissions
定義角色→動作配對。
--permissions 無法重複。 要增加更多角色,先先跑 dab add 一個角色,再跑 dab update 去爭取額外角色。
Example
dab add Book \
--source dbo.Books \
--permissions "anonymous:read"
dab update Book \
--permissions "authenticated:create,read,update,delete"
--parameters.name
僅限預存程序。 參數名稱的逗號分隔列表。
備註
此選項僅在 v1.7 預發布 CLI(目前為 RC)中提供。 安裝時用 dotnet tool install microsoft.dataapibuilder --prerelease.
Example
dab add GetOrdersByDateRange \
--source dbo.usp_GetOrdersByDateRange \
--source.type stored-procedure \
--permissions "authenticated:execute" \
--description "Retrieves all orders placed within a specified date range" \
--parameters.name "StartDate,EndDate,CustomerID" \
--parameters.description "Beginning of date range (inclusive),End of date range (inclusive),Optional customer ID filter" \
--parameters.required "true,true,false" \
--parameters.default ",,null"
產生的設定
{
"entities": {
"GetOrdersByDateRange": {
"description": "Retrieves all orders placed within a specified date range",
"source": {
"object": "dbo.usp_GetOrdersByDateRange",
"type": "stored-procedure",
"parameters": [
{
"name": "StartDate",
"required": true,
"description": "Beginning of date range (inclusive)"
},
{
"name": "EndDate",
"required": true,
"description": "End of date range (inclusive)"
},
{
"name": "CustomerID",
"required": false,
"default": "null",
"description": "Optional customer ID filter"
}
]
},
"permissions": [
{
"role": "authenticated",
"actions": [
{
"action": "execute"
}
]
}
]
}
}
}
--parameters.description
僅限預存程序。 參數描述的逗號分隔列表對齊於 --parameters.name。
備註
此選項僅在 v1.7 預發布 CLI(目前為 RC)中提供。 安裝時用 dotnet tool install microsoft.dataapibuilder --prerelease.
Example
dab add GetOrdersByDateRange \
--source dbo.usp_GetOrdersByDateRange \
--source.type stored-procedure \
--permissions "authenticated:execute" \
--parameters.name "StartDate,EndDate" \
--parameters.description "Beginning of date range (inclusive),End of date range (inclusive)"
--parameters.required
僅限預存程序。 以逗號分隔的數值列表 true/false ,對齊於 --parameters.name。
備註
此選項僅在 v1.7 預發布 CLI(目前為 RC)中提供。 安裝時用 dotnet tool install microsoft.dataapibuilder --prerelease.
Example
dab add GetOrdersByDateRange \
--source dbo.usp_GetOrdersByDateRange \
--source.type stored-procedure \
--permissions "authenticated:execute" \
--parameters.name "StartDate,EndDate" \
--parameters.required "true,true"
--parameters.default
僅限預存程序。 以逗號分隔的預設值列表,對齊於 --parameters.name。
備註
此選項僅在 v1.7 預發布 CLI(目前為 RC)中提供。 安裝時用 dotnet tool install microsoft.dataapibuilder --prerelease.
Example
dab add GetOrdersByDateRange \
--source dbo.usp_GetOrdersByDateRange \
--source.type stored-procedure \
--permissions "authenticated:execute" \
--parameters.name "CustomerID" \
--parameters.default "null"
--fields.name
要描述的資料庫欄位名稱。
備註
此選項僅在 v1.7 預發布 CLI(目前為 RC)中提供。 安裝時用 dotnet tool install microsoft.dataapibuilder --prerelease.
Example
dab add Products \
--source dbo.Products \
--permissions "anonymous:*" \
--fields.name "ProductID,ProductName" \
--fields.alias "product_id,product_name" \
--fields.description "Unique identifier for each product,Display name of the product" \
--fields.primary-key "true,false"
產生的設定
{
"entities": {
"Products": {
"source": { "type": "table", "object": "dbo.Products" },
"permissions": [
{ "role": "anonymous", "actions": [ { "action": "*" } ] }
],
"fields": [
{
"name": "ProductID",
"alias": "product_id",
"description": "Unique identifier for each product",
"primary-key": true
},
{
"name": "ProductName",
"alias": "product_name",
"description": "Display name of the product",
"primary-key": false
}
]
}
}
}
--fields.alias
田野的別名。 使用一個逗號分隔的清單,對齊於 --fields.name。
備註
此選項僅在 v1.7 預發布 CLI(目前為 RC)中提供。 安裝時用 dotnet tool install microsoft.dataapibuilder --prerelease.
Example
dab add Products \
--source dbo.Products \
--permissions "anonymous:*" \
--fields.name "ProductID" \
--fields.alias "product_id"
--fields.description
該領域的描述。 使用一個逗號分隔的清單,對齊於 --fields.name。
備註
此選項僅在 v1.7 預發布 CLI(目前為 RC)中提供。 安裝時用 dotnet tool install microsoft.dataapibuilder --prerelease.
Example
dab add Products \
--source dbo.Products \
--permissions "anonymous:*" \
--fields.name "ProductID" \
--fields.description "Unique identifier"
--fields.primary-key
田野的主鍵旗幟。 使用一個逗號分隔的值清單true/false,對齊於 。--fields.name
備註
此選項僅在 v1.7 預發布 CLI(目前為 RC)中提供。 安裝時用 dotnet tool install microsoft.dataapibuilder --prerelease.
Example
dab add Products \
--source dbo.Products \
--permissions "anonymous:*" \
--fields.name "ProductID" \
--fields.primary-key "true"
產生的設定
{
"entities": {
"Products": {
"source": { "type": "table", "object": "dbo.Products" },
"permissions": [
{ "role": "anonymous", "actions": [ { "action": "*" } ] }
],
"fields": [
{
"name": "ProductID",
"primary-key": true
}
]
}
}
}
--policy-database
資料庫層級原則。
Example
dab add Book \
--source dbo.Books \
--permissions "anonymous:read" \
--policy-database "region eq 'US'"
產生的設定
{
"entities": {
"Book": {
"source": { "type": "table", "object": "dbo.Books" },
"permissions": [
{
"role": "anonymous",
"actions": [
{
"action": "read",
"policy": {
"database": "region eq 'US'"
}
}
]
}
]
}
}
}
--policy-request
要求層級原則。
Example
dab add Book \
--source dbo.Books \
--permissions "anonymous:read" \
--policy-request "@claims.role == 'admin'"
產生的設定
{
"entities": {
"Book": {
"source": { "type": "table", "object": "dbo.Books" },
"permissions": [
{
"role": "anonymous",
"actions": [
{
"action": "read",
"policy": {
"request": "@claims.role == 'admin'"
}
}
]
}
]
}
}
}
--rest
控制 REST 暴露。
Example
產生的設定
{
"entities": {
"Book": {
"source": { "type": "table", "object": "dbo.Books" },
"permissions": [
{ "role": "anonymous", "actions": [ { "action": "read" } ] }
],
"rest": {
"enabled": true,
"path": "/BooksApi"
}
}
}
}
--rest.methods
僅限預存程序。 允許執行的 HTTP 動詞有:GET, POST, PUTPATCHDELETE 預設為 POST。 對於資料表/檢視會忽略。
Example
dab add BookProc \
--source dbo.MyProc \
--source.type stored-procedure \
--permissions "admin:execute" \
--rest true \
--rest.methods GET,POST
產生的設定
{
"entities": {
"BookProc": {
"source": { "type": "stored-procedure", "object": "dbo.MyProc" },
"permissions": [
{ "role": "admin", "actions": [ { "action": "execute" } ] }
],
"rest": {
"enabled": true,
"methods": [ "get", "post" ]
}
}
}
}
-s, --source
必須的。 資料庫物件名稱:資料表、檢視表、容器或儲存程序。
Example
產生的設定
{
"entities": {
"Book": {
"source": {
"type": "table",
"object": "dbo.Books"
},
"permissions": [
{ "role": "anonymous", "actions": [ { "action": "read" } ] }
]
}
}
}
--source.key-fields
作為主鍵的欄位。 透過 CLI 產生的檢視是必須的。
Example
dab add BookView \
--source dbo.MyView \
--source.type view \
--source.key-fields "id,region" \
--permissions "anonymous:read"
產生的設定
{
"entities": {
"BookView": {
"source": {
"type": "view",
"object": "dbo.MyView",
"key-fields": [ "id", "region" ]
},
"permissions": [
{ "role": "anonymous", "actions": [ { "action": "read" } ] }
]
}
}
}
--source.params
僅限預存程序。 逗號分隔 name:value 的配對。 不允許用於資料表或檢視。
備註
在 v1.7 預發布版本中,CLI(目前為 RC) --source.params 已被棄用。 改用 --parameters.name、 --parameters.default及相關 --parameters.* 選項。
Example
dab add BookProc \
--source dbo.MyProc \
--source.type stored-procedure \
--source.params "year:2024,active:true" \
--permissions "admin:execute"
產生的設定
{
"entities": {
"BookProc": {
"source": {
"type": "stored-procedure",
"object": "dbo.MyProc",
"parameters": [
{
"name": "year",
"required": false,
"default": "2024"
},
{
"name": "active",
"required": false,
"default": "True"
}
]
},
"permissions": [
{ "role": "admin", "actions": [ { "action": "execute" } ] }
]
}
}
}
--help
顯示此說明畫面。
Example
--version
顯示版本資訊。
Example
--source.type
資料庫物件的類型。 預設值:table。
Example
產生的設定
{
"entities": {
"Book": {
"source": {
"type": "table",
"object": "dbo.Books"
},
"permissions": [
{ "role": "anonymous", "actions": [ { "action": "read" } ] }
]
}
}
}