Drizzle ORM patterns -- schema definition, indexes, relations, migrations, transactions, upserts, prepared statements, and connection setup
96
96%
Does it follow best practices?
Impact
98%
1.60xAverage score across 5 eval scenarios
Passed
No known issues
A SaaS company needs the data access layer for their subscription billing system. The backend is TypeScript with Drizzle ORM and SQLite. The system manages customers, subscription plans, and invoices.
Customers subscribe to plans (basic, pro, enterprise -- each with a monthly price). When a billing cycle runs, the system needs to:
The engineering team wants properly typed function signatures that match the schema types without manual duplication.
Produce:
src/db/schema.ts -- Full Drizzle schema for plans, customers, subscriptions, and invoicessrc/db/billing.ts -- The four operations as exported functionssrc/db/db.ts -- Database connection setupThe following starter file is provided:
=============== FILE: package.json =============== { "name": "billing-service", "version": "1.0.0", "dependencies": { "drizzle-orm": "^0.30.0", "better-sqlite3": "^9.0.0" }, "devDependencies": { "drizzle-kit": "^0.21.0", "typescript": "^5.0.0" } }