Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
remove scanBook function
Browse files Browse the repository at this point in the history
  • Loading branch information
imantung committed Dec 17, 2019
1 parent 59fe4b6 commit 3fc654b
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions app/repository/book_repo_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ func (r *BookRepoImpl) Find(ctx context.Context, id int64) (book *Book, err erro
return
}
if rows.Next() {
book, err = scanBook(rows)
var book0 Book
if err = rows.Scan(&book0.ID, &book0.Title, &book0.Author, &book0.UpdatedAt, &book0.CreatedAt); err != nil {
return nil, err
}
book = &book0
}
return
}
Expand All @@ -42,11 +46,11 @@ func (r *BookRepoImpl) List(ctx context.Context) (list []*Book, err error) {
}
list = make([]*Book, 0)
for rows.Next() {
var book *Book
if book, err = scanBook(rows); err != nil {
return
var book0 Book
if err = rows.Scan(&book0.ID, &book0.Title, &book0.Author, &book0.UpdatedAt, &book0.CreatedAt); err != nil {
return nil, err
}
list = append(list, book)
list = append(list, &book0)
}
return
}
Expand Down Expand Up @@ -85,12 +89,3 @@ func (r *BookRepoImpl) Update(ctx context.Context, book Book) (err error) {
_, err = builder.RunWith(r.DB).ExecContext(ctx)
return
}

func scanBook(rows *sql.Rows) (*Book, error) {
var book Book
var err error
if err = rows.Scan(&book.ID, &book.Title, &book.Author, &book.UpdatedAt, &book.CreatedAt); err != nil {
return nil, err
}
return &book, nil
}

0 comments on commit 3fc654b

Please sign in to comment.