
Testing
Test Against SQLite in Memory in Go and Its Limits
Use SQLite in memory for fast Go database tests: a private database per test, one connection, foreign keys switched on, and where it differs from PostgreSQL.
8 min read
Tag
4 articles

Use SQLite in memory for fast Go database tests: a private database per test, one connection, foreign keys switched on, and where it differs from PostgreSQL.

Build a bookmark API in Go on pure-Go SQLite with tags, URL normalisation, FTS5 search, one in-memory database per test and a suite that runs under -race.

Use modernc.org/sqlite in Go: set pragmas in the DSN, switch to WAL with a busy timeout, and see eight writers hit SQLITE_BUSY by default and none after.

Choose between mattn/go-sqlite3, which needs cgo, and modernc.org/sqlite, which does not: build sizes, cross compiling, 100000 inserts and the cgo stub error.