023: MySQL / MariaDB
A Piko project using MySQL (or MariaDB) as its database, with type-safe queries generated from .sql files.
What this demonstrates
- The
WithDatabasebootstrap option with the MySQL driver. - The MySQL engine config (
db_engine_mysql.MySQL()) driving the generator's type inference, plus the MySQL migration dialect (db.MySQLDialect()). - Connection-pool tuning through the registration struct.
- Running migrations and seeds at startup via the
wdk/dbservices (db.NewMigrationService(...).Upanddb.NewSeedService(...).Apply), invoked directly inmain()before the server starts.
Project structure
src/
cmd/
main/main.go Bootstrap with WithDatabase("blog", ...).
generator/main.go Per-project generator entry point.
db/
queries/*.sql Annotated SQL files for the querier generator.
migrations/*.sql Schema migrations.
seeds/ Seed data.
generated/ Type-safe querier output.
pages/
index.pk Posts listing.
post.pk Single post with comments.
actions/
posts/
create.go
publish.go
comments/
create.go
How to run this example
From the Piko repository root:
cd examples/scenarios/023_database_mysql/src/
go mod tidy
go run ./cmd/generator/main.go all
air
This example starts a MySQL 8 container automatically via testcontainers, so a running Docker daemon is required; there is no external database to set up by hand.