lobehub avatar

Drizzle

This is a strict Drizzle ORM style guide for a Postgres project, specifically LobeHub's conventions. It enforces the query builder API over the relational API because those `with:` joins generate fragile lateral queries that are hard to debug. You get concrete patterns for schema authoring: how to name tables and columns, spread timestamps, set up foreign keys with cascade deletes, and build junction tables. The guide is opinionated about splitting one-to-many fetches into two separate queries instead of using `db.query.findMany` with nested relations. If you're on a team that's had production issues with auto-generated joins or needs everyone writing queries the same way, this codifies those decisions.

skills.sh installs
1.4K
GitHub stars
79.8K
last updated
Jul 14, 2026

Install

$ npx -y skills add lobehub/lobe-chat --skill drizzle --agent claude-code

Installs into .claude/skills of the current project.

Files

Drizzle ORM Schema Style Guide

Adding a Model or Repository? Ship a sibling test in the same PR — every new file under packages/database/src/models/** or src/repositories/** needs a matching __tests__/<name>.test.ts. See the testing skill (.agents/skills/testing/references/db-model-test.md) for the getTestDB() integration pattern, user-isolation tests, the BM25 describe.skipIf(!isServerDB) guard, and schema gotchas. CI's coverage patch gate won't reliably catch a brand-new untested file, so this is on you.

Configuration

  • Config: drizzle.config.ts
  • Schemas: packages/database/src/schemas/
  • Migrations: packages/database/migrations/
  • Dialect: postgresql with strict: true

Helper Functions

Location: packages/database/src/schemas/_helpers.ts

  • timestamptz(name): Timestamp with timezone
  • createdAt(), updatedAt(), accessedAt(): Standard timestamp columns
  • timestamps: Object with all three for easy spread

Naming Conventions

Sponsors

Details

Repository
github.com/lobehub/lobe-chat
Categories
Backend & APIs, Databases
First seen
May 16, 2026

More from lobehub/lobe-chat

All 16
1mindrally avatarnextjs-typescript-tailwindcss-supabasemindrally/skillsFull-stack Next.js 14 development with TypeScript, TailwindCSS, and Supabase for building production-ready web applications.1.4Kskills.sh installs
2aradotso avatartavily-key-generator-proxyaradotso/trending-skillstavily key generator proxy1.3Kskills.sh installs
3sickn33 avatarbackend-architectsickn33/antigravity-awesome-skillsbackend architect1.3Kskills.sh installs
4sickn33 avatarfirebasesickn33/antigravity-awesome-skillsfirebase1.3Kskills.sh installs
5ruvnet avataragent-authenticationruvnet/rufloAgent skill for authentication - invoke with $agent-authentication1.1Kskills.sh installs
6sickn33 avatarapi-patternssickn33/antigravity-awesome-skillsapi patterns1.1Kskills.sh installs