Skip to content

dab init

初始化一个新的数据墙DBW 配置文件。生成的 JSON 包含数据源信息、启用的终结点、身份验证设置和默认运行时行为。

语法

bash
dab init [options]

WARNING

如果目标配置文件已存在,dab init 会直接覆盖,不会合并。如需保留旧文件,先做备份或使用版本控制。

选项

基本选项

选项说明默认值
-c, --config输出的配置文件路径dab-config.json

数据源选项

选项说明
--database-type数据库类型:mssqlmysqlpostgresql
--connection-string数据库连接字符串,支持 @env()
--set-session-context启用 SQL Server session context(仅 mssql

GraphQL 选项

选项说明默认值
--graphql.enabled是否启用 GraphQLtrue
--graphql.pathGraphQL 端点前缀/graphql
--graphql.multiple-create.enabled是否允许多重创建变更false

主机与认证选项

选项说明默认值
--host-mode运行模式:DevelopmentProductionProduction
--cors-origin允许的跨域来源列表(逗号分隔)
--rest.enabled是否启用 RESTtrue
--rest.pathREST 端点前缀/api
--auth.provider身份验证提供程序Unauthenticated
--auth.issuerJWT issuer(Custom 提供程序时使用)
--auth.audienceJWT audience(Custom 提供程序时使用)
--mcp.enabled是否启用 MCPtrue

示例

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 单独添加。

下一步

数据墙DBW 产品文档与开发指南。