// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.26.0
// source: session.sql

package db

import (
	"context"
)

const commitSession = `-- name: CommitSession :exec
INSERT INTO sessions (
  token, data, expires
) VALUES (
  $1, $2, $3
)
ON CONFLICT(token) DO UPDATE SET token = $1, data = $2, expires = $3
`

type CommitSessionParams struct {
	Token   string
	Data    []byte
	Expires int64
}

func (q *Queries) CommitSession(ctx context.Context, arg CommitSessionParams) error {
	_, err := q.db.Exec(ctx, commitSession, arg.Token, arg.Data, arg.Expires)
	return err
}

const deleteSession = `-- name: DeleteSession :exec
DELETE FROM sessions WHERE token = $1
`

func (q *Queries) DeleteSession(ctx context.Context, token string) error {
	_, err := q.db.Exec(ctx, deleteSession, token)
	return err
}

const findSession = `-- name: FindSession :one
SELECT data FROM sessions WHERE token = $1 AND expires > $2
`

type FindSessionParams struct {
	Token string
	Now   int64
}

func (q *Queries) FindSession(ctx context.Context, arg FindSessionParams) ([]byte, error) {
	row := q.db.QueryRow(ctx, findSession, arg.Token, arg.Now)
	var data []byte
	err := row.Scan(&data)
	return data, err
}

const findSessions = `-- name: FindSessions :many
SELECT token,data FROM sessions WHERE expires > $1
`

type FindSessionsRow struct {
	Token string
	Data  []byte
}

func (q *Queries) FindSessions(ctx context.Context, now int64) ([]FindSessionsRow, error) {
	rows, err := q.db.Query(ctx, findSessions, now)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []FindSessionsRow
	for rows.Next() {
		var i FindSessionsRow
		if err := rows.Scan(&i.Token, &i.Data); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}
