Index of every page on this site: llms.txt
All skills
andrelandgraf avatar

/drizzle-queries

@4449331
Run it yourself

Write type-safe Postgres queries with Drizzle ORM (select/insert/update/delete, relations, new tables). Use when querying or mutating the database or adding a Drizzle table.

Use this Skill: https://skilld.dev/gh/andrelandgraf/fullstackrecipes/drizzle-queries

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈48 tokens for metadata: the name and description. ≈605 when used: this file.

Description uses 2.4% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈191 characters, or 2.4%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

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

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts5mo3 checks · Risk SAFE
  • Gen Agent Trust Hub5mo

    This skill provides instructions and code examples for using Drizzle ORM with PostgreSQL. It includes standard database migration commands and links to official documentation. No security issues were detected.

  • Socket5mo

    No alerts

  • Snyk5mo

    Risk: LOW · No issues

Signed by skilld at 4449331. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 3 weeks ago.

Steadyupdated 6 months ago

README badge

README badge for andrelandgraf/fullstackrecipes/drizzle-queries