Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.29.0
// source: web_search.sql
package store
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const clearWebSearchDefaultBackend = `-- name: ClearWebSearchDefaultBackend :exec
UPDATE web_search_settings SET default_backend=NULL,updated_at=now()
WHERE default_backend=$1::text
`
// Removing a key also drops it as the default, so searches fall back to
// TeamHub's order instead of asking for the removed key.
func (q *Queries) ClearWebSearchDefaultBackend(ctx context.Context, backend string) error {
_, err := q.db.Exec(ctx, clearWebSearchDefaultBackend, backend)
return err
}
const deleteWebSearchKey = `-- name: DeleteWebSearchKey :exec
DELETE FROM web_search_keys WHERE backend=$1::text
`
func (q *Queries) DeleteWebSearchKey(ctx context.Context, backend string) error {
_, err := q.db.Exec(ctx, deleteWebSearchKey, backend)
return err
}
const getWebSearchDefaultBackend = `-- name: GetWebSearchDefaultBackend :one
SELECT COALESCE(default_backend,'')::text AS default_backend FROM web_search_settings WHERE singleton
`
func (q *Queries) GetWebSearchDefaultBackend(ctx context.Context) (string, error) {
row := q.db.QueryRow(ctx, getWebSearchDefaultBackend)
var default_backend string
err := row.Scan(&default_backend)
return default_backend, err
}
const listWebSearchKeys = `-- name: ListWebSearchKeys :many
SELECT backend,api_key_ciphertext,state,quota_remaining,quota_limit,quota_resets_at,quota_observed_at
FROM web_search_keys
ORDER BY backend
`
type ListWebSearchKeysRow struct {
Backend string `json:"backend"`
ApiKeyCiphertext []byte `json:"api_key_ciphertext"`
State string `json:"state"`
QuotaRemaining pgtype.Float8 `json:"quota_remaining"`
QuotaLimit pgtype.Float8 `json:"quota_limit"`
QuotaResetsAt pgtype.Timestamptz `json:"quota_resets_at"`
QuotaObservedAt pgtype.Timestamptz `json:"quota_observed_at"`
}
// At most one row per backend; callers pick the one they need.
func (q *Queries) ListWebSearchKeys(ctx context.Context) ([]ListWebSearchKeysRow, error) {
rows, err := q.db.Query(ctx, listWebSearchKeys)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListWebSearchKeysRow{}
for rows.Next() {
var i ListWebSearchKeysRow
if err := rows.Scan(
&i.Backend,
&i.ApiKeyCiphertext,
&i.State,
&i.QuotaRemaining,
&i.QuotaLimit,
&i.QuotaResetsAt,
&i.QuotaObservedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const markWebSearchKeyRejected = `-- name: MarkWebSearchKeyRejected :exec
UPDATE web_search_keys SET state='rejected',updated_at=now()
WHERE backend=$1::text AND api_key_ciphertext=$2::bytea
`
type MarkWebSearchKeyRejectedParams struct {
Backend string `json:"backend"`
ApiKeyCiphertext []byte `json:"api_key_ciphertext"`
}
// Matching the sealed key leaves a key saved since the refused call alone.
func (q *Queries) MarkWebSearchKeyRejected(ctx context.Context, arg MarkWebSearchKeyRejectedParams) error {
_, err := q.db.Exec(ctx, markWebSearchKeyRejected, arg.Backend, arg.ApiKeyCiphertext)
return err
}
const recordWebSearchKeyAnswer = `-- name: RecordWebSearchKeyAnswer :exec
UPDATE web_search_keys SET state='verified',
quota_remaining=CASE WHEN $1::boolean THEN $2::double precision ELSE quota_remaining END,
quota_limit=CASE WHEN $1::boolean THEN $3::double precision ELSE quota_limit END,
quota_resets_at=CASE WHEN $1::boolean THEN $4::timestamptz ELSE quota_resets_at END,
quota_observed_at=CASE WHEN $1::boolean THEN now() ELSE quota_observed_at END,
updated_at=now()
WHERE backend=$5::text AND api_key_ciphertext=$6::bytea
`
type RecordWebSearchKeyAnswerParams struct {
HasQuota bool `json:"has_quota"`
QuotaRemaining pgtype.Float8 `json:"quota_remaining"`
QuotaLimit pgtype.Float8 `json:"quota_limit"`
QuotaResetsAt pgtype.Timestamptz `json:"quota_resets_at"`
Backend string `json:"backend"`
ApiKeyCiphertext []byte `json:"api_key_ciphertext"`
}
// An answered call proves the key; quota columns change only when the
// response reported quota.
func (q *Queries) RecordWebSearchKeyAnswer(ctx context.Context, arg RecordWebSearchKeyAnswerParams) error {
_, err := q.db.Exec(ctx, recordWebSearchKeyAnswer,
arg.HasQuota,
arg.QuotaRemaining,
arg.QuotaLimit,
arg.QuotaResetsAt,
arg.Backend,
arg.ApiKeyCiphertext,
)
return err
}
const setWebSearchDefaultBackend = `-- name: SetWebSearchDefaultBackend :exec
INSERT INTO web_search_settings (singleton,default_backend)
VALUES (true,$1::text)
ON CONFLICT (singleton) DO UPDATE SET default_backend=excluded.default_backend,updated_at=now()
`
func (q *Queries) SetWebSearchDefaultBackend(ctx context.Context, defaultBackend pgtype.Text) error {
_, err := q.db.Exec(ctx, setWebSearchDefaultBackend, defaultBackend)
return err
}
const upsertWebSearchKey = `-- name: UpsertWebSearchKey :exec
INSERT INTO web_search_keys (backend,api_key_ciphertext,state)
VALUES ($1::text,$2::bytea,$3::text)
ON CONFLICT (backend) DO UPDATE SET
api_key_ciphertext=excluded.api_key_ciphertext,state=excluded.state,
quota_remaining=NULL,quota_limit=NULL,quota_resets_at=NULL,quota_observed_at=NULL,updated_at=now()
`
type UpsertWebSearchKeyParams struct {
Backend string `json:"backend"`
ApiKeyCiphertext []byte `json:"api_key_ciphertext"`
State string `json:"state"`
}
// A new key starts with no observed quota.
func (q *Queries) UpsertWebSearchKey(ctx context.Context, arg UpsertWebSearchKeyParams) error {
_, err := q.db.Exec(ctx, upsertWebSearchKey, arg.Backend, arg.ApiKeyCiphertext, arg.State)
return err
}