D1Database
Source:
src/Cloudflare/D1/D1Database.ts
A Cloudflare D1 serverless SQL database built on SQLite.
D1 is a serverless relational database that runs at the edge. Create a database as a resource, then bind it to a Worker to run SQL queries.
Creating a Database
Section titled “Creating a Database”Basic database
const db = yield* Cloudflare.D1Database("my-db");Database with location hint
const db = yield* Cloudflare.D1Database("my-db", { primaryLocationHint: "wnam",});Binding to a Worker
Section titled “Binding to a Worker”const db = yield* Cloudflare.D1Connection.bind(MyDB);
// Run a queryconst results = yield* db.prepare("SELECT * FROM users WHERE id = ?") .bind(userId) .all();
// Execute a mutationyield* db.prepare("INSERT INTO users (id, name) VALUES (?, ?)") .bind(newId, name) .run();