Files
mtusi2026lab4/internal/storage/postgres/internal/sqlcgen/sessions.sql.go
T
2026-10-15 20:45:29 +03:00

84 lines
1.8 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: sessions.sql
package sqlcgen
import (
"context"
"time"
"github.com/google/uuid"
)
const createSession = `-- name: CreateSession :one
INSERT INTO sessions (token_hash, user_id, expires_at)
VALUES ($1, $2, $3)
RETURNING token_hash, user_id, expires_at
`
type CreateSessionParams struct {
TokenHash []byte
UserID uuid.UUID
ExpiresAt time.Time
}
type CreateSessionRow struct {
TokenHash []byte
UserID uuid.UUID
ExpiresAt time.Time
}
func (q *Queries) CreateSession(ctx context.Context, arg CreateSessionParams) (CreateSessionRow, error) {
row := q.db.QueryRow(ctx, createSession, arg.TokenHash, arg.UserID, arg.ExpiresAt)
var i CreateSessionRow
err := row.Scan(&i.TokenHash, &i.UserID, &i.ExpiresAt)
return i, err
}
const deleteSession = `-- name: DeleteSession :exec
DELETE FROM sessions
WHERE token_hash = $1
AND user_id = $2
`
type DeleteSessionParams struct {
TokenHash []byte
UserID uuid.UUID
}
func (q *Queries) DeleteSession(ctx context.Context, arg DeleteSessionParams) error {
_, err := q.db.Exec(ctx, deleteSession, arg.TokenHash, arg.UserID)
return err
}
const getSessionUser = `-- name: GetSessionUser :one
SELECT u.id, u.username, u.display_name, u.created_at, s.expires_at
FROM sessions s
JOIN users u ON u.id = s.user_id
WHERE s.token_hash = $1
AND s.expires_at > now()
`
type GetSessionUserRow struct {
ID uuid.UUID
Username string
DisplayName string
CreatedAt time.Time
ExpiresAt time.Time
}
func (q *Queries) GetSessionUser(ctx context.Context, tokenHash []byte) (GetSessionUserRow, error) {
row := q.db.QueryRow(ctx, getSessionUser, tokenHash)
var i GetSessionUserRow
err := row.Scan(
&i.ID,
&i.Username,
&i.DisplayName,
&i.CreatedAt,
&i.ExpiresAt,
)
return i, err
}