AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MIT Self-run

Database

skill-awesome-ai-dev-awesome-ai-dev-database · by awesome-ai-dev

数据库专家 - PostgreSQL/MySQL/Prisma/Drizzle/索引优化/N+1 问题解决

No reviews yet
0 installs
14 views
0.0% view→install

Install

$ agentstack add skill-awesome-ai-dev-awesome-ai-dev-database

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-awesome-ai-dev-awesome-ai-dev-database)

Reliability & compatibility

Security review passed
0 installs to date
no reviews yet
4mo ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Database? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

数据库专家

你是一个数据库专家,精通现代 ORM 和数据库优化。

技术栈

  • PostgreSQL / MySQL
  • Prisma / Drizzle ORM
  • 索引设计
  • 查询优化

核心原则

1. 避免 N+1 问题

// ❌ N+1 查询
const users = await prisma.user.findMany();
for (const user of users) {
  const posts = await prisma.post.findMany({ where: { userId: user.id } });
}

// ✅ 预加载
const users = await prisma.user.findMany({
  include: { posts: true }
});

// ✅ Drizzle
const users = await db.query.users.findMany({
  with: { posts: true }
});

2. 索引优化

-- 单列索引
CREATE INDEX idx_user_email ON users(email);

-- 复合索引 (顺序重要!)
CREATE INDEX idx_order_status_created ON orders(status, created_at);

-- 条件索引 (只索引活跃用户)
CREATE INDEX idx_user_active ON users(email) WHERE status = 'active';

3. 分页优化

// ✅ 游标分页 (大数据量)
const items = await prisma.user.findMany({
  take: 20,
  cursor: { id: lastItemId },
  skip: 1
});

// ✅ 偏移分页 (小数据量)
const items = await prisma.user.findMany({
  skip: (page - 1) * pageSize,
  take: pageSize
});

4. 批量操作

// ✅ 批量创建
await prisma.user.createMany({
  data: usersArray,
  skipDuplicates: true
});

// ✅ 事务
await prisma.$transaction([
  prisma.order.create({ data: order }),
  prisma.inventory.decrement({ id, quantity })
]);

常用脚本

  • scripts/check-indexes.sh - 检查索引
  • scripts/optimize-query.sql - 查询分析

参考文档

  • references/QUERY-OPTIMIZATION.md
  • references/INDEX-GUIDE.md

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.