node-sqlite-patterns
Database patterns for better-sqlite3 with WAL mode. Query optimization, schema design, and migration patterns for the tracker's SQLite layer.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Database patterns for better-sqlite3 with WAL mode. Query optimization, schema design, and migration patterns for the tracker's SQLite layer.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
Use for any question about a codebase, its architecture, file relationships, or project content — especially when graphify-out/ exists, where the question should be treated as a graphify query first. Turns any input (code, docs, papers, images, videos) into a persistent knowledge graph with god nodes, community detection, and query/path/explain tools.
Guide for developing new MCP tools. Use when adding tools to mcp-server.ts or via space plugin mcpTools arrays. Covers Zod validation, actor handling, and test patterns.
Safety guidelines for modifying orchestrator code. Use when touching state transitions, SSE handling, session lifecycle, circuit breaker, safe restart, or dispatch logic in orchestrator.ts.
Research-before-coding workflow. Search for existing patterns, helpers, and implementations in the tracker codebase before writing new code.
Use when adding authentication, handling user input, working with secrets, creating API endpoints, or modifying security-sensitive code. General security checklist.
Guide for developing new space plugins. Use when creating a new space type or extending an existing one. Covers the SpacePlugin interface, parsers, API routes, MCP tools, and UI renderers.
| name | node-sqlite-patterns |
| description | Database patterns for better-sqlite3 with WAL mode. Query optimization, schema design, and migration patterns for the tracker's SQLite layer. |
| origin | ECC-adapted (postgres-patterns → sqlite) |
src/db.tsThe tracker uses better-sqlite3 in WAL mode for concurrent read access.
// GOOD: Parameterized query
const item = db.prepare('SELECT * FROM tracker_items WHERE id = ?').get(id);
// GOOD: Named parameters
const items = db.prepare(
'SELECT * FROM tracker_items WHERE project_id = @projectId AND state = @state'
).all({ projectId, state });
// BAD: String interpolation (SQL injection risk)
const item = db.prepare(`SELECT * FROM tracker_items WHERE id = '${id}'`).get();
const insertMany = db.transaction((items: Item[]) => {
const stmt = db.prepare('INSERT INTO tracker_items (id, title) VALUES (?, ?)');
for (const item of items) {
stmt.run(item.id, item.title);
}
});
insertMany(items); // Atomic — all or nothing
Follow the existing migration pattern in db.ts:
// Migrations run in order, tracked by version number
// Each migration is idempotent (uses IF NOT EXISTS, etc.)
// Never modify existing migrations — add new ones
CREATE INDEX ... WHERE state = 'approved'// BAD: N+1
const items = db.prepare('SELECT * FROM tracker_items').all();
for (const item of items) {
item.comments = db.prepare('SELECT * FROM tracker_comments WHERE item_id = ?').all(item.id);
}
// GOOD: Single query with JOIN or batch
const items = db.prepare(`
SELECT i.*, GROUP_CONCAT(c.body, '|||') as comment_bodies
FROM tracker_items i
LEFT JOIN tracker_comments c ON c.item_id = i.id
GROUP BY i.id
`).all();
// Store JSON in TEXT columns, parse in application layer
db.prepare('UPDATE tracker_items SET space_data = ? WHERE id = ?')
.run(JSON.stringify(spaceData), id);
// Query JSON fields with json_extract (SQLite 3.38+)
db.prepare("SELECT * FROM tracker_items WHERE json_extract(space_data, '$.status.last_run') IS NOT NULL")
.all();