Skip to content

ss-keel-gorm

ss-keel-gorm provides a generic Repository[T, ID] implementation backed by GORM. Supports PostgreSQL, MySQL, and SQLite with zero boilerplate for standard CRUD operations.

Implements: Repository[T, ID]

Terminal window
go get github.com/slice-soft/ss-keel-gorm
import "github.com/slice-soft/ss-keel-gorm"
// Connect
db, err := ssgorm.Connect(ssgorm.Config{
Driver: "postgres",
DSN: os.Getenv("DATABASE_URL"),
})
// Generic repository — no boilerplate
userRepo := ssgorm.NewRepository[User, string](db)
// userRepo implements core.Repository[User, string]
userRepo.FindByID(ctx, "abc-123")
userRepo.FindAll(ctx, core.PageQuery{Page: 1, Limit: 20})
userRepo.Create(ctx, &user)
userRepo.Update(ctx, "abc-123", &user)
userRepo.Delete(ctx, "abc-123")

Models follow standard GORM conventions:

type User struct {
ID string `gorm:"primaryKey"`
Name string
Email string `gorm:"uniqueIndex"`
CreatedAt time.Time
UpdatedAt time.Time
}
app.RegisterHealthChecker(ssgorm.NewHealthChecker(db))
// → "database": "UP" in GET /health

The generic repository covers standard CRUD. For custom queries, embed it:

type UserRepository struct {
*ssgorm.Repository[User, string]
db *gorm.DB
}
func (r *UserRepository) FindByEmail(ctx context.Context, email string) (*User, error) {
var user User
return &user, r.db.WithContext(ctx).Where("email = ?", email).First(&user).Error
}