Skip to content
Start here

Create D1 Database

client.D1.Database.New(ctx, params) (*D1, error)
POST/accounts/{account_id}/d1/database

Returns the created D1 database.

Security
API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
Accepted Permissions (at least one required)
D1 Write
ParametersExpand Collapse
params DatabaseNewParams
AccountID param.Field[string]

Path param: Account identifier tag.

maxLength32
Name param.Field[string]

Body param: D1 database name.

Jurisdiction param.Field[DatabaseNewParamsJurisdiction]optional

Body param: Specify the location to restrict the D1 database to run and store data. If this option is present, the location hint is ignored.

const DatabaseNewParamsJurisdictionEu DatabaseNewParamsJurisdiction = "eu"
const DatabaseNewParamsJurisdictionFedramp DatabaseNewParamsJurisdiction = "fedramp"
PrimaryLocationHint param.Field[DatabaseNewParamsPrimaryLocationHint]optional

Body param: Specify the region to create the D1 primary, if available. If this option is omitted, the D1 will be created as close as possible to the current user.

const DatabaseNewParamsPrimaryLocationHintWnam DatabaseNewParamsPrimaryLocationHint = "wnam"
const DatabaseNewParamsPrimaryLocationHintEnam DatabaseNewParamsPrimaryLocationHint = "enam"
const DatabaseNewParamsPrimaryLocationHintWeur DatabaseNewParamsPrimaryLocationHint = "weur"
const DatabaseNewParamsPrimaryLocationHintEeur DatabaseNewParamsPrimaryLocationHint = "eeur"
const DatabaseNewParamsPrimaryLocationHintApac DatabaseNewParamsPrimaryLocationHint = "apac"
const DatabaseNewParamsPrimaryLocationHintOc DatabaseNewParamsPrimaryLocationHint = "oc"
ReturnsExpand Collapse
type D1 struct{…}

The details of the D1 database.

CreatedAt Timeoptional

Specifies the timestamp the resource was created as an ISO8601 string.

formatdate-time
FileSize float64optional

The D1 database's size, in bytes.

Jurisdiction D1Jurisdictionoptional

Specify the location to restrict the D1 database to run and store data. If this option is present, the location hint is ignored.

One of the following:
const D1JurisdictionEu D1Jurisdiction = "eu"
const D1JurisdictionFedramp D1Jurisdiction = "fedramp"
Name stringoptional

D1 database name.

NumTables float64optional
ReadReplication D1ReadReplicationoptional

Configuration for D1 read replication.

Mode D1ReadReplicationMode

The read replication mode for the database. Use 'auto' to create replicas and allow D1 automatically place them around the world, or 'disabled' to not use any database replicas (it can take a few hours for all replicas to be deleted).

One of the following:
const D1ReadReplicationModeAuto D1ReadReplicationMode = "auto"
const D1ReadReplicationModeDisabled D1ReadReplicationMode = "disabled"
UUID stringoptional

D1 database identifier (UUID).

Version stringoptional

Create D1 Database

package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/d1"
  "github.com/cloudflare/cloudflare-go/option"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  d1, err := client.D1.Database.New(context.TODO(), d1.DatabaseNewParams{
    AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
    Name: cloudflare.F("my-database"),
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", d1.UUID)
}
{
  "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
{
  "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
}