74 lines
1.7 KiB
Go
74 lines
1.7 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: sessions.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
const createSession = `-- name: CreateSession :one
|
|
INSERT INTO sessions (id, user_id, expires_at)
|
|
VALUES ($1, $2, $3)
|
|
RETURNING id, user_id, created_at, expires_at, revoked
|
|
`
|
|
|
|
type CreateSessionParams struct {
|
|
ID string `json:"id"`
|
|
UserID string `json:"user_id"`
|
|
ExpiresAt time.Time `json:"expires_at"`
|
|
}
|
|
|
|
func (q *Queries) CreateSession(ctx context.Context, arg CreateSessionParams) (*Session, error) {
|
|
row := q.db.QueryRow(ctx, createSession, arg.ID, arg.UserID, arg.ExpiresAt)
|
|
var i Session
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.CreatedAt,
|
|
&i.ExpiresAt,
|
|
&i.Revoked,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const getSession = `-- name: GetSession :one
|
|
SELECT id, user_id, created_at, expires_at, revoked FROM sessions
|
|
WHERE id = $1 AND revoked = false AND expires_at > now()
|
|
`
|
|
|
|
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.CreatedAt,
|
|
&i.ExpiresAt,
|
|
&i.Revoked,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const revokeAllUserSessions = `-- name: RevokeAllUserSessions :exec
|
|
UPDATE sessions SET revoked = true
|
|
WHERE user_id = $1
|
|
`
|
|
|
|
func (q *Queries) RevokeAllUserSessions(ctx context.Context, userID string) error {
|
|
_, err := q.db.Exec(ctx, revokeAllUserSessions, userID)
|
|
return err
|
|
}
|
|
|
|
const revokeSession = `-- name: RevokeSession :exec
|
|
UPDATE sessions SET revoked = true
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) RevokeSession(ctx context.Context, id string) error {
|
|
_, err := q.db.Exec(ctx, revokeSession, id)
|
|
return err
|
|
}
|