dab init
初始化一个新的数据墙DBW 配置文件。生成的 JSON 包含数据源信息、启用的终结点、身份验证设置和默认运行时行为。
语法
bash
dab init [options]WARNING
如果目标配置文件已存在,dab init 会直接覆盖,不会合并。如需保留旧文件,先做备份或使用版本控制。
选项
基本选项
| 选项 | 说明 | 默认值 |
|---|---|---|
-c, --config | 输出的配置文件路径 | dab-config.json |
数据源选项
| 选项 | 说明 |
|---|---|
--database-type | 数据库类型:mssql、mysql、postgresql |
--connection-string | 数据库连接字符串,支持 @env() |
--set-session-context | 启用 SQL Server session context(仅 mssql) |
GraphQL 选项
| 选项 | 说明 | 默认值 |
|---|---|---|
--graphql.enabled | 是否启用 GraphQL | true |
--graphql.path | GraphQL 端点前缀 | /graphql |
--graphql.multiple-create.enabled | 是否允许多重创建变更 | false |
主机与认证选项
| 选项 | 说明 | 默认值 |
|---|---|---|
--host-mode | 运行模式:Development 或 Production | Production |
--cors-origin | 允许的跨域来源列表(逗号分隔) | — |
--rest.enabled | 是否启用 REST | true |
--rest.path | REST 端点前缀 | /api |
--auth.provider | 身份验证提供程序 | Unauthenticated |
--auth.issuer | JWT issuer(Custom 提供程序时使用) | — |
--auth.audience | JWT audience(Custom 提供程序时使用) | — |
--mcp.enabled | 是否启用 MCP | true |
示例
SQL Server 开发环境
bash
dab init \
--database-type "mssql" \
--connection-string "Server=localhost;Database=todos;User Id=sa;Password=P@ssw0rd1;TrustServerCertificate=true;Encrypt=true;" \
--host-mode "Development" \
--config "dab-config.json"PostgreSQL 生产环境
bash
dab init \
--database-type "postgresql" \
--connection-string "@env('PG_CONN_STR')" \
--host-mode "Production" \
--auth.provider "Custom" \
--auth.issuer "https://idp.example.com/" \
--auth.audience "api://dab-api"MySQL 开发环境(启用 session context)
bash
dab init \
--database-type "mysql" \
--connection-string "Server=localhost;Database=todos;User=root;Password=pwd;" \
--host-mode "Development"生成的配置文件
json
{
"$schema": "https://github.com/Azure/data-api-builder/releases/latest/download/dab.draft.schema.json",
"data-source": {
"database-type": "mssql",
"connection-string": "Server=localhost;Database=todos;User Id=sa;Password=P@ssw0rd1;TrustServerCertificate=true;Encrypt=true;"
},
"runtime": {
"rest": { "enabled": true, "path": "/api" },
"graphql": { "enabled": true, "path": "/graphql" },
"host": { "mode": "development" }
}
}init 只生成基础骨架。实体需要通过 dab add 单独添加。
