D
drizzle
Drizzle ORM schema and database guide. Use when working with database schemas (src/database/schemas/*), defining tables, creating migrations, or database model code. Triggers on Drizzle schema definition, database migrations, or ORM usage questions.
Installation
Pick a client and clone the repository into its skills directory.
Installation
About this skill
Drizzle ORM schema and database guide. Use when working with database schemas (src/database/schemas/*), defining tables, creating migrations, or database model code. Triggers on Drizzle schema definition, database migrations, or ORM usage questions.
How to use
- Zainstaluj skill w swoim projekcie lobehub, wskazując ścieżkę do repozytorium drizzle z gałęzi main.
- Umieść konfigurację Drizzle w pliku drizzle.config.ts na poziomie głównym projektu.
- Organizuj schematy w katalogu src/database/schemas/, korzystając z funkcji pomocniczych z pliku _helpers.ts do znaczników czasu (createdAt, updatedAt, accessedAt).
- Definiuj tabele w PostgreSQL, stosując konwencje: nazwy tabel w liczbie mnogiej i snake_case (np. users, session_groups), kolumny w snake_case (user_id, created_at). Dla kluczy głównych użyj text z prefixem (np. idGenerator('agents')), dla kluczy obcych dodaj references() z akcją onDelete.
- Tworząc indeksy, zwracaj tablicę zamiast obiektu, np. (t) => [uniqueIndex('client_id_user_id_unique').on(t.clientId, t.userId)].
- Wnioskuj typy TypeScript z tabel za pomocą createInsertSchema oraz typeof agents.$inferInsert i typeof agents.$inferSelect, aby uzyskać typy NewAgent i AgentItem.