Create D1 Database (D1 데이터베이스 만들기)
이 문서는 Cloudflare API를 사용해 계정에 새 D1 데이터베이스를 만드는 방법을 설명하는 API 레퍼런스예요.
출처: 문서
본문
POST/accounts/{account_id}/d1/database
계정에 새 D1 데이터베이스를 만들어요.
보안 (Security)
API Email + API Key
Global API 키와 함께 사용되던, Cloudflare API와 상호작용하기 위한 이전 인증 방식이에요.
예시: X-Auth-Email: user@example.com
Cloudflare API와 상호작용하기 위한 이전 인증 방식이에요. 가능하면 Global API 키 대신 API 토큰을 사용하세요.
예시: X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
허용되는 권한 (Accepted Permissions, 최소 하나 이상 필요)
D1 Write
경로 매개변수 (Path Parameters)
account_id: string
계정 식별자 태그(Account identifier tag)예요.
maxLength32
본문 매개변수 (Body Parameters)
name: string
D1 데이터베이스 이름이에요.
jurisdiction: optional "eu" 또는 "fedramp" 또는 "us"
D1 데이터베이스가 실행되고 데이터를 저장할 위치를 제한할 지역을 지정해요. 이 옵션이 있으면 위치 힌트(location hint)는 무시돼요.
다음 중 하나:
"eu"
"fedramp"
"us"
primary_location_hint: optional "wnam" 또는 "enam" 또는 "weur" 또는 그 외 3개
가능하면 D1 primary를 만들 지역을 지정해요. 이 옵션을 생략하면 D1은 현재 사용자에게 최대한 가까운 곳에 생성돼요.
다음 중 하나:
"wnam"
"enam"
"weur"
"eeur"
"apac"
"oc"
read_replication: optional object {mode }
D1 읽기 복제에 대한 설정이에요.
mode: "auto" 또는 "disabled"
데이터베이스의 읽기 복제 모드예요. 'auto'를 사용해 복제본을 만들고 D1이 자동으로 전 세계에 배치하도록 하거나, 'disabled'를 사용해 데이터베이스 복제본을 사용하지 않도록 해요 (모든 복제본이 삭제되는 데 몇 시간이 걸릴 수 있어요).
다음 중 하나:
"auto"
"disabled"
반환 (Returns)
errors: array of ResponseInfo { code, message, documentation_url, source }
code: number
minimum1000
message: string
documentation_url: optional string
source: optional object {pointer }
pointer: optional string
messages: array of ResponseInfo { code, message, documentation_url, source }
code: number
minimum1000
message: string
documentation_url: optional string
source: optional object {pointer }
pointer: optional string
result: D1 { created_at, file_size, jurisdiction, 그 외 5개 }
D1 데이터베이스의 세부 정보예요.
created_at: optional string
리소스가 생성된 타임스탬프를 ISO8601 문자열로 지정해요.
formatdate-time
file_size: optional number
D1 데이터베이스의 크기(바이트)예요.
jurisdiction: optional "eu" 또는 "fedramp" 또는 "us"
D1 데이터베이스가 실행되고 데이터를 저장할 위치를 제한할 지역을 지정해요. 이 옵션이 있으면 위치 힌트는 무시돼요.
다음 중 하나:
"eu"
"fedramp"
"us"
name: optional string
D1 데이터베이스 이름이에요.
Deprecated num_tables: optional number
D1 데이터베이스의 테이블 수예요. 이 개수는 더 이상 정확하지 않으며 의존해서는 안 돼요.
read_replication: optional object {mode }
D1 읽기 복제에 대한 설정이에요.
mode: "auto" 또는 "disabled"
데이터베이스의 읽기 복제 모드예요. 'auto' 모드는 D1이 복제본을 만들어 전 세계에 자동으로 배치함을 의미해요. 'disabled' 모드는 데이터베이스 복제본을 사용하지 않음을 의미해요.
다음 중 하나:
"auto"
"disabled"
uuid: optional string
D1 데이터베이스 식별자(UUID)예요.
version: optional string
success: true
API 호출이 성공했는지 여부예요.
Create D1 Database
HTTP
curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/d1/database \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $CLOUD...OKEN" \
-d '{
"name": "my-database",
"jurisdiction": "eu",
"primary_location_hint": "wnam"
}'
200 example
{
"errors": [
{
"code": 1000,
"message": "message",
"documentation_url": "documentation_url",
"source": {
"pointer": "pointer"
}
}
],
"messages": [
{
"code": 1000,
"message": "message",
"documentation_url": "documentation_url",
"source": {
"pointer": "pointer"
}
}
],
"result": {
"created_at": "2022-11-15T18:25:44.442097Z",
"file_size": 12,
"jurisdiction": "eu",
"name": "my-database",
"num_tables": 12,
"read_replication": {
"mode": "auto"
},
"uuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"version": "production"
},
"success": true
}
반환 예시 (Returns Examples)
200 example
{
"errors": [
{
"code": 1000,
"message": "message",
"documentation_url": "documentation_url",
"source": {
"pointer": "pointer"
}
}
],
"messages": [
{
"code": 1000,
"message": "message",
"documentation_url": "documentation_url",
"source": {
"pointer": "pointer"
}
}
],
"result": {
"created_at": "2022-11-15T18:25:44.442097Z",
"file_size": 12,
"jurisdiction": "eu",
"name": "my-database",
"num_tables": 12,
"read_replication": {
"mode": "auto"
},
"uuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"version": "production"
},
"success": true
}