Skip to content
Start here

Raw D1 Database query

client.D1.Database.Raw(ctx, databaseID, params) (*SinglePage[DatabaseRawResponse], error)
POST/accounts/{account_id}/d1/database/{database_id}/raw

Returns the query result rows as arrays rather than objects. This is a performance-optimized version of the /query endpoint.

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 ReadD1 Write
ParametersExpand Collapse
databaseID string

D1 database identifier (UUID).

params DatabaseRawParams
AccountID param.Field[string]

Path param: Account identifier tag.

maxLength32
Sql param.Field[string]

Body param: Your SQL query. Supports multiple statements, joined by semicolons, which will be executed as a batch.

Params param.Field[[]string]optional

Body param

ReturnsExpand Collapse
type DatabaseRawResponse struct{…}
Meta DatabaseRawResponseMetaoptional
ChangedDB booloptional

Denotes if the database has been altered in some way, like deleting rows.

Changes float64optional

Rough indication of how many rows were modified by the query, as provided by SQLite's sqlite3_total_changes().

Duration float64optional

The duration of the SQL query execution inside the database. Does not include any network communication.

LastRowID float64optional

The row ID of the last inserted row in a table with an INTEGER PRIMARY KEY as provided by SQLite. Tables created with WITHOUT ROWID do not populate this.

RowsRead float64optional

Number of rows read during the SQL query execution, including indices (not all rows are necessarily returned).

RowsWritten float64optional

Number of rows written during the SQL query execution, including indices.

ServedByColo stringoptional

The three letters airport code of the colo that handled the query.

ServedByPrimary booloptional

Denotes if the query has been handled by the database primary instance.

ServedByRegion DatabaseRawResponseMetaServedByRegionoptional

Region location hint of the database instance that handled the query.

One of the following:
const DatabaseRawResponseMetaServedByRegionWnam DatabaseRawResponseMetaServedByRegion = "WNAM"
const DatabaseRawResponseMetaServedByRegionEnam DatabaseRawResponseMetaServedByRegion = "ENAM"
const DatabaseRawResponseMetaServedByRegionWeur DatabaseRawResponseMetaServedByRegion = "WEUR"
const DatabaseRawResponseMetaServedByRegionEeur DatabaseRawResponseMetaServedByRegion = "EEUR"
const DatabaseRawResponseMetaServedByRegionApac DatabaseRawResponseMetaServedByRegion = "APAC"
const DatabaseRawResponseMetaServedByRegionOc DatabaseRawResponseMetaServedByRegion = "OC"
SizeAfter float64optional

Size of the database after the query committed, in bytes.

Timings DatabaseRawResponseMetaTimingsoptional

Various durations for the query.

SqlDurationMs float64optional

The duration of the SQL query execution inside the database. Does not include any network communication.

Results DatabaseRawResponseResultsoptional
Columns []stringoptional
Rows [][]unknownoptional
One of the following:
unknown
Success booloptional

Raw D1 Database query

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"),
  )
  page, err := client.D1.Database.Raw(
    context.TODO(),
    "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    d1.DatabaseRawParams{
      AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
      Body: d1.DatabaseRawParamsBodyD1SingleQuery{
        Sql: cloudflare.F("SELECT * FROM myTable WHERE field = ? OR field = ?;"),
      },
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", page)
}
{
  "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": [
    {
      "meta": {
        "changed_db": true,
        "changes": 0,
        "duration": 0,
        "last_row_id": 0,
        "rows_read": 0,
        "rows_written": 0,
        "served_by_colo": "LHR",
        "served_by_primary": true,
        "served_by_region": "EEUR",
        "size_after": 0,
        "timings": {
          "sql_duration_ms": 0
        }
      },
      "results": {
        "columns": [
          "string"
        ],
        "rows": [
          [
            0
          ]
        ]
      },
      "success": true
    }
  ],
  "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": [
    {
      "meta": {
        "changed_db": true,
        "changes": 0,
        "duration": 0,
        "last_row_id": 0,
        "rows_read": 0,
        "rows_written": 0,
        "served_by_colo": "LHR",
        "served_by_primary": true,
        "served_by_region": "EEUR",
        "size_after": 0,
        "timings": {
          "sql_duration_ms": 0
        }
      },
      "results": {
        "columns": [
          "string"
        ],
        "rows": [
          [
            0
          ]
        ]
      },
      "success": true
    }
  ],
  "success": true
}