022: SQLite database

A Piko project using SQLite as its database, with type-safe queries generated from .sql files by the project's scaffolded generator.

What this demonstrates

  • The WithDatabase bootstrap option with the SQLite driver.
  • Type-safe query functions generated from db/queries/*.sql at build time.
  • Migrations run on startup via a MigrationService (db.NewMigrationService(...).Up) invoked in main() before the server starts.
  • Action code calling the generated querier.

Project structure

src/
  cmd/
    main/main.go        Bootstrap with WithDatabase("tasks", ...).
    generator/main.go   Per-project generator entry point.
  db/
    queries/*.sql       SQL files annotated for the querier generator.
    migrations/         Schema migrations.
    generated/          Type-safe querier output (regenerated at build).
  pages/
    index.pk            Task list page.
  actions/
    tasks/
      create.go         Uses the generated querier.
      delete.go
      toggle.go

How to run this example

From the Piko repository root:

cd examples/scenarios/022_database_sqlite/src/
go mod tidy
go run ./cmd/generator/main.go all
air

See also