Skip to content

Database

The scaffold supports three database drivers via GORM.

Supported Drivers

DriverBest ForConfig
SQLiteDevelopment, small projectsZero config, file-based
MySQLProduction, existing MySQL infraRequires running MySQL server
PostgreSQLProduction, advanced featuresRequires running PostgreSQL server

Configuration

In config.yaml:

yaml
database:
    driver: sqlite           # sqlite / mysql / postgres
    dsn: data.db             # Connection string

DSN Examples

SQLite:

yaml
dsn: data.db

MySQL:

yaml
dsn: root:password@tcp(127.0.0.1:3306)/mydb?charset=utf8mb4&parseTime=True&loc=Local

PostgreSQL:

yaml
dsn: host=127.0.0.1 user=postgres password=123456 dbname=mydb port=5432 sslmode=disable

Docker Compose

The generated project includes a docker-compose.yaml with pre-configured services:

bash
# Start MySQL
docker compose up -d mysql

# Start PostgreSQL
docker compose up -d postgres

# Start Redis
docker compose up -d redis

Auto Migration

GORM's AutoMigrate runs at startup, creating tables automatically. Add new models in internal/models/ and register them in db.go.