본문 바로가기
WIKI 기술 지식 베이스

데이터베이스 생성

원문 보기 위키 갱신

조직 또는 사용자를 위해 그룹 안에 새 데이터베이스를 만드는 API예요.

출처: 문서

본문

요청 예시:

curl -L -X POST 'https://api.turso.tech/v1/organizations/{organizationSlug}/databases' \
  -H 'Authorization: Bearer ***' \
  -H 'Content-Type: application/json' \
  -d '{
      "name": "new-database",
      "group": "default"
  }'

업로드용 요청 예시:

curl -L -X POST 'https://api.turso.tech/v1/organizations/{organizationSlug}/databases' \
  -H 'Authorization: Bearer ***' \
  -H 'Content-Type: application/json' \
  -d '{
      "name": "new-database",
      "group": "default",
      "seed": {
        "type": "database_upload"
      }
  }'

암호화 업로드용 요청 예시:

curl -L -X POST 'https://api.turso.tech/v1/organizations/{organizationSlug}/databases' \
  -H 'Authorization: Bearer ***' \
  -H 'Content-Type: application/json' \
  -d '{
      "name": "new-database",
      "group": "default",
      "seed": {
        "type": "database_upload"
      },
      "remote_encryption": {
        "encryption_key": "BASE64_ENCRYPTION_KEY",
        "encryption_cipher": "aes256gcm"
      }
  }'

새 암호화 데이터베이스 요청 예시:

curl -L -X POST 'https://api.turso.tech/v1/organizations/{organizationSlug}/databases' \
  -H 'Authorization: Bearer ***' \
  -H 'Content-Type: application/json' \
  -d '{
      "name": "new-database",
      "group": "default",
      "remote_encryption": {
        "encryption_key": "BASE64_ENCRYPTION_KEY",
        "encryption_cipher": "aes256gcm"
      }
  }'

암호화 데이터베이스 포크 요청 예시:

curl -L -X POST 'https://api.turso.tech/v1/organizations/{organizationSlug}/databases' \
  -H 'Authorization: Bearer ***' \
  -H 'Content-Type: application/json' \
  -d '{
      "name": "new-database",
      "group": "default",
      "seed": {
        "type": "database",
        "name": "source-encrypted-db"
      },
      "remote_encryption": {
        "encryption_key": "BASE64_ENCRYPTION_KEY",
        "encryption_cipher": "aes256gcm"
      }
  }'

Node.js 요청 예시:

import { createClient } from "@tursodatabase/api";

const turso = createClient({
  org: "...",
  token: "",
});

const database = await turso.databases.create("new-database", {
  group: "default",
});

OpenAPI

openapi: 3.0.1
info:
  title: Turso Platform API
  description: API description here
  license:
    name: MIT
  version: 0.1.0
servers:
  - url: https://api.turso.tech
    description: Turso's Platform API
security: []
paths:
  /v1/organizations/{organizationSlug}/databases:
    post:
      summary: Create Database
      description: Creates a new database in a group for the organization or user.
      operationId: createDatabase
      parameters:
        - $ref: '#/components/parameters/organizationSlug'
      requestBody:
        description: Database data to create a new database
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateDatabaseInput'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  database:
                    $ref: '#/components/schemas/CreateDatabaseOutput'
                    description: The newly created database
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: The error message
                    example: group not found
        '409':
          description: Conflict
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: The error message
                    example: database with name [databaseName] already exists
components:
  parameters:
    organizationSlug:
      in: path
      name: organizationSlug
      required: true
      schema:
        type: string
      description: The slug of the organization or user account.
  schemas:
    CreateDatabaseInput:
      type: object
      properties:
        name:
          type: string
          description: >-
            The name of the new database. Must contain only lowercase letters,
            numbers, dashes. No longer than 64 characters.
        group:
          type: string
          description: >-
            The name of the group where the database should be created. **The
            group must already exist.**
        seed:
          type: object
          properties:
            type:
              type: string
              enum:
                - database
                - database_upload
              description: >-
                The type of seed to be used to create a new database. Use
                `database` to copy from an existing database, or
                `database_upload` to [upload a SQLite database
                file](/api-reference/databases/upload).
              example: database
            name:
              type: string
              description: >-
                The name of the existing database when `database` is used as a
                seed type.
              example: my-db
            timestamp:
              type: string
              description: >-
                A formatted [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)
                recovery point to create a database from. This must be within
                the last 24 hours, or 30 days on the scaler plan.
              example: '2023-12-20T09:46:08Z'
        size_limit:
          type: string
          description: >-
            The maximum size of the database in bytes. Values with units are
            also accepted, e.g. 1mb, 256mb, 1gb.
        remote_encryption:
          type: object
          description: >-
            Encryption configuration for the database. Can be used when creating
            a new encrypted database, creating a encrypted database from upload
            (`seed.type = "database_upload"`), or forking from an encrypted
            database (required when the source database is encrypted).
          properties:
            encryption_key:
              type: string
              description: >-
                Base64-encoded encryption key. Key size depends on cipher: 32
                bytes for aes256gcm, chacha20poly1305, aegis256 variants; 16
                bytes for aes128gcm, aegis128l variants.
              example: base64-encoded-key
            encryption_cipher:
              type: string
              enum:
                - aes256gcm
                - aes128gcm
                - chacha20poly1305
                - aegis128l
                - aegis128x2
                - aegis128x4
                - aegis256
                - aegis256x2
                - aegis256x4
              description: The encryption cipher to use.
              example: aes256gcm
      required:
        - name
        - group
    CreateDatabaseOutput:
      type: object
      properties:
        DbId: 167f392c-6486-4034-96e6-cea54c66a391
        Hostname: 0aeb6468-7306-4f82-bc6b-8d44b22d8dc2
        Name: 0e20ec10-39f6-4155-a7aa-a212bcfe04fc

더 알아보기 (Learn more)