Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allBooks() #4

Open
danzelbg opened this issue Nov 7, 2020 · 0 comments
Open

allBooks() #4

danzelbg opened this issue Nov 7, 2020 · 0 comments

Comments

@danzelbg
Copy link

danzelbg commented Nov 7, 2020

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)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant