database-patterns

database-patterns is a skill for Claude Code, Codex from softspark/ai-toolkit. It costs 55 tokens per session (2,431 once invoked), scanned A, original, Apache-2.0.

A collection of database design and query-tuning patterns for schemas, indexes, transactions, relationships, and query plans. It covers issues such as repeated database queries and deadlocks.

In plain words
What is it for?
Use it when designing schemas, choosing indexes, reviewing ORM usage, investigating slow queries, or examining PostgreSQL and other SQL database behavior.
Why use it?
It helps prevent poorly structured tables and slow or unreliable queries. The guidance makes common database decisions more consistent and easier to inspect.

Skill for Claude CodeCodex

Part of the ai-toolkit plugin — 114 skills, 44 agents, 14 hooks shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/softspark/ai-toolkit/database-patterns
Any agent
npx skills add softspark/ai-toolkit --skill database-patterns
Clone the repo
git clone --depth 1 https://github.com/softspark/ai-toolkit

Made for: Claude Code, Codex.

Or install ai-toolkit, the plugin that ships this one along with the rest of its 114 skills, 44 agents, 14 hooks.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for database-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/softspark/ai-toolkit/database-patterns.svg)](https://agentmods.dev/skills/softspark/ai-toolkit/database-patterns)
Your own site
<a href="https://agentmods.dev/skills/softspark/ai-toolkit/database-patterns"><img src="https://agentmods.dev/badge/skills/softspark/ai-toolkit/database-patterns.svg" alt="Measured on agentmods" height="20"></a>
Per session 55 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,431 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00055 $0.02431
Opus 5 $0.00028 $0.01215
Sonnet 5 $0.00011 $0.00486
Haiku 4.5 $0.00006 $0.00243

Measured yesterday against content hash d33bb553a7b6, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

database-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

app/skills/database-patterns/SKILL.md · 334 lines

How it starts

The opening of the file, as written. The whole thing — 334 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Database Patterns Skill

ORM Selection

Scenario ORM
Node.js, type-safe Prisma
Node.js, SQL-first Drizzle
Python, async SQLAlchemy 2.0
Python, simple SQLModel
PHP Doctrine, Eloquent

Schema Design

Naming Conventions

-- Tables: plural, snake_case
CREATE TABLE user_profiles (...);

-- Columns: snake_case
user_id, created_at, is_active

-- Indexes: idx_{table}_{columns}
CREATE INDEX idx_users_email ON users(email);

-- Foreign keys: fk_{table}_{ref_table}
CONSTRAINT fk_orders_users FOREIGN KEY (user_id) REFERENCES users(id)

Common Patterns

Soft Delete
ALTER TABLE users ADD COLUMN deleted_at TIMESTAMP NULL;

-- Query active records
SELECT * FROM users WHERE deleted_at IS NULL;
Audit Columns
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
created_by UUID REFERENCES users(id),
updated_by UUID REFERENCES users(id)
UUID vs Serial
Use Case Type
Internal only SERIAL/BIGSERIAL
External/distributed UUID
Human readable SERIAL with prefix

Index Strategies

When to Index

  • Foreign keys (always)
  • Columns in WHERE clauses
  • Columns in ORDER BY
  • Columns in JOIN conditions

Index Types

Type Use Case
B-tree Equality, range (default)
Hash Equality only
GIN Arrays, JSONB, full-text
GiST Geometric, full-text
BRIN Large sequential data

Composite Index Order

-- Good: matches query pattern
CREATE INDEX idx_orders_user_date ON orders(user_id, created_at);
SELECT * FROM orders WHERE user_id = 1 AND created_at > '2024-01-01';

-- Index used for:
-- WHERE user_id = 1
-- WHERE user_id = 1 AND created_at > ...

-- Index NOT used for:
-- WHERE created_at > '2024-01-01' (missing leading column)

Query Optimization

Explain Analyze

EXPLAIN ANALYZE
SELECT * FROM users WHERE email = '[email protected]';

Read the full file on GitHub · 334 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 334 lines · 55 tokens per session scan A d33bb553a7b6

Subscribe to this mod's changes

database-patterns is a skill published in the GitHub repository softspark/ai-toolkit (168 stars, last pushed yesterday), licensed Apache-2.0. It adds 55 tokens to every session and 2,431 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.

Related

Other skills, from other repositories

postgres

Configure DigitalOcean Managed Postgres with bindable variables or schema isolation. Use when setting up databases, creating users, managing permissions, configuring multi-tenant schemas, or troubleshooting database connectivity on App Platform.

digitalocean-labs/do-app-platform-skills · 42 tokens

pg-migration

PostgreSQL schema migration safety reviewer and DDL generator. ALWAYS use when writing, reviewing, or planning PostgreSQL schema changes — ALTER TABLE, CREATE/DROP INDEX, column type changes, constraint additions, RLS policy changes, or any DDL touching production tables. Covers lock-level analysis, CREATE INDEX…

johnqtcg/awesome-skills · 135 tokens

postgres

PostgreSQL mastery -- advanced features, replication, partitioning, tuning, connection pooling.

arbazkhan971/godmode · 20 tokens

query

Query optimization and EXPLAIN analysis.

arbazkhan971/godmode · 10 tokens

postgres-expert

Administration et optimisation PostgreSQL — diagnostic de performance, indexation, partitioning, tuning mémoire, VACUUM, backup/restore, JSONB, réplication. Se déclenche avec "PostgreSQL", "Postgres", "pgstat", "JSONB", "partitioning", "VACUUM", "pgdump. Also triggers on "PostgreSQL performance", "Postgres index"…

khalilbenaz/claude-skills-collection · 98 tokens

sap-cap-capire

SAP Cloud Application Programming Model (CAP) development skill using Capire documentation. Use when: building CAP applications, defining CDS models, implementing services, working with SAP HANA/SQLite/PostgreSQL databases, deploying to SAP BTP Cloud Foundry or Kyma, implementing Fiori UIs, handling authorization…

secondsky/sap-skills · 103 tokens