sqlite-expert
它能做什么
这个技能指导将 SQLite 用作嵌入式单文件数据库,包括性能设置、事务和全文搜索。适合构建小型应用、移动应用、设备或本地缓存的开发者。
适用场景
- ✓当你在构建一个把数据存放在单个 SQLite 文件中的小型应用或设备时。
- ✓当 SQLite 报出忙碌错误,需要更好的并发访问设置时。
- ✓当你需要在 SQLite 数据库中进行全文搜索时。
技能链接
https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/sqlite-expert/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请为我的小型笔记应用设置 SQLite,使读写能够顺畅协作,并支持搜索笔记标题和正文。”
每周 5 个新技能,1 分钟读完。
工作原理
该技能推荐预写日志(WAL)、忙碌超时、简短明确的事务、合理的索引,以及使用 FTS5 扩展进行全文搜索。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
SQLite Expert
A database specialist with deep expertise in SQLite internals, performance tuning, and embedded database patterns. This skill provides guidance for using SQLite effectively in applications ranging from mobile apps and IoT devices to server-side caching layers and analytical workloads, leveraging its advanced features well beyond simple key-value storage.
Key Principles
- Enable WAL mode (PRAGMA journal_mode=WAL) for concurrent read/write access; it allows readers to proceed without blocking writers and vice versa
- Use PRAGMA busy_timeout to set a reasonable wait duration (e.g., 5000ms) instead of receiving SQLITE_BUSY errors immediately on contention
- Design schemas with appropriate indexes from the start; SQLite's query planner relies heavily on index availability for efficient execution plans
- Keep transactions short and explicit; wrap related writes in BEGIN/COMMIT to ensure atomicity and reduce fsync overhead
- Understand that SQLite is serverless and single-file; its strength is simplicity and reliability, not high-concurrency multi-writer workloads
Techniques
- Set performance PRAGMAs at connection open: journal_mode=WAL, synchronous=NORMAL, cache_size=-64000 (64MB), mmap_size=268435456, temp_store=MEMORY
- Use FTS5 for full-text search: CREATE VIRTUAL TABLE docs USING fts5(title, body) with MATCH queries and bm25() ranking
- Query JSON data with the JSON1 extension: json_extract(), json_each(), json_group_array() for document-style data stored in TEXT columns
- Write recursive CTEs (WITH RECURSIVE) for tree traversal, graph walking, and generating series of values
- Use window functions (ROW_NUMBER, LAG, LEAD, SUM OVER) for running totals, rankings, and time-series analysis without self-joins
- Create covering indexes that include all columns needed by a query to enable index-only scans (verified with EXPLAIN QUERY PLAN showing COVERING INDEX)
- Implement UPSERT with INSERT ... ON CONFLICT (column) DO UPDATE SET for atomic insert-or-update operations
Common Patterns
- Multi-database Access: Use ATTACH DATABASE to query across multiple SQLite files in a single connection, joining tables from different databases
- Application-defined Functions: Register custom scalar or aggregate functions in your host language for domain-specific computations inside SQL queries
- Incremental Vacuum: Use PRAGMA auto_vacuum=INCREMENTAL with periodic PRAGMA incremental_vacuum to reclaim space without a full VACUUM lock
- Schema Migration: Use PRAGMA user_version to track schema version and apply migration scripts sequentially on application startup
Pitfalls to Avoid
- Do not open multiple connections with different PRAGMA settings; WAL mode and other PRAGMAs should be set consistently on every connection
- Do not use SQLite for high-concurrency write workloads with dozens of simultaneous writers; consider PostgreSQL or another client-server database instead
- Do not store large BLOBs (over 1MB) inline; SQLite performs better when large objects are stored as external files with paths referenced in the database
- Do not skip EXPLAIN QUERY PLAN during development; without it, slow full-table scans go unnoticed until production load reveals them
常见问题
什么是 WAL 模式?
它是一种日志模式,使写入者工作时读取者仍能继续读取,有助于并发访问。
SQLite 适合大量写入者同时工作吗?
该技能说明,SQLite 最擅长简单、可靠的单文件存储,而不是高并发的多写入者工作负载。
忙碌超时有什么作用?
当另一个写入正在进行时,它会让 SQLite 等待设定的时间获取锁,而不是立即失败。
详情
作者的原始描述
SQLite expert for WAL mode, query optimization, embedded patterns, and advanced features
repo: RightNow-AI/openfang
热度
- GitHub 星标
- 18k
- 排名
- #10714
- 许可证
- Apache-2.0
- 更新时间
- 2026/7/2
评论
- …
同一仓库的更多技能
browser-automation
18k教你的智能体使用 Playwright 控制网页浏览器,借助 CSS 选择器找到按钮、表单和链接。
clip-hand-skill
18k帮你的智能体制作视频片段:下载视频、转录语音、生成字幕文件,并用 ffmpeg 剪辑片段。
collector-hand-skill
18k帮你的智能体收集某个主题或公司的公开信息,提取关键实体,跟踪变化并判断舆论倾向。
infisical-sync-skill
18k帮你的智能体通过 API 读取和更新 Infisical 保险库中的密钥,包含登录步骤和清晰的错误处理。