jgamaraalv/ts-dev-kit/drizzle-pg

Claude Code and agent skill by jgamaraalv/ts-dev-kit

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Drizzle ORM reference for PostgreSQL — schema definition, typesafe queries, relations, and migrations with drizzle-kit. Use when: (1) defining pgTable schemas with column types, indexes, constraints, or enums, (2) writing select/insert/update/delete queries or joins, (3) defining relations and using the relational query API (db.query.*), (4) running drizzle-kit generate/migrate/push/pull, (5) configuring drizzle.config.ts, (6) using the sql`` template operator, or (7) working with PostGIS/pg_vector extensions.

Install

npx vskill@latest install jgamaraalv/ts-dev-kit/drizzle-pg

SKILL.md

Drizzle ORM — PostgreSQL

Drizzle is a headless TypeScript ORM. Zero dependencies, SQL-like API, single-query output. Packages: drizzle-orm (runtime), drizzle-kit (CLI/migrations).

Table of Contents

<examples>

Quick Start

Connect
typescript
import { drizzle } from "drizzle-orm/node-postgres";
import * as schema from "./schema";
import { relations } from "./relations";
const db = drizzle(process.env.DATABASE_URL, { schema, relations });

Or with existing Pool:

typescript
import { Pool } from "pg";
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const db = drizzle({ client: pool, schema, relations });
Define Schema
typescript
import {
pgTable,
pgEnum,
serial,
text,
integer,
timestamp,
uuid,
jsonb,
index,
uniqueIndex,
} from "drizzle-orm/pg-core";
import { sql } from "drizzle-orm";
export const statusEnum = pgEnum("status", ["active", "inactive", "banned"]);
export const users = pgTable(
"users",
{
id: uuid("id")
.default(sql`gen_random_uuid()`)
.primaryKey(),
name: text("name").notNull(),
email: text("email").notNull().unique(),
status: statusEnum().default("active").notNull(),
metadata: jsonb("metadata").$type<{ roles: string[] }>(),
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
},
(t) => [index("users_email_idx").on(t.email)],
);
export const posts = pgTable("posts", {
id: serial("id").primaryKey(),
title: text("title").notNull(),
authorId: uuid("author_id")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
});
Define Relations
typescript
import { defineRelations } from "drizzle-orm";
import * as schema from "./schema";
export const relations = defineRelations(schema, (r) => ({
users: {
posts: r.many.posts({ from: r.users.id, to: r.posts.authorId }),
},
posts: {
author: r.one.users({ from: r.posts.authorId, to: r.users.id }),
},
}));
CRUD
typescript
import { eq, and, ilike, sql } from "drizzle-orm";
// SELECT
const allUsers = await db.select().from(users);
const user = await db.select().from(users).where(eq(users.id, id));
// INSERT
const [created] = await db
.insert(users)
.values({ name: "Dan", email: "dan@example.com" })
.returning();
// UPDATE
await db.update(users).set({ name: "Updated" }).where(eq(users.id, id));
// DELETE
await db.delete(users).where(eq(users.id, id));
// UPSERT
await db
.insert(users)
.values({ id, name: "Dan", email: "dan@ex.com" })
.onConflictDoUpdate({ target: users.id, set: { name: "Dan" } });
Relational Queries
typescript
// Nested eager loading (single SQL query)
const usersWithPosts = await db.query.users.findMany({
with: { posts: true },
where: { status: "active" },
orderBy: { createdAt: "desc" },
limit: 10,
});
const user = await db.query.users.findFirst({
where: { id: userId },
with: { posts: { columns: { id: true, title: true } } },
});
Migrations
bash
# drizzle.config.ts -> see references/migrations.md
npx drizzle-kit generate # schema diff -> SQL files
npx drizzle-kit migrate # apply SQL to database
npx drizzle-kit push # direct push (no SQL files)
npx drizzle-kit pull # introspect DB -> Drizzle schema
npx drizzle-kit studio # visual browser UI

Common Patterns

Conditional filters
typescript
const filters: SQL[] = [];
if (name) filters.push(ilike(users.name, `%${name}%`));
if (status) filters.push(eq(users.status, status));
await db
.select()
.from(users)
.where(and(...filters));
Transactions
typescript
await db.transaction(async (tx) => {
const [user] = await tx.insert(users).values({ name: "Dan" }).returning();
await tx.insert(posts).values({ title: "Hello", authorId: user.id });
});
Type inference
typescript
type User = typeof users.$inferSelect;
type NewUser = typeof users.$inferInsert;

</examples>

<quick_reference>

Import Cheat Sheet

Import pathKey exports
drizzle-orm/pg-corepgTable, pgEnum, column types (serial, text, integer, uuid, timestamp, jsonb, varchar, boolean, numeric, bigint, geometry, vector, ...), index, uniqueIndex, unique, check, primaryKey, foreignKey
drizzle-ormOperators: eq, ne, gt, gte, lt, lte, and, or, not, isNull, isNotNull, inArray, between, like, ilike, exists, sql, asc, desc. Utilities: getColumns, defineRelations, cosineDistance, l2Distance
drizzle-orm (types)InferSelectModel, InferInsertModel
drizzle-zodcreateInsertSchema, createSelectSchema

</quick_reference>

<references>

Reference Files

For detailed API coverage, see:

</references>

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
12
Repository npm downloads, 7 days
46
7-day trend score
28

Stars and forks are for the whole GitHub repository, not this skill alone. Downloads are for the repository's npm package. Refreshed 17 Mar 2026, 8 months ago.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/jgamaraalv/ts-dev-kit/drizzle-pg/badge)](https://verified-skill.com/skills/jgamaraalv/ts-dev-kit/drizzle-pg)

Something wrong with this skill or its page? Tell us.