ampelmaennchen.git

ref: df4ccb956a6718407ddb1592677bebff36b83994

db/users.go


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
package db

import (
	"apiote.xyz/p/ampelmaennchen/accounts"

	"database/sql"
	"errors"
	"fmt"
)

func GetUser(userID string) (accounts.User, error) {
	user := accounts.User{}
	row := db.QueryRow("select name, matrix_handle from users where id = $1", userID)
	err := row.Scan(&user.Name, &user.MatrixHandle)
	if err != nil {
		if errors.Is(err, sql.ErrNoRows) {
			return user, nil
		}
		return user, fmt.Errorf("while selecting user: %w", err)
	}
	return user, nil
}