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

package db

import (
	"context"
)

const commitSession = `-- name: CommitSession :exec
REPLACE INTO sessions (
  token, data, expires
) VALUES (
  ?, ?, ?
)
`

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

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

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

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

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

type FindSessionParams struct {
	Token string
	Now   int64
}

func (q *Queries) FindSession(ctx context.Context, arg FindSessionParams) ([]byte, error) {
	row := q.db.QueryRowContext(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.QueryContext(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.Close(); err != nil {
		return nil, err
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}
