← SQLite with Go

SQLITE GO TUTORIAL · DATABASE/SQL · 5 LESSONS

SQLite project: a tested notes repository

Migrations with user_version, FTS5 search, backups and maintenance, tests with temporary databases, and a complete notes repository.

  1. Migrate a schema with PRAGMA user_version: ordered steps, one transaction each

    Apply append-only migrations that record their version in PRAGMA user_version inside the same transaction, skip applied steps, roll back a failing step and refuse a newer schema.

    4 min · Worked lesson

  2. Full-text search with FTS5: an external-content index, ranking and safe queries

    Index a table with an external-content FTS5 table kept in sync by triggers, query it with prefixes, phrases, operators and column filters, rank with bm25, and quote user input.

    4 min · Worked lesson

  3. Back up and maintain a live database: VACUUM INTO, checkpoints, VACUUM and ANALYZE

    Take a consistent backup of a WAL database with VACUUM INTO, verify the copy, reclaim free pages, truncate the WAL with a checkpoint and keep planner statistics current.

    4 min · Worked lesson

  4. Test against real SQLite: a fresh migrated database file per test

    Write a test helper that opens a migrated file database in t.TempDir, registers cleanup, and lets table-driven and parallel tests run against isolated databases.

    4 min · Worked lesson

  5. Project: a tested notes repository with migrations, transactions and full-text search

    Build a small notes store on SQLite that migrates itself, writes in IMMEDIATE transactions with RETURNING and optimistic versions, cascades tags, and searches with FTS5, with a check for every behaviour.

    5 min · Worked lesson