Load users from the database during startup

This commit is contained in:
Gary Kramlich
2022-01-05 14:59:35 -06:00
parent aa7059b1e3
commit de1f524e25
5 changed files with 60 additions and 8 deletions

View File

@@ -25,3 +25,19 @@ func (uq *UserQuery) GetByMXID(userID id.UserID) *User {
return uq.New().Scan(row)
}
func (uq *UserQuery) GetAll() []*User {
rows, err := uq.db.Query("SELECT mxid, id, management_room, token FROM user")
if err != nil || rows == nil {
return nil
}
defer rows.Close()
users := []*User{}
for rows.Next() {
users = append(users, uq.New().Scan(rows))
}
return users
}