Skip to content

allBooks()  #4

@danzelbg

Description

@danzelbg

Hi, nice work! I am curious:

Can you explain why In the book.go allBooks function all variables for database query rows are redeclared inside "for" loop?
What about memory allocation? Have you tested all possible database response scenarios?

As shown in this tutorial variables are declared outside the loop:

Fetching Data from the Database
http://go-database-sql.org/retrieving.html

var (
id int
name string
)
rows, err := db.Query("select id, name from users where id = ?", 1)
if err != nil {
log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
err := rows.Scan(&id, &name)
if err != nil {
log.Fatal(err)
}
log.Println(id, name)
}
err = rows.Err()
if err != nil {
log.Fatal(err)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions