Skip to content

Instantly share code, notes, and snippets.

@shuymn
Created September 3, 2023 06:16
Show Gist options
  • Select an option

  • Save shuymn/0b46da1cf8aed79be197d7f46fff37cd to your computer and use it in GitHub Desktop.

Select an option

Save shuymn/0b46da1cf8aed79be197d7f46fff37cd to your computer and use it in GitHub Desktop.
import { Miniflare } from 'miniflare'
const mf = new Miniflare({
modules: true,
script: 'addEventListener("fetch", (event) => event.respondWith(new Response(null, { status: 404 })));',
d1Databases: ['DEBUG'],
})
const QUERY = `
CREATE TABLE debug (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL GENERATED ALWAYS AS (JSON_EXTRACT("properties", "$.name")) STORED,
properties TEXT NOT NULL
);
`
const db = await mf.getD1Database('DEBUG')
await db.prepare(QUERY).run()
// console.log(await db.prepare('SELECT * FROM sqlite_master').all())
await mf.dispose()
@shuymn
Copy link
Author

shuymn commented Sep 3, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment