GORM Feature
GORM feature
The gorm feature adds PostgreSQL persistence using the GORM ORM. This is the default ORM β if you donβt specify --use-bun, GORM is added automatically.
What it provides
| File | Purpose |
|---|---|
internal/adapters/persistence/gorm/db.go |
PostgreSQL connection factory via GORM |
internal/adapters/persistence/gorm/migrate.go |
Migration runner using golang-migrate |
internal/adapters/persistence/gorm/user_repository.go |
GORM-backed UserRepository |
migrations/000001_init.up.sql |
Initial database schema |
migrations/000001_init.down.sql |
Initial schema rollback |
Tech stack
| Library | Purpose | Documentation |
|---|---|---|
| GORM v2 | Go ORM with rich feature set | gorm.io/docs |
| GORM PostgreSQL driver | PostgreSQL connectivity | gorm.io/docs |
| golang-migrate | Database migration tool | github.com/golang-migrate/migrate |
| PostgreSQL | Relational database | postgresql.org/docs |
Learning resources
- GORM documentation β gorm.io/docs (associations, hooks, preloading, raw SQL)
- GORM tutorials β gorm.io/docs (getting started, CRUD, querying)
- golang-migrate β github.com/golang-migrate/migrate (migration files, CLI usage)
- PostgreSQL documentation β postgresql.org/docs
Notes
- GORM and Bun are mutually exclusive β a project cannot have both.
- Running
crank make scaffoldwith GORM enabled generates a migration for the new resource (unless--skip-migrationis passed).