إشعار
يتطلب الوصول إلى هذه الصفحة تخويلاً. يمكنك محاولة تسجيل الدخول أو تغيير الدلائل.
يتطلب الوصول إلى هذه الصفحة تخويلاً. يمكنك محاولة تغيير الدلائل.
Add a new entity definition to an existing Data API builder configuration file. You must already have a config created with dab init. Use dab update to modify entities after creation.
Tip
Use dab add to create new entities, and dab update to evolve them.
Syntax
dab add <entity-name> [options]
Quick glance
| Option | Summary |
|---|---|
<entity-name> |
Required positional argument. Logical entity name. |
-c, --config |
Config file path. Default dab-config.json. |
--cache.enabled |
Enable/disable caching for entity. |
--cache.ttl |
Cache time-to-live in seconds. |
--description |
Free-form description for entity. |
--fields.exclude |
Comma-separated excluded fields. |
--fields.include |
Comma-separated allowed fields (* = all). |
--fields.name |
Field names to describe (repeatable or comma-separated). |
--fields.alias |
Field aliases (comma-separated, aligned to --fields.name). |
--fields.description |
Field descriptions (comma-separated, aligned to --fields.name). |
--fields.primary-key |
Primary key flags (comma-separated, aligned to --fields.name). |
--graphql |
GraphQL exposure: false, true, singular, or singular:plural. |
--graphql.operation |
Stored procedures only. Query or Mutation (default mutation). |
--permissions |
Required. role:actions for a single role. |
--policy-database |
OData-style filter applied in DB query. |
--policy-request |
Request policy evaluated before DB call. |
--parameters.name |
Stored procedures only. Parameter names (comma-separated). |
--parameters.description |
Stored procedures only. Parameter descriptions. |
--parameters.required |
Stored procedures only. Parameter required flags. |
--parameters.default |
Stored procedures only. Parameter default values. |
--rest |
REST exposure: false, true, or custom route. |
--rest.methods |
Stored procedures only. Allowed verbs: GET, POST, PUT, PATCH, DELETE. Default POST. |
-s, --source |
Required. Database object name (table, view, or stored procedure). |
--source.key-fields |
The field(s) to be used as primary keys. |
--source.params |
Stored procedures only. Default parameter values. |
--source.type |
Source type: table, view, stored-procedure (default table). |
--help |
Display this help screen. |
--version |
Display version information. |
<entity-name>
Logical name of the entity in config. Case-sensitive.
Quick examples for tables, views, and stored procedures
Add a table
dab add Book \
--source dbo.Books \
--source.type table \
--permissions "anonymous:read" \
--description "Example for managing book inventory"
Add a view
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"
Add a stored procedure
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
Config file path. Default is dab-config.json.
Example
dab add Book \
--config ./dab-config.mssql.json \
--source dbo.Books \
--permissions "anonymous:read"
--cache.enabled
Enable or disable caching.
Example
dab add Book \
--source dbo.Books \
--permissions "anonymous:read" \
--cache.enabled true
Resulting config
{
"entities": {
"Book": {
"source": {
"type": "table",
"object": "dbo.Books"
},
"permissions": [
{ "role": "anonymous", "actions": [ { "action": "read" } ] }
],
"cache": {
"enabled": true
}
}
}
}
--cache.ttl
Cache time-to-live in seconds.
Example
dab add Book \
--source dbo.Books \
--permissions "anonymous:read" \
--cache.ttl 300
Resulting config
{
"entities": {
"Book": {
"source": {
"type": "table",
"object": "dbo.Books"
},
"permissions": [
{ "role": "anonymous", "actions": [ { "action": "read" } ] }
],
"cache": {
"enabled": false,
"ttl-seconds": 300
}
}
}
}
--description
Free-text description of the entity.
Note
This option is available only in the v1.7 prerelease CLI (currently RC). Install with dotnet tool install microsoft.dataapibuilder --prerelease.
Example
dab add Book \
--source dbo.Books \
--permissions "anonymous:read" \
--description "Entity for managing book inventory"
Resulting config
{
"entities": {
"Book": {
"source": {
"type": "table",
"object": "dbo.Books"
},
"permissions": [
{ "role": "anonymous", "actions": [ { "action": "read" } ] }
],
"description": "Entity for managing book inventory"
}
}
}
--fields.exclude
Comma-separated list of fields to exclude.
Example
dab add Book \
--source dbo.Books \
--permissions "anonymous:read" \
--fields.exclude "internal_flag,secret_note"
Resulting config
{
"entities": {
"Book": {
"source": { "type": "table", "object": "dbo.Books" },
"permissions": [
{
"role": "anonymous",
"actions": [
{
"action": "read",
"fields": {
"exclude": [ "internal_flag", "secret_note" ]
}
}
]
}
]
}
}
}
--fields.include
Comma-separated list of fields to expose.
Example
dab add Book \
--source dbo.Books \
--permissions "anonymous:read" \
--fields.include "id,title,price"
Resulting config
{
"entities": {
"Book": {
"source": { "type": "table", "object": "dbo.Books" },
"permissions": [
{
"role": "anonymous",
"actions": [
{
"action": "read",
"fields": {
"include": [ "id", "title", "price" ]
}
}
]
}
]
}
}
}
--graphql
Control GraphQL exposure.
Example
dab add Book \
--source dbo.Books \
--permissions "anonymous:read" \
--graphql book:books
Resulting config
{
"entities": {
"Book": {
"source": { "type": "table", "object": "dbo.Books" },
"permissions": [
{ "role": "anonymous", "actions": [ { "action": "read" } ] }
],
"graphql": {
"enabled": true,
"type": {
"singular": "book",
"plural": "books"
}
}
}
}
}
--graphql.operation
Stored procedures only. GraphQL operation type. Default is mutation.
Example
dab add BookProc \
--source dbo.MyProc \
--source.type stored-procedure \
--permissions "admin:execute" \
--graphql.operation Query
Resulting config
{
"entities": {
"BookProc": {
"source": { "type": "stored-procedure", "object": "dbo.MyProc" },
"permissions": [
{ "role": "admin", "actions": [ { "action": "execute" } ] }
],
"graphql": {
"enabled": true,
"operation": "query"
}
}
}
}
--permissions
Defines role→actions pairs.
--permissions isn't repeatable. To add more roles, run dab add with one role and then run dab update for additional roles.
Example
dab add Book \
--source dbo.Books \
--permissions "anonymous:read"
dab update Book \
--permissions "authenticated:create,read,update,delete"
--parameters.name
Stored procedures only. Comma-separated list of parameter names.
Note
This option is available only in the v1.7 prerelease CLI (currently RC). Install with 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"
Resulting config
{
"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
Stored procedures only. Comma-separated list of parameter descriptions aligned to --parameters.name.
Note
This option is available only in the v1.7 prerelease CLI (currently RC). Install with 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
Stored procedures only. Comma-separated list of true/false values aligned to --parameters.name.
Note
This option is available only in the v1.7 prerelease CLI (currently RC). Install with 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
Stored procedures only. Comma-separated list of default values aligned to --parameters.name.
Note
This option is available only in the v1.7 prerelease CLI (currently RC). Install with 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
Name of the database column to describe.
Note
This option is available only in the v1.7 prerelease CLI (currently RC). Install with 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"
Resulting config
{
"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
Alias for the field. Use a comma-separated list aligned to --fields.name.
Note
This option is available only in the v1.7 prerelease CLI (currently RC). Install with dotnet tool install microsoft.dataapibuilder --prerelease.
Example
dab add Products \
--source dbo.Products \
--permissions "anonymous:*" \
--fields.name "ProductID" \
--fields.alias "product_id"
--fields.description
Description for the field. Use a comma-separated list aligned to --fields.name.
Note
This option is available only in the v1.7 prerelease CLI (currently RC). Install with 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
Primary key flag for the field. Use a comma-separated list of true/false values aligned to --fields.name.
Note
This option is available only in the v1.7 prerelease CLI (currently RC). Install with dotnet tool install microsoft.dataapibuilder --prerelease.
Example
dab add Products \
--source dbo.Products \
--permissions "anonymous:*" \
--fields.name "ProductID" \
--fields.primary-key "true"
Resulting config
{
"entities": {
"Products": {
"source": { "type": "table", "object": "dbo.Products" },
"permissions": [
{ "role": "anonymous", "actions": [ { "action": "*" } ] }
],
"fields": [
{
"name": "ProductID",
"primary-key": true
}
]
}
}
}
--policy-database
Database-level policy.
Example
dab add Book \
--source dbo.Books \
--permissions "anonymous:read" \
--policy-database "region eq 'US'"
Resulting config
{
"entities": {
"Book": {
"source": { "type": "table", "object": "dbo.Books" },
"permissions": [
{
"role": "anonymous",
"actions": [
{
"action": "read",
"policy": {
"database": "region eq 'US'"
}
}
]
}
]
}
}
}
--policy-request
Request-level policy.
Example
dab add Book \
--source dbo.Books \
--permissions "anonymous:read" \
--policy-request "@claims.role == 'admin'"
Resulting config
{
"entities": {
"Book": {
"source": { "type": "table", "object": "dbo.Books" },
"permissions": [
{
"role": "anonymous",
"actions": [
{
"action": "read",
"policy": {
"request": "@claims.role == 'admin'"
}
}
]
}
]
}
}
}
--rest
Control REST exposure.
Example
dab add Book \
--source dbo.Books \
--permissions "anonymous:read" \
--rest BooksApi
Resulting config
{
"entities": {
"Book": {
"source": { "type": "table", "object": "dbo.Books" },
"permissions": [
{ "role": "anonymous", "actions": [ { "action": "read" } ] }
],
"rest": {
"enabled": true,
"path": "/BooksApi"
}
}
}
}
--rest.methods
Stored procedures only. HTTP verbs allowed for execution: GET, POST, PUT, PATCH, DELETE. Defaults to POST. Ignored for tables/views.
Example
dab add BookProc \
--source dbo.MyProc \
--source.type stored-procedure \
--permissions "admin:execute" \
--rest true \
--rest.methods GET,POST
Resulting config
{
"entities": {
"BookProc": {
"source": { "type": "stored-procedure", "object": "dbo.MyProc" },
"permissions": [
{ "role": "admin", "actions": [ { "action": "execute" } ] }
],
"rest": {
"enabled": true,
"methods": [ "get", "post" ]
}
}
}
}
-s, --source
Required. Name of the database object: table, view, container, or stored procedure.
Example
dab add Book \
--source dbo.Books \
--permissions "anonymous:read"
Resulting config
{
"entities": {
"Book": {
"source": {
"type": "table",
"object": "dbo.Books"
},
"permissions": [
{ "role": "anonymous", "actions": [ { "action": "read" } ] }
]
}
}
}
--source.key-fields
The field(s) to be used as primary keys. Required for views when generated through the CLI.
Example
dab add BookView \
--source dbo.MyView \
--source.type view \
--source.key-fields "id,region" \
--permissions "anonymous:read"
Resulting config
{
"entities": {
"BookView": {
"source": {
"type": "view",
"object": "dbo.MyView",
"key-fields": [ "id", "region" ]
},
"permissions": [
{ "role": "anonymous", "actions": [ { "action": "read" } ] }
]
}
}
}
--source.params
Stored procedures only. Comma-separated name:value pairs. Not allowed for tables or views.
Note
In the v1.7 prerelease CLI (currently RC), --source.params is deprecated. Use --parameters.name, --parameters.default, and related --parameters.* options instead.
Example
dab add BookProc \
--source dbo.MyProc \
--source.type stored-procedure \
--source.params "year:2024,active:true" \
--permissions "admin:execute"
Resulting config
{
"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
Display this help screen.
Example
dab add \
--help
--version
Display version information.
Example
dab add \
--version
--source.type
Type of database object. Default: table.
Example
dab add Book \
--source dbo.Books \
--source.type table \
--permissions "anonymous:read"
Resulting config
{
"entities": {
"Book": {
"source": {
"type": "table",
"object": "dbo.Books"
},
"permissions": [
{ "role": "anonymous", "actions": [ { "action": "read" } ] }
]
}
}
}