Skip to content

Instantly share code, notes, and snippets.

@dmichael
Last active December 17, 2015 01:59
Show Gist options
  • Save dmichael/5532334 to your computer and use it in GitHub Desktop.
Save dmichael/5532334 to your computer and use it in GitHub Desktop.
Simple ad-hoc query for count
var db *sql.DB
func Count() (int, error) {
rows, err := db.Query("SELECT COUNT(*) AS count FROM users")
if err != nil {
return nil, err
}
var count int
// populate the count
defer rows.Close()
for rows.Next() {
rows.Scan(&count)
}
return result.Count, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment