Skip to main content
Every EdgeSpark project includes a Cloudflare D1 database. You define your app tables in server/src/defs/db_schema.ts, generate migrations with the CLI, and query the database from the runtime SDK.

Define your schema

Add app tables to server/src/defs/db_schema.ts:
server/src/defs/db_schema.ts
If you need relations, add them in server/src/defs/db_relations.ts.

Generate and apply migrations

After editing db_schema.ts, run:
Useful related commands:
Use edgespark pull schema only for platform-managed tables that EdgeSpark generates into server/src/__generated__/. Your app tables live in server/src/defs/ and use the migration workflow above.

Query data

Use the runtime SDK inside route handlers:
server/src/index.ts

Update and delete data

server/src/index.ts

Run ad-hoc SQL

For inspection or one-off data changes, use:

Constraints

Runtime DDL is blocked. Do not use edgespark db sql for CREATE TABLE, ALTER TABLE, or DROP TABLE. Apply schema changes through edgespark db generate and edgespark db migrate.
Transactions are not available. Use db.batch([...]) for atomic multi-step operations, and see platform limits whenever you are working near database or bundle constraints.

See also

db reference

Complete API for selects, inserts, updates, deletes, relational queries, and batching.

Declarative workflow

How schema files, generated types, and migrations stay in sync.
Last modified on April 7, 2026