// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.25.0
// source: metrics.sql

package db

import (
	"context"
	"time"

	"github.com/jackc/pgtype"
)

const DomainStats = `-- name: DomainStats :many
SELECT time,
       data
FROM metrics
WHERE measurement = 'domains'
ORDER BY time DESC
LIMIT 1
`

type DomainStatsRow struct {
	Time time.Time
	Data pgtype.JSONB
}

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

const GetMetric = `-- name: GetMetric :many
SELECT time,
       data
FROM metrics
WHERE measurement = $1
ORDER BY time DESC
`

type GetMetricRow struct {
	Time time.Time
	Data pgtype.JSONB
}

func (q *Queries) GetMetric(ctx context.Context, measurement string) ([]GetMetricRow, error) {
	rows, err := q.db.Query(ctx, GetMetric, measurement)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []GetMetricRow{}
	for rows.Next() {
		var i GetMetricRow
		if err := rows.Scan(&i.Time, &i.Data); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const StoreMetric = `-- name: StoreMetric :exec
INSERT INTO metrics(measurement, data)
VALUES ($1, $2)
RETURNING id, measurement, time, data
`

type StoreMetricParams struct {
	Measurement string
	Data        pgtype.JSONB
}

func (q *Queries) StoreMetric(ctx context.Context, arg StoreMetricParams) error {
	_, err := q.db.Exec(ctx, StoreMetric, arg.Measurement, arg.Data)
	return err
}
