Example project for Drizzle ORM D1 SQLite package Subscribe to our updates on Twitter!
To setup project for your Cloudflare D1 - please refer to official docs
## your wrangler.toml will look something like this
name = "YOUR PROJECT NAME"
main = "src/index.ts"
compatibility_date = "2022-11-07"
node_compat = true
[[ d1_databases ]]
binding = "DB"
database_name = "YOUR DB NAME"
database_id = "YOUR DB ID"
To init local database and run server locally
wrangler d1 execute <DATABASE_NAME> --local --file=./drizzle/0000_short_lockheed.sql
wrangler dev --local --persist
Install Drizzle ORM
npm install drizzle-orm
To automatically generate migration .sql files, when src/schema.ts changes
npm install drizzle-kit
## package.json
{
...
scripts: {
"generate": "drizzle-kit generate:sqlite --schema=src/schema.ts",
"up": "drizzle-kit up:sqlite --schema=src/schema.ts"
}
}
npm run generate