xx
.md

cf_d1_create

cf_d1_create asynchronously creates a D1 database when no database with the same name exists. Existing databases are reused. The returned resource can be passed directly through any deps argument.

The resource has name and id fields. Reading id waits for provisioning and returns the D1 database UUID as a string. Passing the resource through deps preserves asynchronous execution without reading the ID during Starlark evaluation.

Arguments

ArgumentRequiredDescription
nameYesD1 database name.
locationNoCreation location hint: weur, eeur, apac, oc, wnam, or enam. Existing placement cannot be changed or verified.
jurisdictionNoRequired data jurisdiction: eu, fedramp, or us. An existing database must report the same jurisdiction. Cannot be combined with location.
depsNoDependencies activated before running Wrangler. Use these to provide Wrangler, credentials, or an account ID.

Example

This example expects package.json to list "wrangler": "4.123.0" in devDependencies.

load("@cloudflare@1", "cf_d1_create")
load("@[email protected]", "npm_install")
load("@os@1", "env_prepend", "env_set")

wrangler = npm_install() + env_prepend("PATH", "node_modules/.bin")
account = env_set("CLOUDFLARE_ACCOUNT_ID", "0123456789abcdef0123456789abcdef")
database = cf_d1_create("app", jurisdiction="eu", deps=[wrangler, account])

# Blocks only when the raw ID is needed during Starlark evaluation.
print(database.id)