echonext-database
/echonext-database
Work with EchoNext's database layer: GORM models, the generic Repository[T] pattern from pkg/contrib/database, and Atlas migrations/seeds via the CLI. Use when defining models, querying/persisting data, or creating and applying migrations in an echonext project.
- Author
- abdussamadbello ↗
- Repository
- echonext ↗
- Licence
- MIT
- Last repository change
- 26.10.2026
Assessment and security
- Files in this package
- 1
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 26.10.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Work with EchoNext's database layer: GORM models, the generic Repository[T] pattern from pkg/contrib/database, and Atlas migrations/seeds via the CLI. Use when defining models, querying/persisting data, or creating and applying migrations in an echonext project.
Original author description
Work with EchoNext's database layer: GORM models, the generic Repository[T] pattern from pkg/contrib/database, and Atlas migrations/seeds via the CLI. Use when defining models, querying/persisting data, or creating and applying migrations in an echonext project.
How it works
- Models
- Repository[T]
- Migrations (Atlas via the CLI)
- Seeding
- Checklist
SKILL.md preview
---
name: echonext-database
description: >-
Work with EchoNext's database layer: GORM models, the generic Repository[T]
pattern from pkg/contrib/database, and Atlas migrations/seeds via the CLI. Use
when defining models, querying/persisting data, or creating and applying
migrations in an echonext project.
license: MIT
metadata:
version: 0.1.0
---
# EchoNext Database
EchoNext uses GORM for persistence and Atlas for migrations. The optional
`pkg/contrib/database` package adds a generic, type-safe `Repository[T]` so you
don't rewrite CRUD per model.
## Models
Plain GORM structs (see the `echonext-domain` skill for the conventional layout):
```go
type User struct {
ID uint `gorm:"primaryKey"`
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt gorm.DeletedAt `gorm:"index"`
Email string `gorm:"unique;not null"`
Name string `gorm:"not null"`
}
func (User) TableName() string { return "users" }
```
## Repository[T]
`pkg/contrib/database` provides a generic repository. Construct it with the
model type and a `*gorm.DB`:
```go
import "github.com/abdussamadbello/echonext/pkg/contrib/database"
repo := database.NewRepository[User](db)
```
Core methods (from the `Repository[T]` interface):
```go
repo.Create(&user) // INSERT
user, err := repo.Find(1) // by primary key -> (*User, error)
users, err := repo.FindAll() // -> ([]*User, error)
repo.Update(&user) // UPDATE
repo.Delete(1) // DELETE by id
count, err := repo.Count() // -> (int64, error)
```
Chainable query builders return the repository so you can compose, then call a
terminal method:
```go
// All active users, newest first, page 2 of 20.
recent, err := repo.
Where("active = ?", true).
Order("created_at DESC").
Limit(20).
Offset(20).
FindAll()
// Run inside a transaction:
err := db.Transaction(func(tx *gorm.DB) error {
return repo.WithTx(tx).Create(&user)
})
```
Available builders: `Where(query, args...)`, `Order(value)`, `Limit(n)`,
`Offset(n)`, `WithTx(tx)`; `DB()` returns the underlying `*gorm.DB` for anything
the repository doesn't cover.
> Use `Repository[T]` for generic CRUD. The default `echonext generate domain`
> service holds a raw `*gorm.DB` instead — either is fine; pick one per project
> and stay consistent.
## Migrations (Atlas via the CLI)
```bash
echonext db init # one-time: set up Atlas migration files
echonext db migrate:diff add_users # diff Go models -> a new migration
echonext db migrate # apply pending migrations
echonext db migrate:status # what's applied / pending
echonext db migrate:down # roll back
echonext db migrate:new add_index # hand-write an empty migration
echonext db migrate:lint # check migrations for issues
echonext db schema:inspect # dump the current DB schema
```
Typical loop: edit `model.go` → `db migrate:diff <name>` → review the generated
SQL → `db migrate`.
## Seeding
```bash
echonext db seed # insert sample/seed data
```
For loading fixtures in **tests**, use the contrib testing helpers instead (see
the `echonext-testing` skill), not the seed command.
## Checklist
- Models are GORM structs with a `TableName()`; use pointers/`omitempty` only
where semantics require it.
- Prefer `database.NewRepository[T](db)` for CRUD; drop to `repo.DB()` for
bespoke queries.
- After any model change, run `db migrate:diff <name>` then `db migrate`.
- Review generated migration SQL before applying it.
Versions
The database has no other skills named echonext-database.
Database snapshot: 13.11.2026 · package version 7519dbf70368 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100echonext-testing
Write tests for EchoNext APIs using the pkg/contrib/testing helpers — APIClient for in-process HTTP requests, Suite for setup/teardown, and FixtureManager for seeding test data. Use when writing or fixing tests for echonext handlers, services, or endpoints. - 100echonext-middleware-config
Register, order and write EchoNext middleware, and load application configuration. Use when adding middleware (auth, CORS, logging, request IDs, metrics, tracing) to an echonext app or group, writing a custom echo.MiddlewareFunc, or loading config from YAML/env with the contrib config package. - 100go-database
Database patterns for Go services: database/sql, connection management, transactions, migrations, query builders, and ORM usage (sqlc, GORM, ent). Use when: "database access", "SQL query", "connection pool", "transactions", "database migration", "sqlc", "GORM", "ent", "prepared… - 100grb-postgres-migrations
Use when changing the database schema, the seed, a gorm store or a migration in the Go React boilerplate. Covers embedded golang-migrate files, gorm boundaries, UUID keys, seed idempotency and the relevant commands. - 100go-data-persistence
Data persistence patterns in Go covering raw SQL with sqlx/pgx, ORMs like Ent and GORM, connection pooling, migrations with golang-migrate, and transaction management. Use when implementing database access, designing repositories, or managing schema migrations. - 100uw-analyze-database
Use when analyzing the database layer including schema, migrations, ORM configuration, and data access patterns