// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.30.0 // source: sessions.sql package db import ( "context" "github.com/jackc/pgx/v5/pgtype" ) const deleteExpiredSessions = `-- name: DeleteExpiredSessions :exec DELETE FROM sessions WHERE expires_at < NOW() ` func (q *Queries) DeleteExpiredSessions(ctx context.Context) error { _, err := q.db.Exec(ctx, deleteExpiredSessions) return err } const deleteSession = `-- name: DeleteSession :exec DELETE FROM sessions WHERE id = $1 ` func (q *Queries) DeleteSession(ctx context.Context, id string) error { _, err := q.db.Exec(ctx, deleteSession, id) return err } const deleteSessionForUser = `-- name: DeleteSessionForUser :exec DELETE FROM sessions WHERE id = $1 AND user_id = $2 ` type DeleteSessionForUserParams struct { ID string `json:"id"` UserID pgtype.UUID `json:"user_id"` } func (q *Queries) DeleteSessionForUser(ctx context.Context, arg DeleteSessionForUserParams) error { _, err := q.db.Exec(ctx, deleteSessionForUser, arg.ID, arg.UserID) return err } const deleteSessionsByUserID = `-- name: DeleteSessionsByUserID :many DELETE FROM sessions WHERE user_id = $1 RETURNING id ` func (q *Queries) DeleteSessionsByUserID(ctx context.Context, userID pgtype.UUID) ([]string, error) { rows, err := q.db.Query(ctx, deleteSessionsByUserID, userID) if err != nil { return nil, err } defer rows.Close() var items []string for rows.Next() { var id string if err := rows.Scan(&id); err != nil { return nil, err } items = append(items, id) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const getSession = `-- name: GetSession :one SELECT id, user_id, team_id, csrf_token, user_agent, ip_address, created_at, last_seen_at, expires_at FROM sessions WHERE id = $1 ` func (q *Queries) GetSession(ctx context.Context, id string) (Session, error) { row := q.db.QueryRow(ctx, getSession, id) var i Session err := row.Scan( &i.ID, &i.UserID, &i.TeamID, &i.CsrfToken, &i.UserAgent, &i.IpAddress, &i.CreatedAt, &i.LastSeenAt, &i.ExpiresAt, ) return i, err } const insertSession = `-- name: InsertSession :one INSERT INTO sessions (id, user_id, team_id, csrf_token, user_agent, ip_address, expires_at) VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING id, user_id, team_id, csrf_token, user_agent, ip_address, created_at, last_seen_at, expires_at ` type InsertSessionParams struct { ID string `json:"id"` UserID pgtype.UUID `json:"user_id"` TeamID pgtype.UUID `json:"team_id"` CsrfToken string `json:"csrf_token"` UserAgent string `json:"user_agent"` IpAddress string `json:"ip_address"` ExpiresAt pgtype.Timestamptz `json:"expires_at"` } func (q *Queries) InsertSession(ctx context.Context, arg InsertSessionParams) (Session, error) { row := q.db.QueryRow(ctx, insertSession, arg.ID, arg.UserID, arg.TeamID, arg.CsrfToken, arg.UserAgent, arg.IpAddress, arg.ExpiresAt, ) var i Session err := row.Scan( &i.ID, &i.UserID, &i.TeamID, &i.CsrfToken, &i.UserAgent, &i.IpAddress, &i.CreatedAt, &i.LastSeenAt, &i.ExpiresAt, ) return i, err } const listSessionsByUserID = `-- name: ListSessionsByUserID :many SELECT id, user_id, team_id, csrf_token, user_agent, ip_address, created_at, last_seen_at, expires_at FROM sessions WHERE user_id = $1 ORDER BY last_seen_at DESC ` func (q *Queries) ListSessionsByUserID(ctx context.Context, userID pgtype.UUID) ([]Session, error) { rows, err := q.db.Query(ctx, listSessionsByUserID, userID) if err != nil { return nil, err } defer rows.Close() var items []Session for rows.Next() { var i Session if err := rows.Scan( &i.ID, &i.UserID, &i.TeamID, &i.CsrfToken, &i.UserAgent, &i.IpAddress, &i.CreatedAt, &i.LastSeenAt, &i.ExpiresAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const touchSession = `-- name: TouchSession :exec UPDATE sessions SET last_seen_at = NOW() WHERE id = $1 ` func (q *Queries) TouchSession(ctx context.Context, id string) error { _, err := q.db.Exec(ctx, touchSession, id) return err } const updateSessionTeam = `-- name: UpdateSessionTeam :exec UPDATE sessions SET team_id = $2 WHERE id = $1 ` type UpdateSessionTeamParams struct { ID string `json:"id"` TeamID pgtype.UUID `json:"team_id"` } func (q *Queries) UpdateSessionTeam(ctx context.Context, arg UpdateSessionTeamParams) error { _, err := q.db.Exec(ctx, updateSessionTeam, arg.ID, arg.TeamID) return err }