database

database is a skill for Claude Code, Codex from xiaobei930/cc-best. It costs 25 tokens per session (1,660 once invoked), scanned A, original, MIT.

A reusable guide for designing databases, writing queries, improving query speed, managing schema changes, and adding indexes. It includes general conventions and database-specific guidance for systems such as PostgreSQL, MySQL, Oracle, and SQLite.

In plain words
What is it for?
Use it when creating database schemas, choosing relationships, writing queries, planning migrations, or deciding which columns to index.
Why use it?
It helps avoid inconsistent table designs, weak relationships, and queries that become slow as data grows.

Skill for Claude CodeCodex

Part of the cc-best plugin — 19 skills, 44 commands, 8 agents, 20 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/xiaobei930/cc-best/database
Any agent
npx skills add xiaobei930/cc-best --skill database
Clone the repo
git clone --depth 1 https://github.com/xiaobei930/cc-best

Made for: Claude Code, Codex.

Or install cc-best, the plugin that ships this one along with the rest of its 19 skills, 44 commands, 8 agents, 20 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

README.md
[![agentmods](https://agentmods.dev/badge/skills/xiaobei930/cc-best/database.svg)](https://agentmods.dev/skills/xiaobei930/cc-best/database)
Your own site
<a href="https://agentmods.dev/skills/xiaobei930/cc-best/database"><img src="https://agentmods.dev/badge/skills/xiaobei930/cc-best/database.svg" alt="Measured on agentmods" height="20"></a>
Per session 25 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,660 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.00025 $0.01660
Opus 5 $0.00013 $0.00830
Sonnet 5 $0.00005 $0.00332
Haiku 4.5 $0.00003 $0.00166

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

Security

Grade A, and why

database 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.

skills/database/SKILL.md · 215 lines

How it starts

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

数据库模式技能

关联 Agent: architect — 架构设计时加载数据库约束上下文

本技能提供数据库设计和操作的最佳实践,支持多数据库按需加载。

触发条件

  • 设计数据库 Schema
  • 编写数据库查询
  • 优化查询性能
  • 管理数据库迁移
  • 配置索引

数据库专属模式

根据项目技术栈,加载对应的数据库专属文件:

数据库 加载文件 适用场景
PostgreSQL postgres.md 企业应用、复杂查询
MySQL mysql.md Web 应用、读多写少
Oracle oracle.md 大型企业、高并发 OLTP
SQLite sqlite.md 嵌入式、移动端、本地化

检测方式: 根据连接字符串、ORM 配置或项目依赖确定数据库类型。


通用 Schema 设计

命名规范

-- 表名:小写下划线,复数形式
users, order_items, user_preferences

-- 列名:小写下划线
created_at, updated_at, user_id, is_active

-- 索引名:idx_表名_列名
idx_users_email, idx_orders_user_id_created_at

-- 外键名:fk_表名_关联表
fk_orders_users

必备字段

CREATE TABLE users (
    id BIGINT PRIMARY KEY,           -- 主键
    -- 业务字段...
    created_at TIMESTAMP NOT NULL,   -- 创建时间
    updated_at TIMESTAMP NOT NULL,   -- 更新时间
    deleted_at TIMESTAMP             -- 软删除
);

关系设计

关系类型 设计方式 示例
一对多 子表添加外键 orders.user_id → users
多对多 中间表 + 联合主键 user_roles(user_id, role_id)
一对一 子表主键 = 外键 user_settings.user_id

通用索引策略

何时创建索引

  • ✅ WHERE 条件频繁使用的列
  • ✅ JOIN 关联的列
  • ✅ ORDER BY / GROUP BY 的列
  • ❌ 很少查询的列
  • ❌ 值重复率高的列(如性别)
  • ❌ 频繁更新的列

索引类型选择

查询模式 推荐索引
WHERE col = value B-tree
WHERE col > value B-tree
全文搜索 全文索引
JSON 字段查询 GIN/JSON 索引
时序数据范围查询 BRIN(PG)

复合索引原则

-- 规则:等值列在前,范围列在后
-- 查询:WHERE status = 'active' AND created_at > '2024-01-01'

-- ✅ 正确顺序
CREATE INDEX idx_orders_status_created ON orders(status, created_at);

-- ❌ 错误顺序(范围列在前会导致后续列无法使用索引)
CREATE INDEX idx_orders_created_status ON orders(created_at, status);

N+1 问题

问题示例

获取 100 个用户及其订单:
1 次查询获取用户 + 100 次查询获取每个用户的订单 = 101 次查询

Read the full file on GitHub · 215 lines

Files

What ships with it

4 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

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 · 215 lines · 25 tokens per session scan A a871a6e7be53

Subscribe to this mod's changes

database is a skill published in the GitHub repository xiaobei930/cc-best (50 stars, last pushed 2mo ago), licensed MIT. It adds 25 tokens to every session and 1,660 once invoked, about $0.0001 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

optimize

Analyze and suggest performance improvements for code, queries, or systems.

FlorianBruniaux/claude-code-ultimate-guide · 15 tokens

db

Database operations via CLI. Replaces Postgres/SurrealDB MCP (saves 3,000-8,000 tokens). Supports PostgreSQL, SurrealDB, SQLite.

Supersynergy/awesome-agentic-coding · 39 tokens

moai-platform-database-cloud

Cloud database platform specialist covering Neon (serverless PostgreSQL), Supabase (PostgreSQL 16 with real-time), and Firebase Firestore (NoSQL with offline sync). Use when choosing or setting up cloud databases.

modu-ai/moai-adk · 51 tokens

design-patterns

Detect, suggest, and evaluate GoF design patterns in TypeScript/JavaScript codebases. Use when refactoring code, applying singleton/factory/observer/strategy patterns, reviewing pattern quality, or finding stack-native alternatives for React, Angular, NestJS, and Vue.

FlorianBruniaux/claude-code-ultimate-guide · 59 tokens

eval-hooks

Audit Claude Code hooks defined in settings.json files for validity, performance safety, and correctness. Resolves each command against the filesystem, checks exit-code strategy for blocking hooks, flags missing timeouts, and reviews interactive vs async patterns. Use when setting up hooks for the first time…

FlorianBruniaux/claude-code-ultimate-guide · 78 tokens

source-command-audit-whitepapers

Audit version freshness, FR/EN parity, and metadata quality of all whitepapers and recap cards.

FlorianBruniaux/claude-code-ultimate-guide · 26 tokens