Skip to content
Miniflare
Visit Miniflare on GitHub
Set theme to dark (โ‡ง+D)

๐Ÿ’พ D1

Databases

Specify D1 Databases to add to your environment as follows:

wrangler.toml
[[d1_databases]]
binding = "DB"
database_name = "test-db"
database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
const mf = new Miniflare({
d1Databases: {
DB: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
},
});

Working with D1 Databases

For testing, it can be useful to put/get data from D1 storage bound to a worker. You can do this with the getD1Database method:

const db = await mf.getD1Database("DB");
const { results } = await db.prepare("<Query>");
console.log(await res.json(results));