sqlite
Skill1 starsChanged 4 months agoMITView on GitHub
SQLite-specific database expertise — dynamic typing and column affinity (and `STRICT` tables), the absence of native boolean/date types and what to store instead, foreign keys being off by default per connection, the single-writer concurrency model with WAL mode and `busy_timeout`, `BEGIN IMMEDIATE` for write transactions to avoid upgrade deadlocks, `EXPLAIN QUERY PLAN`-driven index design, the limited `ALTER TABLE`, and safe backup/deployment of a file-backed database. Use when `package.json` lists `better-sqlite3`, `sqlite3`, `node:sqlite`, `@libsql/client`, or `expo-sqlite`, when an ORM's dialect/provider is `sqlite` (Prisma `provider = "sqlite"`, Drizzle `better-sqlite3`/`libsql`, TypeORM `type: 'sqlite'`), when a `.db`/`.sqlite`/`.sqlite3` file or a `file:` connection string is in the repo, or when asked directly (Thai or English) to เขียนหรือตรวจ schema/query SQLite ให้ถูกต้อง. Not a replacement for database-schema-dev's engine-agnostic migration workflow or backend-dev's access-layer code — this is the SQLite-specific expertise both draw on, and it also underlies `skills/turso/SKILL.md`.
In this repository20 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- agent-flowSkill
- dev-testingSkill
- dry-and-corSkill
- electronSkill
- firebaseSkill
- flutterSkill
- google-authSkill
- html-cssSkill
- mysqlSkill
- nodejsSkill
- postgresSkill
- reactSkill
- stack-briefingSkill
- supabaseSkill
- tailwindSkill
- tursoSkill
- typescriptSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
18 rules. About 0 are common, 4 are distinctive, and 14 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
14
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 17
Check package.json for better-sqlite3, sqlite3, node:sqlite, @libsql/client, expo-sqlite, or drizzle-orm with a SQLite driver.
- Very specific: line 30
Use STRICT tables (SQLite 3.37+) on anything new — CREATE TABLE t (…) STRICT enforces the declared type per row and turns a whole class of …
- Very specific: line 42
Only INTEGER PRIMARY KEY aliases the internal rowid.
- Distinctive: line 50
Every pooled connection needs it.
- Very specific: line 67
Use BEGIN IMMEDIATE for any transaction that will write.
- Distinctive: line 75
Never put a SQLite file on NFS or another network filesystem — its locking is not reliable there.
- Very specific: line 93
Run ANALYZE after a substantial data load so the planner has statistics.
- Very specific: line 95
Use FTS5 for text search rather than LIKE '%term%', which cannot use an index at all.
- Very specific: line 120
Never copy a live database file with cp/rsync — a concurrent write produces a corrupt copy, and in WAL mode the -wal file holds committed …
- Very specific: line 149
Don't assume declared types are enforced — use STRICT, and add CHECK constraints where it isn't available.
- Distinctive: line 151
Don't store dates or booleans as their "natural" type.
- Very specific: line 152
Don't rely on REFERENCES without PRAGMA foreign_keys = ON per connection.
- Very specific: line 154
Don't leave write transactions as BEGIN DEFERRED, and don't run without WAL and a busy_timeout in a concurrent app.
- Very specific: line 156
Don't call a query fast without EXPLAIN QUERY PLAN, and don't leave an automatic covering index in a plan unfixed.
- Very specific: line 158
Don't attempt ALTER COLUMN/ADD CONSTRAINT — recreate the table.
- Very specific: line 159
Don't cp a live database or ignore the -wal/-shm files.
- Distinctive: line 160
Don't run SQLite off a network filesystem, or across multiple app instances writing the same file.
- Very specific: line 162
Don't write the engine-agnostic migration or access-layer code here — that's database-schema-dev/backend-dev.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
SQLite
database-schema-dev's and backend-dev's SQLite-specific expertise layer,
the same way skills/mysql/SKILL.md is for MySQL. SQLite is an embedded
library writing to a single file, not a server — most of what follows comes
from that one difference. If the project is Turso/libSQL, everything here
still applies to the schema and queries; the connection, replication, and
transaction-shape rules on top of it are skills/turso/SKILL.md.
Step 1 — Confirm the engine is actually SQLite
Check package.json for better-sqlite3, sqlite3, node:sqlite,
@libsql/client, expo-sqlite, or drizzle-orm with a SQLite driver; an
ORM provider/dialect set to sqlite; a committed or gitignored
.db/.sqlite file; or a file:/libsql: connection string. If the
engine is MySQL or Postgres, use skills/mysql/SKILL.md or
skills/postgres/SKILL.md instead — the type systems and concurrency models
are genuinely different, and SQLite habits port badly.
Step 2 — Dynamic typing, affinity, and STRICT
- SQLite does not enforce declared types by default. A
VARCHAR(10)column happily stores a 500-character string and an integer; the declared type only sets a type affinity that guides conversion. - Use
STRICTtables (SQLite 3.37+) on anything new —CREATE TABLE t (…) STRICTenforces the declared type per row and turns a whole class of silent data corruption into an error. Confirm the shipped library version supports it first. - There is no
BOOLEAN: storeINTEGER0/1. Add aCHECK (flag IN (0,1))so a stray2can't appear. - There is no date/time type. Pick one representation per project and stay
with it — ISO-8601 UTC
TEXT('2026-07-29T10:00:00Z', sorts and compares lexicographically) or anINTEGERUnix epoch. Mixed representations across tables is a recurring source of wrong comparisons. REALfor money is wrong here for the same reason as everywhere else — store minor units asINTEGER(cents), since SQLite has noDECIMAL.- Only
INTEGER PRIMARY KEYaliases the internal rowid;INT PRIMARY KEYdoes not, and creates a second index.AUTOINCREMENTis rarely needed — it only prevents rowid reuse, at the cost of an extra table and writes.
Step 3 — Foreign keys are off by default
PRAGMA foreign_keys = ONmust be issued per connection, before anything else — it is not a schema property, and it does not persist. Every pooled connection needs it. Most ORMs have a setting or an after-connect hook for this; confirm it's actually set rather than assuming.- Without it,
REFERENCESclauses are inert documentation and orphan rows accumulate silently. ON DELETE CASCADE/SET NULLlikewise do nothing until the pragma is on.
Step 4 — Concurrency: one writer at a time
- SQLite allows many concurrent readers but exactly one writer per database file. That's the model, not a tuning problem to solve.
- Enable WAL mode (
PRAGMA journal_mode = WAL, persistent per database) so readers don't block the writer and vice versa. It's the single biggest practical win for a web workload. - Set
PRAGMA busy_timeout = 5000(or the value the app can tolerate) per connection — without it, a concurrent write returnsSQLITE_BUSYimmediately instead of waiting. - Use
BEGIN IMMEDIATEfor any transaction that will write. A default deferred transaction takes a read lock first and must upgrade on the first write, which fails withSQLITE_BUSYunder contention and cannot be retried safely mid-transaction. PRAGMA synchronous = NORMALis the usual pairing with WAL (durable against process crashes, a small risk window on power loss);synchronous = OFFtrades real durability and shouldn't be chosen silently.- Never put a SQLite file on NFS or another network filesystem — its locking is not reliable there. That constraint is also why a multi-instance deployment usually needs a client/server database or Turso instead.
Step 5 — Query planning and indexes
EXPLAIN QUERY PLAN <query>is the check.SCAN tmeans a full scan;SEARCH t USING INDEX …means an index was used.USING TEMP B-TREE FOR ORDER BYmeans the sort isn't served by an index — usually fixed by an index matching theORDER BY.- Composite index rules match other engines: equality columns first, the range/sort column last, and the leftmost prefix serves shorter lookups, so don't add a redundant single-column index alongside.
SEARCH … USING AUTOMATIC COVERING INDEXin a plan means SQLite built a throwaway index at runtime because a real one was missing — that's a standing signal to add the index.- Index foreign key columns explicitly; SQLite does not create them for you, and an unindexed FK makes cascading deletes and joins scan.
- Run
ANALYZEafter a substantial data load so the planner has statistics; without it the plan can be chosen on guesses. - Use FTS5 for text search rather than
LIKE '%term%', which cannot use an index at all.
Step 6 — Schema changes and SQL dialect gaps
ALTER TABLEsupports onlyRENAME TABLE,RENAME COLUMN,ADD COLUMN, andDROP COLUMN(3.35+). There is noALTER COLUMNand noADD CONSTRAINT— changing a type or a constraint means the documented 12-step recreate: new table, copy, drop, rename, all inside a transaction with foreign keys temporarily off.ADD COLUMN … NOT NULLrequires a non-null default; adding one with a non-constant default is rejected.- No
RIGHT/FULL OUTER JOINbefore 3.39, no stored procedures, andTRUNCATEdoesn't exist (DELETE FROM tis the equivalent). LIKEis case-insensitive for ASCII only, and there is no built-inUPPER/LOWERfor non-ASCII — a_ci-style comparison over non-English text needsCOLLATE NOCASE(still ASCII-only) or normalization in the application.- Integer division truncates (
3/2is1) — cast when a fraction is meant. UPSERT(ON CONFLICT … DO UPDATE) andRETURNING(3.35+) exist and are usually better than a read-then-write round trip; check the pinned version.
Step 7 — Backups, files, and deployment
- Never copy a live database file with
cp/rsync— a concurrent write produces a corrupt copy, and in WAL mode the-walfile holds committed data the main file doesn't. UseVACUUM INTO 'backup.db'or the driver's online backup API. - The
-waland-shmsidecar files are part of the database. Move or delete them together with it, and don't commit any of them to git. - A database file on a container's ephemeral filesystem is deleted on every
redeploy — it needs a mounted volume, and it still doesn't survive
horizontal scaling. Say this out loud rather than letting it be
discovered in production; the fix (a persistent volume, or a hosted libSQL
target) is
devops-dev's lane. VACUUMrebuilds and compacts the file but takes a full lock and needs free space equal to the database size — schedule it, don't run it inline in a request.
Step 8 — Self-check before reporting done
Confirm foreign_keys is enabled on every connection the app opens, WAL and
a busy_timeout are set, and every writing transaction uses
BEGIN IMMEDIATE. Confirm new tables are STRICT where the version allows,
booleans are INTEGER with a CHECK, timestamps use the project's single
representation, and money is stored in minor units. Confirm each new index
is backed by a query pattern with EXPLAIN QUERY PLAN showing it used, and
that no plan reports an automatic covering index. Confirm any schema change
beyond ADD COLUMN is written as a full table recreate inside a
transaction, and that the deployment target actually persists the file.
What not to do
- Don't assume declared types are enforced — use
STRICT, and addCHECKconstraints where it isn't available. - Don't store dates or booleans as their "natural" type; SQLite has neither.
- Don't rely on
REFERENCESwithoutPRAGMA foreign_keys = ONper connection. - Don't leave write transactions as
BEGIN DEFERRED, and don't run without WAL and abusy_timeoutin a concurrent app. - Don't call a query fast without
EXPLAIN QUERY PLAN, and don't leave an automatic covering index in a plan unfixed. - Don't attempt
ALTER COLUMN/ADD CONSTRAINT— recreate the table. - Don't
cpa live database or ignore the-wal/-shmfiles. - Don't run SQLite off a network filesystem, or across multiple app instances writing the same file.
- Don't write the engine-agnostic migration or access-layer code here —
that's
database-schema-dev/backend-dev.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

