refactor(db): drop Querier and select only user id for session lookup

This commit is contained in:
kk10
2026-10-04 23:08:11 +03:00
parent 527c1748f8
commit 5d6f5a397f
4 changed files with 13 additions and 58 deletions
+9 -22
View File
@@ -58,28 +58,15 @@ func (q *Queries) DeleteSession(ctx context.Context, tokenHash string) error {
return err
}
const getSessionUser = `-- name: GetSessionUser :one
SELECT u.id, u.username, u.display_name, u.created_at FROM sessions s
JOIN users u ON u.id = s.user_id
WHERE s.token_hash = $1
AND s.expires_at > now()
const getSessionUserID = `-- name: GetSessionUserID :one
SELECT user_id FROM sessions
WHERE token_hash = $1
AND expires_at > now()
`
type GetSessionUserRow struct {
ID uuid.UUID
Username string
DisplayName string
CreatedAt time.Time
}
func (q *Queries) GetSessionUser(ctx context.Context, tokenHash string) (GetSessionUserRow, error) {
row := q.db.QueryRow(ctx, getSessionUser, tokenHash)
var i GetSessionUserRow
err := row.Scan(
&i.ID,
&i.Username,
&i.DisplayName,
&i.CreatedAt,
)
return i, err
func (q *Queries) GetSessionUserID(ctx context.Context, tokenHash string) (uuid.UUID, error) {
row := q.db.QueryRow(ctx, getSessionUserID, tokenHash)
var user_id uuid.UUID
err := row.Scan(&user_id)
return user_id, err
}