// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.31.1 // source: sessions.sql package store import ( "context" "time" "github.com/google/uuid" ) const getSessionByTokenHash = `-- name: GetSessionByTokenHash :one SELECT s.id, s.user_id, s.token_hash, s.created_at, s.expires_at, s.last_used, s.revoked_at, u.username as session_username FROM sessions s JOIN users u ON u.id = s.user_id WHERE token_hash = $1 AND revoked_at IS NULL AND expires_at > NOW() ` type GetSessionByTokenHashRow struct { ID uuid.UUID UserID uuid.UUID TokenHash []byte CreatedAt time.Time ExpiresAt time.Time LastUsed *time.Time RevokedAt *time.Time SessionUsername string } func (q *Queries) GetSessionByTokenHash(ctx context.Context, tokenHash []byte) (GetSessionByTokenHashRow, error) { row := q.db.QueryRow(ctx, getSessionByTokenHash, tokenHash) var i GetSessionByTokenHashRow err := row.Scan( &i.ID, &i.UserID, &i.TokenHash, &i.CreatedAt, &i.ExpiresAt, &i.LastUsed, &i.RevokedAt, &i.SessionUsername, ) return i, err } const newSession = `-- name: NewSession :one INSERT INTO sessions (user_id, token_hash, expires_at) VALUES ($1, $2, $3) RETURNING id, user_id, token_hash, created_at, expires_at, last_used, revoked_at ` type NewSessionParams struct { UserID uuid.UUID TokenHash []byte ExpiresAt time.Time } func (q *Queries) NewSession(ctx context.Context, arg NewSessionParams) (Session, error) { row := q.db.QueryRow(ctx, newSession, arg.UserID, arg.TokenHash, arg.ExpiresAt) var i Session err := row.Scan( &i.ID, &i.UserID, &i.TokenHash, &i.CreatedAt, &i.ExpiresAt, &i.LastUsed, &i.RevokedAt, ) return i, err } const revokeSession = `-- name: RevokeSession :exec UPDATE sessions SET revoked_at = NOW() WHERE id = $1 ` func (q *Queries) RevokeSession(ctx context.Context, id uuid.UUID) error { _, err := q.db.Exec(ctx, revokeSession, id) return err }