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 loke somthing like this
name = "YOU PROJECT NAME"
main = "src/index.ts"
compatibility_date = "2022-11-07"
node_compat = true
[[ d1_databases ]]
binding = "DB"
database_name = "YOU DB NAME"
database_id = "YOUR DB ID"
To init local database and run server locally
wrangler d1 execute <DATABASE_NAME> --local --file=./drizzle/20221126113135/migration.sql
wrangler dev --local --persist
Install Drizzle ORM and SQLite packages
npm install drizzle-orm drizzle-orm-sqlite
To automatically generate migration .sql files, when src/schema.ts chages
npm install drizzle-kit
## package.json
{
...
scripts: {
"generate": "drizzle-kit generate --schema=src/schema.ts dialect=sqlite"
}
}
npm run generate