-
Notifications
You must be signed in to change notification settings - Fork 22
Open
Description
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)
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels