이 섹션에서는 data-source 데이터베이스 액세스 세부 정보를 정의합니다. 또한 데이터베이스 옵션을 정의합니다.
데이터 원본 설정
| Property | Description |
|---|---|
| data-source | 데이터베이스 연결 설정을 포함하는 개체 |
| data-source.database-type | 백 엔드에 사용되는 데이터베이스: mssql, postgresql, mysql, cosmosdb_nosqlcosmosdb_postgresql |
| data-source.connection-string | 선택한 데이터베이스 형식에 대한 연결 문자열 |
| data-source.options | 데이터베이스별 속성(예: SQL Server, Cosmos DB 등의 옵션) |
| data-source.options.database | NoSQL용 Azure Cosmos DB 데이터베이스의 이름(필요한 경우 database-type = cosmosdb_nosql) |
| data-source.options.container | NoSQL 컨테이너용 Azure Cosmos DB의 이름(필요한 경우 database-type = cosmosdb_nosql) |
| data-source.options.schema | GraphQL 스키마 파일의 경로(필요한 경우 database-type = cosmosdb_nosql) |
| data-source.options.set-session-context | JWT(JSON Web Token) 클레임을 세션 컨텍스트로 보낼 수 있습니다(SQL Server에만 해당) |
| data-source.health | 데이터 원본에 대한 상태 검사 구성 개체 |
| data-source.health.enabled | 상태 검사 엔드포인트를 사용하도록 설정 |
| data-source.health.name | 상태 보고서에 사용되는 식별자 |
| data-source.health.threshold-ms | 상태 검사 쿼리의 최대 기간(밀리초) |
Format overview
{
"data-source": {
"database-type": <string>,
"connection-string": <string>,
"options": {
// mssql only
"set-session-context": <true> (default) | <false>,
// cosmosdb_nosql only
"database": <string>,
"container": <string>,
"schema": <string>
},
"health": {
"enabled": <true> (default) | <false>,
"name": <string>,
"threshold-ms": <integer; default: 1000>
}
},
"data-source-files": ["<string>"]
}
Data source
| Parent | Property | Type | Required | Default |
|---|---|---|---|---|
$root |
database-source |
object | ✔️ Yes | - |
Nested properties
| Parent | Property | Type | Required | Default |
|---|---|---|---|---|
data-source |
database-type |
enum | ✔️ Yes | None |
data-source |
connection-string |
string | ✔️ Yes | None |
data-source |
options |
object | ❌ 아니요 | None |
Property values
database-type |
Description | Min Version |
|---|---|---|
mssql |
패브릭의 SQL | - |
mssql |
Azure SQL 데이터베이스 | - |
mssql |
Azure SQL MI | - |
mssql |
SQL Server | 2016 |
dwsql |
Azure Synapse Analytics | - |
dwsql |
Fabric Warehouse | - |
dwsql |
패브릭 SQL 분석 엔드포인트 | - |
postgresql |
PostgreSQL | ver. 11 |
mysql |
MySQL | ver. 8 |
cosmosdb_nosql |
NoSQL용 Azure Cosmos DB | - |
cosmosdb_postgresql |
Azure Cosmos DB for PostgreSQL (아주르 코스모스 DB 포스트그레SQL용) | - |
Format
{
"data-source": {
"database-type": <string>,
"connection-string": <string>,
"options": {
"<key-name>": <string>
}
}
}
예: Azure SQL 및 SQL Server
"data-source": {
"database-type": "mssql",
"connection-string": "Server=tcp:myserver.database.windows.net,1433;Initial Catalog=MyDatabase;User ID=MyUser;Password=MyPassword;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;",
"options": {
"set-session-context": true
}
}
Note
We use SqlClient for Azure SQL and SQL Server, which supports these connection strings variants.
소모 SESSION_CONTEXT
Azure SQL 및 SQL Server의 경우 데이터 API 작성기에서 SQL의 SESSION_CONTEXT클레임 정보를 포함할 수 있습니다.
CREATE PROC GetUser @userId INT AS
BEGIN
-- Use claims
IF SESSION_CONTEXT(N'user_role') = 'admin'
BEGIN
RAISERROR('Unauthorized access', 16, 1);
END
SELECT Id, Name, Age, IsAdmin
FROM Users
WHERE Id = @userId;
END;
예: Azure Cosmos DB
"data-source": {
"database-type": "cosmosdb_nosql",
"connection-string": "@env('SQL_CONNECTION_STRING')",
"options": {
"database": "Your_CosmosDB_Database_Name",
"container": "Your_CosmosDB_Container_Name",
"schema": "Path_to_Your_GraphQL_Schema_File"
}
}
Note
지정된 "옵션"(databasecontainer및schema)은 Azure Cosmos DB와 관련이 있습니다.
Environment variables
환경 변수를 사용하여 구성 파일에서 일반 텍스트 비밀을 유지합니다.
Tip
Data API Builder는 function.env](../reference-functions.md#env) and [의 파일을 모두@env() 지원합니다.
"data-source": {
"database-type": "mssql",
"connection-string": "@env('SQL_CONNECTION_STRING')"
}
Connection resiliency
데이터 API 작성기에서는 지수 백오프를 사용하여 일시적인 오류 후 데이터베이스 요청을 다시 시도합니다.
| Attempts | First | Second | Third | Fourth | Fifth |
|---|---|---|---|---|---|
| Seconds | 2s | 4s | 8s | 16s | 32s |
MSI(관리 서비스 ID)
MSI(관리 서비스 ID)는 라이브러리에 Azure.Identity 정의된 상태로 DefaultAzureCredential 지원됩니다.
Azure SQL용 Microsoft Entra의 관리 ID에 대해 자세히 알아봅니다.
UAMI(관리 ID) User-Assigned
For User Assigned Managed Identity, append the Authentication and User Id properties to your connection string while substituting in your User Assigned Managed Identity's client id: Authentication=Active Directory Managed Identity; User Id=<UMI_CLIENT_ID>;.
System-Assigned 관리 ID(SAMI)
For System Assigned Managed Identity, append the Authentication property and exclude the UserId and Password arguments from your connection string: Authentication=Active Directory Managed Identity;.
상태(데이터 원본)
| Parent | Property | Type | Required | Default |
|---|---|---|---|---|
data-source |
health |
object | No | – |
데이터 API 작성기에서는 각각 자체 데이터 원본이 있는 여러 구성 파일을 지원합니다. 이 구성 블록을 사용하면 각 데이터 원본이 자체 상태 구성을 가질 수 있습니다.
Nested properties
| Parent | Property | Type | Required | Default |
|---|---|---|---|---|
data-source.health |
enabled |
boolean | No | true |
data-source.health |
name |
string | No | database-type |
data-source.health |
threshold-ms |
integer | No | 1000 |
Check name
여러 구성 파일이 동일한 형식의 데이터 원본을 가리킬 수 있으므로 상태 보고서에서 해당 데이터 원본을 구분할 수 없습니다. 상태 보고서에만 사용되는 고유하고 식별 가능한 레이블을 할당하는 데 사용합니다 name .
Check behavior
데이터베이스 유형과 관련된 가장 간단한 쿼리는 지정된 데이터 원본에 대해 실행되어 연결을 열 수 있는지 확인합니다. 이 threshold-ms 속성을 사용하여 해당 쿼리가 완료될 최대 허용 기간(밀리초)을 구성합니다.
Format
{
"data-source": {
"health": {
"enabled": <true> (default) | <false>,
"name": <string>,
"threshold-ms": <integer; default: 1000>
}
}
}