D1
List
Returns a list of D1 databases.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account Identifier. | |
params | array | No | [] | Query Parameters. |
$response = $client->d1()->list('ACCOUNT_ID', []);
Create
Create D1 Database
$client->d1()->create('ACCOUNT_ID', [
'name' => 'my-database',
'primary_location_hint' => 'weur',
]);
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account Identifier. | |
values | array | Yes | `name` is required and must match `^[a-z0-9][a-z0-9-_]*$`. `primary_location_hint` (`wnam`, `enam`, `weur`, `eeur`, `apac` or `oc`) places the primary, defaulting to near the caller. `read_replication` and `jurisdiction` are optional. |
$response = $client->d1()->create('ACCOUNT_ID', []);
Get
Returns the specified D1 database.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account Identifier. | |
databaseId | string | Yes | Database Identifier. |
$response = $client->d1()->get('ACCOUNT_ID', 'DATABASE_ID');
Delete
Deletes the specified D1 database.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account Identifier. | |
databaseId | string | Yes | Database Identifier. |
$response = $client->d1()->delete('ACCOUNT_ID', 'DATABASE_ID');
Update
Updates the specified D1 database, overwriting the full configuration.
$client->d1()->update('ACCOUNT_ID', 'DATABASE_ID', [
'read_replication' => ['mode' => 'auto'],
]);
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account Identifier. | |
databaseId | string | Yes | Database Identifier. | |
values | array | Yes | `read_replication` is required, itself carrying a `mode` of `auto` to let D1 place replicas around the world, or `disabled` to use none. |
$response = $client->d1()->update('ACCOUNT_ID', 'DATABASE_ID', []);
Edit
Applies changes to the specified D1 database, overwriting only the supplied properties.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account Identifier. | |
databaseId | string | Yes | Database Identifier. | |
values | array | Yes | Values to patch on the database, e.g. `read_replication`. |
$response = $client->d1()->edit('ACCOUNT_ID', 'DATABASE_ID', []);
Bookmark
Get a Time Travel bookmark for a D1 database.
Without a timestamp you get the current bookmark; with one, the nearest
bookmark at or before it. Feed either into restore().
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account Identifier. | |
databaseId | string | Yes | Database Identifier. | |
timestamp | string|null | No | ISO 8601 timestamp to find the nearest bookmark at or before. Omit for the current bookmark. |
$response = $client->d1()->bookmark('ACCOUNT_ID', 'DATABASE_ID', 'TIMESTAMP');
Restore
Restore a D1 database to a previous point in time.
Give it exactly one of a bookmark or a timestamp — a bookmark from
bookmark() names an exact point, a timestamp asks D1 to find the
nearest one.
$bookmark = $client->d1()->bookmark('ACCOUNT_ID', 'DATABASE_ID')->json('result.bookmark');
$client->d1()->restore('ACCOUNT_ID', 'DATABASE_ID', bookmark: $bookmark);
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account Identifier. | |
databaseId | string | Yes | Database Identifier. | |
bookmark | string|null | No | Bookmark to restore to. Required if `$timestamp` is not given. | |
timestamp | string|null | No | ISO 8601 timestamp to restore to. Required if `$bookmark` is not given. |
$response = $client->d1()->restore('ACCOUNT_ID', 'DATABASE_ID', 'BOOKMARK', 'TIMESTAMP');
Export
Returns a URL where the SQL contents of your D1 can be downloaded. Note: this process may take some time for larger DBs, during which your D1 will be unavailable to serve queries. To avoid blocking your DB unnecessarily, an in-progress export must be continually polled or will automatically cancel.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account Identifier. | |
databaseId | string | Yes | Database Identifier. | |
currentBookmark | string|null | No | To poll an in-progress export, provide the current bookmark (returned by your first polling response) | |
noData | bool | No | false | Export only the table definitions, not their contents |
noSchema | bool | No | false | Export only each table's contents, not its definition |
tables | array | No | [] | Filter the export to just one or more tables. Passing an empty array is the same as not passing anything and means: export all tables. |
$response = $client->d1()->export('ACCOUNT_ID', 'DATABASE_ID', 'CURRENT_BOOKMARK', true, true, []);
Import
Generates a temporary URL for uploading an SQL file to, then instructing the D1 to import it and polling it for status updates. Imports block the D1 for their duration.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account Identifier. | |
databaseId | string | Yes | Database Identifier. | |
action | string | No | 'init' | - `init`: Indicates you have a new SQL file to upload. - `ingest`: Indicates you've finished uploading to tell the D1 to start consuming it - `poll`: Indicates you've finished uploading to tell the D1 to start consuming it |
etag | string|null | No | Required when action is `init` or `ingest`. An md5 hash of the file you're uploading. Used to check if it already exists, and validate its contents before ingesting. | |
filename | string|null | No | The filename you have successfully uploaded. | |
currentBookmark | string|null | No | This identifies the currently-running import, checking its status. |
$response = $client->d1()->import('ACCOUNT_ID', 'DATABASE_ID', 'ACTION', 'ETAG', 'FILENAME', 'CURRENT_BOOKMARK');
Query
Returns the query result as an object.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account Identifier. | |
databaseId | string | Yes | Database Identifier. | |
query | string | Yes | Your SQL query. Supports multiple statements, joined by semicolons, which will be executed as a batch. | |
params | array | No | [] | Query params. |
$response = $client->d1()->query('ACCOUNT_ID', 'DATABASE_ID', 'QUERY', []);
Raw
Returns the query result rows as arrays rather than objects. This is a performance-optimized version of the /query endpoint.
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
accountId | string | Yes | Account Identifier. | |
databaseId | string | Yes | Database Identifier. | |
query | string | Yes | Your SQL query. Supports multiple statements, joined by semicolons, which will be executed as a batch. | |
params | array | No | [] | Query params. |
$response = $client->d1()->raw('ACCOUNT_ID', 'DATABASE_ID', 'QUERY', []);

