/gorm-snippets

Code snippets generator for gorm

Primary LanguageGoMIT LicenseMIT

gorm-snippets

Maintainability Test Coverage

Code snippet generator for GORM. Generates customizable DB helper functions work with GORM. Designed to be used by code generators that generates repository layer code.

Usage

Golang

s, _ := snippet.FindByParam("model.Book", "UUID", "string")

will generate

func findBookByUUID(db *gorm.DB, arg string) (*model.Book, error) {
        if len(arg) == 0 {
                return nil, xerrors.Errorf("UUID must be non-nil.")
        }
        var obj model.Book
        if err := db.Find(&obj, "`uuid` = ?", arg).Error; err != nil {
                return nil, xerrors.Errorf("failed to find model.Book by UUID: %w", err)
        }
        return &obj, nil
}

Command line

TBD

Snippets

  • FindByID
  • FindByParam
  • BatchFindByID
  • BatchFindByParam