yokoe/gorm-snippets

View on GitHub
testdata/find_by_id.golden

Summary

Maintainability
Test Coverage
func findBookByID(db *gorm.DB, id int) (*model.Book, error) {
    var obj model.Book
    if err := db.Find(&obj, id).Error; err != nil {
        return nil, xerrors.Errorf("failed to find model.Book with id %v: %w", id, err)
    }
    return &obj, nil
}