Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
andrelandgraf avatar

Drizzle Queries

  • 48 installs
  • 18 repo stars
  • Updated June 8, 2026
  • andrelandgraf/fullstackrecipes

drizzle-queries is a Claude Code skill for writing type-safe Postgres queries with Drizzle ORM, covering select, insert, update, delete, relations, and adding new tables.

About

This skill shows how to write type-safe Postgres queries with Drizzle ORM: selecting, inserting, updating, deleting, relational queries, and adding a new table. Developers use it when querying or mutating the database or adding a Drizzle table. It assumes the Neon plus Drizzle setup recipe is already complete and imports db from @/lib/db/client.

  • Type-safe Postgres select/insert/update/delete with Drizzle ORM
  • Relational queries via db.query.<table> instead of manual joins
  • Pattern for co-locating a new Drizzle table and migrating

Drizzle Queries by the numbers

  • 48 all-time installs (skills.sh)
  • Ranked #422 of 911 Databases skills by installs in the Skillselion catalog
  • Data as of Jul 28, 2026 (Skillselion catalog sync)
At a glance

drizzle-queries capabilities & compatibility

Capabilities
database query · schema migration · orm usage
Works with
postgres
Use cases
database · api development
Pricing
Free
From the docs

What drizzle-queries says it does

Write type-safe Postgres queries with Drizzle ORM.
SKILL.md
Use `db.query.<table>` for relations instead of manual joins.
SKILL.md
npx skills add https://github.com/andrelandgraf/fullstackrecipes --skill drizzle-queries

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs48
repo stars18
Last updatedJune 8, 2026
Repositoryandrelandgraf/fullstackrecipes

What it does

Write type-safe Postgres queries with Drizzle ORM and add new tables in a full-stack app.

Who is it for?

Developers querying or mutating a Postgres database or adding a Drizzle table.

Skip if: Initial Neon and Drizzle setup, which the Neon + Drizzle Setup recipe handles.

When should I use this skill?

Querying or mutating the database or adding a Drizzle table.

What you get

  • Drizzle query code
  • New table schema
  • Migration commands

Files

SKILL.mdMarkdownGitHub ↗

Drizzle Queries

Write type-safe Postgres queries with Drizzle ORM.

Prerequisites

Complete these setup recipes first:

  • Neon + Drizzle Setup

Selecting

Import db from @/lib/db/client and operators from drizzle-orm. For a single row, .limit(1) then take rows[0].

import { db } from "@/lib/db/client";
import { chats } from "@/lib/chat/schema";
import { eq, desc } from "drizzle-orm";

const allChats = await db.select().from(chats);

const userChats = await db
  .select()
  .from(chats)
  .where(eq(chats.userId, userId))
  .orderBy(desc(chats.createdAt));

const chat = await db
  .select()
  .from(chats)
  .where(eq(chats.id, chatId))
  .limit(1)
  .then((rows) => rows[0]);

Inserting

Use .returning() when the inserted row is needed back.

const [newChat] = await db
  .insert(chats)
  .values({ userId, title: "New Chat" })
  .returning();

await db.insert(messages).values([
  { chatId, role: "user", content: "Hello" },
  { chatId, role: "assistant", content: "Hi there!" },
]);

Updating

await db
  .update(chats)
  .set({ title: "Updated Title" })
  .where(eq(chats.id, chatId));

Deleting

await db.delete(chats).where(eq(chats.id, chatId));

Relational Queries

Use db.query.<table> for relations instead of manual joins.

const chatWithMessages = await db.query.chats.findFirst({
  where: eq(chats.id, chatId),
  with: {
    messages: {
      orderBy: (messages, { asc }) => [asc(messages.createdAt)],
    },
  },
});

Adding a Table

Co-locate the schema in the feature's library folder, register it on the shared client, then migrate.

// src/lib/feature/schema.ts
import { pgTable, text, uuid, timestamp } from "drizzle-orm/pg-core";

export const items = pgTable("items", {
  id: uuid("id").primaryKey().defaultRandom(),
  name: text("name").notNull(),
  createdAt: timestamp("created_at").defaultNow().notNull(),
});
// src/lib/db/client.ts
import * as itemSchema from "@/lib/feature/schema";

const schema = { ...authSchema, ...chatSchema, ...itemSchema };
bun run db:generate
bun run db:migrate

---

References

Related skills

FAQ

How do I fetch a single row?

Use .limit(1) then take rows[0], for example .limit(1).then((rows) => rows[0]).

How do I load relations?

Use db.query.<table> with a with clause instead of writing manual joins.

Databasesdatabases

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.