1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2025-06-25 13:58:10 +02:00

More metrics

This commit is contained in:
binwiederhier 2023-03-16 22:19:20 -04:00
parent 358b344916
commit ca9fed7b67
5 changed files with 60 additions and 19 deletions

View file

@ -169,6 +169,7 @@ const (
ELSE 2
END, user
`
selectUserCountQuery = `SELECT COUNT(*) FROM user`
updateUserPassQuery = `UPDATE user SET pass = ? WHERE user = ?`
updateUserRoleQuery = `UPDATE user SET role = ? WHERE user = ?`
updateUserPrefsQuery = `UPDATE user SET prefs = ? WHERE id = ?`
@ -853,6 +854,23 @@ func (a *Manager) Users() ([]*User, error) {
return users, nil
}
// UsersCount returns the number of users in the databsae
func (a *Manager) UsersCount() (int64, error) {
rows, err := a.db.Query(selectUserCountQuery)
if err != nil {
return 0, err
}
defer rows.Close()
if !rows.Next() {
return 0, errNoRows
}
var count int64
if err := rows.Scan(&count); err != nil {
return 0, err
}
return count, nil
}
// User returns the user with the given username if it exists, or ErrUserNotFound otherwise.
// You may also pass Everyone to retrieve the anonymous user and its Grant list.
func (a *Manager) User(username string) (*User, error) {