feat: sqlite: implement GetUserByUsername
This commit is contained in:
parent
9220753210
commit
6e1ac07b04
3 changed files with 77 additions and 6 deletions
|
|
@ -98,6 +98,19 @@ func (s *Store) GetUserByEmail(ctx context.Context, email string) (*store.User,
|
|||
return u, nil
|
||||
}
|
||||
|
||||
// GetUserByUsername returns the user with the given username.
|
||||
func (s *Store) GetUserByUsername(ctx context.Context, normalizedUsername string) (*store.User, error) {
|
||||
row := s.db.QueryRowContext(ctx, s.q.GetUserByUsername, normalizedUsername)
|
||||
u, err := s.scanUser(row)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, fmt.Errorf("pase/sqlite: get user by username: %w", store.ErrUserNotFound)
|
||||
}
|
||||
return nil, fmt.Errorf("pase/sqlite: get user by username: %w", err)
|
||||
}
|
||||
return u, nil
|
||||
}
|
||||
|
||||
func (s *Store) scanUser(row *sql.Row) (*store.User, error) {
|
||||
var u store.User
|
||||
err := row.Scan(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue