Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Chapter_6_Storing_Data/sql_store1/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func Posts(limit int) (posts []Post, err error) {
if err != nil {
return
}
defer rows.Close()
for rows.Next() {
post := Post{}
err = rows.Scan(&post.Id, &post.Content, &post.Author)
Expand All @@ -37,7 +38,6 @@ func Posts(limit int) (posts []Post, err error) {
}
posts = append(posts, post)
}
rows.Close()
return
}

Expand Down
2 changes: 1 addition & 1 deletion Chapter_6_Storing_Data/sql_store2/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func GetPost(id int) (post Post, err error) {
if err != nil {
return
}
defer rows.Close()
for rows.Next() {
comment := Comment{Post: &post}
err = rows.Scan(&comment.Id, &comment.Content, &comment.Author)
Expand All @@ -59,7 +60,6 @@ func GetPost(id int) (post Post, err error) {
}
post.Comments = append(post.Comments, comment)
}
rows.Close()
return
}

Expand Down