# Drizzle ORM taste of a TypeScript developer who likes to see the SQL
- Define the schema in TypeScript with drizzle-orm table builders, split into one file per domain and re-exported from a single schema index. Confidence: 0.85
- Generate SQL migrations with drizzle-kit generate, review the SQL by hand and commit it; never use push against production. Confidence: 0.95
- Use drizzle-kit push only on throwaway local or preview databases where losing data is fine. Confidence: 0.80
- Keep drizzle.config.ts small and read the database URL from the environment, never from a committed file. Confidence: 0.90
- Apply migrations in a separate deploy step with the migrator, not on every app boot in every serverless instance. Confidence: 0.85
- Name columns in snake_case in the database and camelCase in TypeScript using the casing option instead of hand-mapping each one. Confidence: 0.75
- Give every table a primary key, created_at and updated_at with database defaults, and use timestamp with time zone. Confidence: 0.85
- Declare foreign keys with references() and an explicit onDelete behavior so the database enforces integrity. Confidence: 0.90
- Add indexes in the table definition for every foreign key and every column you filter or sort on. Confidence: 0.85
- Define relations() for the relational query API and use db.query with "with" for nested reads instead of manual joins. Confidence: 0.75
- Use the SQL-like select builder with explicit joins when you need aggregates, window functions or precise control. Confidence: 0.80
- Select only the columns you need instead of returning whole rows, especially for list endpoints. Confidence: 0.80
- Infer types with $inferSelect and $inferInsert rather than writing duplicate interfaces by hand. Confidence: 0.90
- Generate Zod schemas from tables with drizzle-zod and refine them for API validation. Confidence: 0.75
- Wrap multi-step writes in db.transaction and pass the tx object down instead of the global db. Confidence: 0.90
- Use the sql template tag for raw fragments, which keeps values parameterized; never build SQL with string concatenation. Confidence: 1.00
- Use prepared statements with placeholders for hot queries on long-running servers. Confidence: 0.65
- Use returning() on inserts and updates instead of a second read query. Confidence: 0.80
- Use onConflictDoUpdate for upserts and back it with a real unique index. Confidence: 0.85
- Pick the driver that matches the runtime (node-postgres for servers, the Neon or other HTTP driver for edge and serverless) and keep it in one db module. Confidence: 0.80
- Keep queries in small repository or data-access functions so route handlers never build queries inline. Confidence: 0.70
- Run integration tests against a real Postgres (container or branch database) with migrations applied, not against mocks. Confidence: 0.85
- Seed local data with a typed seed script checked into the repo. Confidence: 0.70
Comments & Questions (0)
No comments yet
Be the first to comment!