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]
Planned Installation
Section titled “Planned Installation”go get github.com/slice-soft/ss-keel-gormPlanned Usage
Section titled “Planned Usage”import "github.com/slice-soft/ss-keel-gorm"
// Connectdb, err := ssgorm.Connect(ssgorm.Config{ Driver: "postgres", DSN: os.Getenv("DATABASE_URL"),})
// Generic repository — no boilerplateuserRepo := 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")Model Definition
Section titled “Model Definition”Models follow standard GORM conventions:
type User struct { ID string `gorm:"primaryKey"` Name string Email string `gorm:"uniqueIndex"` CreatedAt time.Time UpdatedAt time.Time}Health Check
Section titled “Health Check”app.RegisterHealthChecker(ssgorm.NewHealthChecker(db))// → "database": "UP" in GET /healthExtending the Generic Repository
Section titled “Extending the Generic Repository”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}