// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.31.1 // source: queries.sql package db import ( "context" "database/sql" ) const addSecret = `-- name: AddSecret :exec INSERT INTO secrets(kind, id, value, expires) VALUES (?, ?, ?, ?) ` type AddSecretParams struct { Kind string ID string Value []byte Expires int64 } func (q *Queries) AddSecret(ctx context.Context, arg AddSecretParams) error { _, err := q.exec(ctx, q.addSecretStmt, addSecret, arg.Kind, arg.ID, arg.Value, arg.Expires, ) return err } const advanceCursor = `-- name: AdvanceCursor :exec INSERT INTO stream_cursors(source, time_us) VALUES (?, ?) ON CONFLICT(source) DO UPDATE SET time_us = max(stream_cursors.time_us, excluded.time_us) ` type AdvanceCursorParams struct { Source string TimeUs int64 } func (q *Queries) AdvanceCursor(ctx context.Context, arg AdvanceCursorParams) error { _, err := q.exec(ctx, q.advanceCursorStmt, advanceCursor, arg.Source, arg.TimeUs) return err } const advanceReplayAccount = `-- name: AdvanceReplayAccount :exec INSERT INTO replay_accounts(source, author, sequence) VALUES (?1, ?2, ?3) ON CONFLICT(source, author) DO UPDATE SET sequence = excluded.sequence ` type AdvanceReplayAccountParams struct { Source string Author int64 Sequence int64 } func (q *Queries) AdvanceReplayAccount(ctx context.Context, arg AdvanceReplayAccountParams) error { _, err := q.exec(ctx, q.advanceReplayAccountStmt, advanceReplayAccount, arg.Source, arg.Author, arg.Sequence) return err } const authorRecords = `-- name: AuthorRecords :many SELECT author, subject, tag, score, created_at, record_key, comment, source FROM vouches WHERE author = ? ` func (q *Queries) AuthorRecords(ctx context.Context, author string) ([]Vouch, error) { rows, err := q.query(ctx, q.authorRecordsStmt, authorRecords, author) if err != nil { return nil, err } defer rows.Close() items := []Vouch{} for rows.Next() { var i Vouch if err := rows.Scan( &i.Author, &i.Subject, &i.Tag, &i.Score, &i.CreatedAt, &i.RecordKey, &i.Comment, &i.Source, ); 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 } const bumpGraphRevision = `-- name: BumpGraphRevision :exec UPDATE graph_revision SET revision = revision + 1 WHERE singleton = 1 ` func (q *Queries) BumpGraphRevision(ctx context.Context) error { _, err := q.exec(ctx, q.bumpGraphRevisionStmt, bumpGraphRevision) return err } const cachedTrust = `-- name: CachedTrust :one SELECT status, score FROM trust_cache WHERE cache_key = ? AND expires_us > ? ` type CachedTrustParams struct { CacheKey string ExpiresUs int64 } type CachedTrustRow struct { Status string Score sql.NullFloat64 } func (q *Queries) CachedTrust(ctx context.Context, arg CachedTrustParams) (CachedTrustRow, error) { row := q.queryRow(ctx, q.cachedTrustStmt, cachedTrust, arg.CacheKey, arg.ExpiresUs) var i CachedTrustRow err := row.Scan(&i.Status, &i.Score) return i, err } const clearListAuthor = `-- name: ClearListAuthor :exec DELETE FROM list_records WHERE author = (SELECT id FROM identities WHERE did = CAST(?1 AS TEXT)) ` func (q *Queries) ClearListAuthor(ctx context.Context, author string) error { _, err := q.exec(ctx, q.clearListAuthorStmt, clearListAuthor, author) return err } const clearListVersions = `-- name: ClearListVersions :exec DELETE FROM list_versions WHERE author = (SELECT id FROM identities WHERE did = CAST(?1 AS TEXT)) ` func (q *Queries) ClearListVersions(ctx context.Context, author string) error { _, err := q.exec(ctx, q.clearListVersionsStmt, clearListVersions, author) return err } const clearSoft = `-- name: ClearSoft :exec DELETE FROM soft_vouches WHERE author = (SELECT id FROM identities WHERE did = CAST(?1 AS TEXT)) ` func (q *Queries) ClearSoft(ctx context.Context, author string) error { _, err := q.exec(ctx, q.clearSoftStmt, clearSoft, author) return err } const clearSoftVersions = `-- name: ClearSoftVersions :exec DELETE FROM soft_versions WHERE author = (SELECT id FROM identities WHERE did = CAST(?1 AS TEXT)) ` func (q *Queries) ClearSoftVersions(ctx context.Context, author string) error { _, err := q.exec(ctx, q.clearSoftVersionsStmt, clearSoftVersions, author) return err } const clearTrust = `-- name: ClearTrust :exec DELETE FROM trust_cache ` func (q *Queries) ClearTrust(ctx context.Context) error { _, err := q.exec(ctx, q.clearTrustStmt, clearTrust) return err } const clearVersions = `-- name: ClearVersions :exec DELETE FROM record_versions WHERE author = ? ` func (q *Queries) ClearVersions(ctx context.Context, author string) error { _, err := q.exec(ctx, q.clearVersionsStmt, clearVersions, author) return err } const clearVouches = `-- name: ClearVouches :exec DELETE FROM vouches WHERE author = ? ` func (q *Queries) ClearVouches(ctx context.Context, author string) error { _, err := q.exec(ctx, q.clearVouchesStmt, clearVouches, author) return err } const consumeSecret = `-- name: ConsumeSecret :one DELETE FROM secrets WHERE kind = ? AND id = ? AND expires > ? RETURNING value ` type ConsumeSecretParams struct { Kind string ID string Expires int64 } func (q *Queries) ConsumeSecret(ctx context.Context, arg ConsumeSecretParams) ([]byte, error) { row := q.queryRow(ctx, q.consumeSecretStmt, consumeSecret, arg.Kind, arg.ID, arg.Expires) var value []byte err := row.Scan(&value) return value, err } const cursor = `-- name: Cursor :one SELECT time_us FROM stream_cursors WHERE source = ? ` func (q *Queries) Cursor(ctx context.Context, source string) (int64, error) { row := q.queryRow(ctx, q.cursorStmt, cursor, source) var time_us int64 err := row.Scan(&time_us) return time_us, err } const deferReplayIndexes = `-- name: DeferReplayIndexes :exec UPDATE replay_indexes SET source = ?, deferred = 1 WHERE singleton = 1 ` func (q *Queries) DeferReplayIndexes(ctx context.Context, source string) error { _, err := q.exec(ctx, q.deferReplayIndexesStmt, deferReplayIndexes, source) return err } const deferTrustInvalidation = `-- name: DeferTrustInvalidation :exec UPDATE cache_policy SET deferred = 1 WHERE singleton = 1 ` func (q *Queries) DeferTrustInvalidation(ctx context.Context) error { _, err := q.exec(ctx, q.deferTrustInvalidationStmt, deferTrustInvalidation) return err } const deleteListRecord = `-- name: DeleteListRecord :exec DELETE FROM list_records WHERE author = (SELECT id FROM identities WHERE did = CAST(?1 AS TEXT)) AND source = ?2 AND record_key = ?3 ` type DeleteListRecordParams struct { Author string Source string RecordKey string } func (q *Queries) DeleteListRecord(ctx context.Context, arg DeleteListRecordParams) error { _, err := q.exec(ctx, q.deleteListRecordStmt, deleteListRecord, arg.Author, arg.Source, arg.RecordKey) return err } const deleteRecord = `-- name: DeleteRecord :exec DELETE FROM vouches WHERE author = ? AND record_key = ? ` type DeleteRecordParams struct { Author string RecordKey string } func (q *Queries) DeleteRecord(ctx context.Context, arg DeleteRecordParams) error { _, err := q.exec(ctx, q.deleteRecordStmt, deleteRecord, arg.Author, arg.RecordKey) return err } const deleteReplaySoft = `-- name: DeleteReplaySoft :exec DELETE FROM soft_vouches WHERE author = ?1 AND source = ?2 AND record_key = ?3 ` type DeleteReplaySoftParams struct { Author int64 Source string RecordKey string } func (q *Queries) DeleteReplaySoft(ctx context.Context, arg DeleteReplaySoftParams) error { _, err := q.exec(ctx, q.deleteReplaySoftStmt, deleteReplaySoft, arg.Author, arg.Source, arg.RecordKey) return err } const deleteSoft = `-- name: DeleteSoft :exec DELETE FROM soft_vouches WHERE author = (SELECT id FROM identities WHERE did = CAST(?1 AS TEXT)) AND source = ?2 AND record_key = ?3 ` type DeleteSoftParams struct { Author string Source string RecordKey string } func (q *Queries) DeleteSoft(ctx context.Context, arg DeleteSoftParams) error { _, err := q.exec(ctx, q.deleteSoftStmt, deleteSoft, arg.Author, arg.Source, arg.RecordKey) return err } const deleteTrust = `-- name: DeleteTrust :exec DELETE FROM trust_cache WHERE cache_key = ? ` func (q *Queries) DeleteTrust(ctx context.Context, cacheKey string) error { _, err := q.exec(ctx, q.deleteTrustStmt, deleteTrust, cacheKey) return err } const finishReplayIndexes = `-- name: FinishReplayIndexes :exec UPDATE replay_indexes SET deferred = 0 WHERE singleton = 1 ` func (q *Queries) FinishReplayIndexes(ctx context.Context) error { _, err := q.exec(ctx, q.finishReplayIndexesStmt, finishReplayIndexes) return err } const getSecret = `-- name: GetSecret :one SELECT value FROM secrets WHERE kind = ? AND id = ? AND expires > ? ` type GetSecretParams struct { Kind string ID string Expires int64 } func (q *Queries) GetSecret(ctx context.Context, arg GetSecretParams) ([]byte, error) { row := q.queryRow(ctx, q.getSecretStmt, getSecret, arg.Kind, arg.ID, arg.Expires) var value []byte err := row.Scan(&value) return value, err } const graph = `-- name: Graph :many SELECT vouches.author, vouches.subject, vouches.tag, vouches.score, vouches.created_at, vouches.record_key, vouches.comment, vouches.source FROM vouches JOIN participants ON participants.did = vouches.author WHERE participants.active = 1 AND NOT EXISTS (SELECT 1 FROM participants target WHERE target.did = vouches.subject AND target.active = 0) AND (tag = ?1 OR (CAST(?2 AS INTEGER) = 1 AND tag = '')) ORDER BY author, subject, tag LIMIT ?3 ` type GraphParams struct { Tag string Fallback int64 MaxRows int64 } func (q *Queries) Graph(ctx context.Context, arg GraphParams) ([]Vouch, error) { rows, err := q.query(ctx, q.graphStmt, graph, arg.Tag, arg.Fallback, arg.MaxRows) if err != nil { return nil, err } defer rows.Close() items := []Vouch{} for rows.Next() { var i Vouch if err := rows.Scan( &i.Author, &i.Subject, &i.Tag, &i.Score, &i.CreatedAt, &i.RecordKey, &i.Comment, &i.Source, ); 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 } const graphRevision = `-- name: GraphRevision :one SELECT revision FROM graph_revision WHERE singleton = 1 ` func (q *Queries) GraphRevision(ctx context.Context) (int64, error) { row := q.queryRow(ctx, q.graphRevisionStmt, graphRevision) var revision int64 err := row.Scan(&revision) return revision, err } const incoming = `-- name: Incoming :many SELECT vouches.author, vouches.subject, vouches.tag, vouches.score, vouches.created_at, vouches.record_key, vouches.comment, vouches.source FROM vouches JOIN participants ON participants.did = vouches.author WHERE subject = ?1 AND participants.active = 1 AND NOT EXISTS (SELECT 1 FROM participants target WHERE target.did = vouches.subject AND target.active = 0) AND (tag = ?2 OR (CAST(?3 AS INTEGER) = 1 AND tag = '')) ORDER BY author, tag LIMIT ?4 ` type IncomingParams struct { Subject string Tag string Column3 int64 Limit int64 } func (q *Queries) Incoming(ctx context.Context, arg IncomingParams) ([]Vouch, error) { rows, err := q.query(ctx, q.incomingStmt, incoming, arg.Subject, arg.Tag, arg.Column3, arg.Limit, ) if err != nil { return nil, err } defer rows.Close() items := []Vouch{} for rows.Next() { var i Vouch if err := rows.Scan( &i.Author, &i.Subject, &i.Tag, &i.Score, &i.CreatedAt, &i.RecordKey, &i.Comment, &i.Source, ); 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 } const initCursor = `-- name: InitCursor :exec INSERT INTO stream_cursors(source, time_us) VALUES (?, ?) ON CONFLICT(source) DO NOTHING ` type InitCursorParams struct { Source string TimeUs int64 } func (q *Queries) InitCursor(ctx context.Context, arg InitCursorParams) error { _, err := q.exec(ctx, q.initCursorStmt, initCursor, arg.Source, arg.TimeUs) return err } const insertVouch = `-- name: InsertVouch :exec INSERT INTO vouches(author, subject, tag, score, created_at, record_key, comment) VALUES (?, ?, ?, ?, ?, ?, ?) ` type InsertVouchParams struct { Author string Subject string Tag string Score int64 CreatedAt string RecordKey string Comment string } func (q *Queries) InsertVouch(ctx context.Context, arg InsertVouchParams) error { _, err := q.exec(ctx, q.insertVouchStmt, insertVouch, arg.Author, arg.Subject, arg.Tag, arg.Score, arg.CreatedAt, arg.RecordKey, arg.Comment, ) return err } const join = `-- name: Join :exec INSERT INTO participants(did) VALUES (?) ON CONFLICT(did) DO NOTHING ` func (q *Queries) Join(ctx context.Context, did string) error { _, err := q.exec(ctx, q.joinStmt, join, did) return err } const joinReplaySoft = `-- name: JoinReplaySoft :exec INSERT INTO soft_accounts(did) VALUES (?) ON CONFLICT(did) DO NOTHING ` func (q *Queries) JoinReplaySoft(ctx context.Context, did int64) error { _, err := q.exec(ctx, q.joinReplaySoftStmt, joinReplaySoft, did) return err } const joinSoft = `-- name: JoinSoft :exec INSERT INTO soft_accounts(did) SELECT id FROM identities WHERE did = CAST(?1 AS TEXT) ON CONFLICT(did) DO NOTHING ` func (q *Queries) JoinSoft(ctx context.Context, did string) error { _, err := q.exec(ctx, q.joinSoftStmt, joinSoft, did) return err } const legacyKeys = `-- name: LegacyKeys :many SELECT author, subject, tag FROM vouches WHERE record_key = '' ` type LegacyKeysRow struct { Author string Subject string Tag string } func (q *Queries) LegacyKeys(ctx context.Context) ([]LegacyKeysRow, error) { rows, err := q.query(ctx, q.legacyKeysStmt, legacyKeys) if err != nil { return nil, err } defer rows.Close() items := []LegacyKeysRow{} for rows.Next() { var i LegacyKeysRow if err := rows.Scan(&i.Author, &i.Subject, &i.Tag); 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 } const listAuthorRecords = `-- name: ListAuthorRecords :many SELECT a.did AS author, r.source, r.record_key, r.list_uri, COALESCE(s.did, '') AS subject, r.purpose, r.created_at FROM list_records r JOIN identities a ON a.id = r.author LEFT JOIN identities s ON s.id = r.subject WHERE a.did = CAST(?1 AS TEXT) AND r.source = ?2 ` type ListAuthorRecordsParams struct { Author string Source string } type ListAuthorRecordsRow struct { Author string Source string RecordKey string ListUri string Subject string Purpose string CreatedAt string } func (q *Queries) ListAuthorRecords(ctx context.Context, arg ListAuthorRecordsParams) ([]ListAuthorRecordsRow, error) { rows, err := q.query(ctx, q.listAuthorRecordsStmt, listAuthorRecords, arg.Author, arg.Source) if err != nil { return nil, err } defer rows.Close() items := []ListAuthorRecordsRow{} for rows.Next() { var i ListAuthorRecordsRow if err := rows.Scan( &i.Author, &i.Source, &i.RecordKey, &i.ListUri, &i.Subject, &i.Purpose, &i.CreatedAt, ); 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 } const listBootstrap = `-- name: ListBootstrap :one SELECT bootstrap_us FROM list_bootstraps WHERE author = (SELECT id FROM identities WHERE did = CAST(?1 AS TEXT)) ` func (q *Queries) ListBootstrap(ctx context.Context, author string) (int64, error) { row := q.queryRow(ctx, q.listBootstrapStmt, listBootstrap, author) var bootstrap_us int64 err := row.Scan(&bootstrap_us) return bootstrap_us, err } const listGraph = `-- name: ListGraph :many SELECT e.author, e.subject, e.source, e.record_key, e.created_at, e.list_uri, e.list_author, e.list_key, e.item_key FROM list_edges e WHERE (CAST(?1 AS INTEGER) = 1 OR EXISTS (SELECT 1 FROM participants p WHERE p.did = e.author AND p.active = 1)) AND NOT EXISTS (SELECT 1 FROM vouches v WHERE v.author = e.author AND v.subject = e.subject AND (v.tag = ?2 OR (CAST(?3 AS INTEGER) = 1 AND v.tag = ''))) LIMIT ?4 ` type ListGraphParams struct { AllAuthors int64 Tag string Fallback int64 MaxRows int64 } func (q *Queries) ListGraph(ctx context.Context, arg ListGraphParams) ([]ListEdge, error) { rows, err := q.query(ctx, q.listGraphStmt, listGraph, arg.AllAuthors, arg.Tag, arg.Fallback, arg.MaxRows, ) if err != nil { return nil, err } defer rows.Close() items := []ListEdge{} for rows.Next() { var i ListEdge if err := rows.Scan( &i.Author, &i.Subject, &i.Source, &i.RecordKey, &i.CreatedAt, &i.ListUri, &i.ListAuthor, &i.ListKey, &i.ItemKey, ); 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 } const listIncoming = `-- name: ListIncoming :many SELECT e.author, e.subject, e.source, e.record_key, e.created_at, e.list_uri, e.list_author, e.list_key, e.item_key FROM list_edges e WHERE e.subject = ?1 AND (CAST(?2 AS INTEGER) = 1 OR EXISTS (SELECT 1 FROM participants p WHERE p.did = e.author AND p.active = 1)) AND NOT EXISTS (SELECT 1 FROM vouches v WHERE v.author = e.author AND v.subject = e.subject AND (v.tag = ?3 OR (CAST(?4 AS INTEGER) = 1 AND v.tag = ''))) ORDER BY e.author, e.list_uri LIMIT ?5 ` type ListIncomingParams struct { Subject string AllAuthors int64 Tag string Fallback int64 MaxRows int64 } func (q *Queries) ListIncoming(ctx context.Context, arg ListIncomingParams) ([]ListEdge, error) { rows, err := q.query(ctx, q.listIncomingStmt, listIncoming, arg.Subject, arg.AllAuthors, arg.Tag, arg.Fallback, arg.MaxRows, ) if err != nil { return nil, err } defer rows.Close() items := []ListEdge{} for rows.Next() { var i ListEdge if err := rows.Scan( &i.Author, &i.Subject, &i.Source, &i.RecordKey, &i.CreatedAt, &i.ListUri, &i.ListAuthor, &i.ListKey, &i.ItemKey, ); 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 } const listOutgoing = `-- name: ListOutgoing :many SELECT e.author, e.subject, e.source, e.record_key, e.created_at, e.list_uri, e.list_author, e.list_key, e.item_key FROM list_edges e WHERE e.author = ?1 AND (CAST(?2 AS INTEGER) = 1 OR EXISTS (SELECT 1 FROM participants p WHERE p.did = e.author AND p.active = 1)) AND NOT EXISTS (SELECT 1 FROM vouches v WHERE v.author = e.author AND v.subject = e.subject AND (v.tag = ?3 OR (CAST(?4 AS INTEGER) = 1 AND v.tag = ''))) LIMIT ?5 ` type ListOutgoingParams struct { Author string AllAuthors int64 Tag string Fallback int64 MaxRows int64 } func (q *Queries) ListOutgoing(ctx context.Context, arg ListOutgoingParams) ([]ListEdge, error) { rows, err := q.query(ctx, q.listOutgoingStmt, listOutgoing, arg.Author, arg.AllAuthors, arg.Tag, arg.Fallback, arg.MaxRows, ) if err != nil { return nil, err } defer rows.Close() items := []ListEdge{} for rows.Next() { var i ListEdge if err := rows.Scan( &i.Author, &i.Subject, &i.Source, &i.RecordKey, &i.CreatedAt, &i.ListUri, &i.ListAuthor, &i.ListKey, &i.ItemKey, ); 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 } const listRecord = `-- name: ListRecord :one SELECT a.did AS author, r.source, r.record_key, r.list_uri, COALESCE(s.did, '') AS subject, r.purpose, r.created_at FROM list_records r JOIN identities a ON a.id = r.author LEFT JOIN identities s ON s.id = r.subject WHERE a.did = CAST(?1 AS TEXT) AND r.source = ?2 AND r.record_key = ?3 ` type ListRecordParams struct { Author string Source string RecordKey string } type ListRecordRow struct { Author string Source string RecordKey string ListUri string Subject string Purpose string CreatedAt string } func (q *Queries) ListRecord(ctx context.Context, arg ListRecordParams) (ListRecordRow, error) { row := q.queryRow(ctx, q.listRecordStmt, listRecord, arg.Author, arg.Source, arg.RecordKey) var i ListRecordRow err := row.Scan( &i.Author, &i.Source, &i.RecordKey, &i.ListUri, &i.Subject, &i.Purpose, &i.CreatedAt, ) return i, err } const listURIRecords = `-- name: ListURIRecords :many SELECT a.did AS author, r.source, r.record_key, r.list_uri, COALESCE(s.did, '') AS subject, r.purpose, r.created_at FROM list_records r JOIN identities a ON a.id = r.author LEFT JOIN identities s ON s.id = r.subject WHERE r.list_uri = ? AND r.source != 'app.bsky.graph.listblock' ` type ListURIRecordsRow struct { Author string Source string RecordKey string ListUri string Subject string Purpose string CreatedAt string } func (q *Queries) ListURIRecords(ctx context.Context, listUri string) ([]ListURIRecordsRow, error) { rows, err := q.query(ctx, q.listURIRecordsStmt, listURIRecords, listUri) if err != nil { return nil, err } defer rows.Close() items := []ListURIRecordsRow{} for rows.Next() { var i ListURIRecordsRow if err := rows.Scan( &i.Author, &i.Source, &i.RecordKey, &i.ListUri, &i.Subject, &i.Purpose, &i.CreatedAt, ); 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 } const listVersion = `-- name: ListVersion :one SELECT time_us FROM list_versions WHERE author = (SELECT id FROM identities WHERE did = CAST(?1 AS TEXT)) AND source = ?2 AND record_key = ?3 ` type ListVersionParams struct { Author string Source string RecordKey string } func (q *Queries) ListVersion(ctx context.Context, arg ListVersionParams) (int64, error) { row := q.queryRow(ctx, q.listVersionStmt, listVersion, arg.Author, arg.Source, arg.RecordKey) var time_us int64 err := row.Scan(&time_us) return time_us, err } const listWatermark = `-- name: ListWatermark :one SELECT bootstrap_us FROM list_snapshots WHERE list_uri = ? ` func (q *Queries) ListWatermark(ctx context.Context, listUri string) (int64, error) { row := q.queryRow(ctx, q.listWatermarkStmt, listWatermark, listUri) var bootstrap_us int64 err := row.Scan(&bootstrap_us) return bootstrap_us, err } const outgoing = `-- name: Outgoing :many SELECT v.author, v.subject, v.tag, v.score, v.created_at, v.record_key, v.comment, v.source FROM vouches v JOIN participants p ON p.did = v.author WHERE v.author = ?1 AND p.active = 1 AND NOT EXISTS (SELECT 1 FROM participants target WHERE target.did = v.subject AND target.active = 0) AND (v.tag = ?2 OR (CAST(?3 AS INTEGER) = 1 AND v.tag = '')) ORDER BY v.subject, v.tag LIMIT ?4 ` type OutgoingParams struct { Author string Tag string Fallback int64 MaxRows int64 } // Outgoing reads preserve per-pair selection and use author indexes rather than a global graph scan. func (q *Queries) Outgoing(ctx context.Context, arg OutgoingParams) ([]Vouch, error) { rows, err := q.query(ctx, q.outgoingStmt, outgoing, arg.Author, arg.Tag, arg.Fallback, arg.MaxRows, ) if err != nil { return nil, err } defer rows.Close() items := []Vouch{} for rows.Next() { var i Vouch if err := rows.Scan( &i.Author, &i.Subject, &i.Tag, &i.Score, &i.CreatedAt, &i.RecordKey, &i.Comment, &i.Source, ); 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 } const ownVouches = `-- name: OwnVouches :many SELECT vouches.author, vouches.subject, vouches.tag, vouches.score, vouches.created_at, vouches.record_key, vouches.comment, vouches.source FROM vouches JOIN participants ON participants.did = vouches.author WHERE participants.active = 1 AND author = ? ORDER BY subject, tag LIMIT ? OFFSET ? ` type OwnVouchesParams struct { Author string Limit int64 Offset int64 } func (q *Queries) OwnVouches(ctx context.Context, arg OwnVouchesParams) ([]Vouch, error) { rows, err := q.query(ctx, q.ownVouchesStmt, ownVouches, arg.Author, arg.Limit, arg.Offset) if err != nil { return nil, err } defer rows.Close() items := []Vouch{} for rows.Next() { var i Vouch if err := rows.Scan( &i.Author, &i.Subject, &i.Tag, &i.Score, &i.CreatedAt, &i.RecordKey, &i.Comment, &i.Source, ); 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 } const participant = `-- name: Participant :one SELECT did, threshold, synced_at, bootstrap_us, active, account_us FROM participants WHERE did = ? ` func (q *Queries) Participant(ctx context.Context, did string) (Participant, error) { row := q.queryRow(ctx, q.participantStmt, participant, did) var i Participant err := row.Scan( &i.Did, &i.Threshold, &i.SyncedAt, &i.BootstrapUs, &i.Active, &i.AccountUs, ) return i, err } const participants = `-- name: Participants :many SELECT did, threshold, synced_at, bootstrap_us, active, account_us FROM participants ORDER BY synced_at, did LIMIT ? ` func (q *Queries) Participants(ctx context.Context, limit int64) ([]Participant, error) { rows, err := q.query(ctx, q.participantsStmt, participants, limit) if err != nil { return nil, err } defer rows.Close() items := []Participant{} for rows.Next() { var i Participant if err := rows.Scan( &i.Did, &i.Threshold, &i.SyncedAt, &i.BootstrapUs, &i.Active, &i.AccountUs, ); 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 } const pruneSecrets = `-- name: PruneSecrets :exec DELETE FROM secrets WHERE expires <= ? ` func (q *Queries) PruneSecrets(ctx context.Context, expires int64) error { _, err := q.exec(ctx, q.pruneSecretsStmt, pruneSecrets, expires) return err } const putIdentity = `-- name: PutIdentity :exec INSERT INTO identities(did) VALUES (?) ON CONFLICT(did) DO NOTHING ` func (q *Queries) PutIdentity(ctx context.Context, did string) error { _, err := q.exec(ctx, q.putIdentityStmt, putIdentity, did) return err } const putListBootstrap = `-- name: PutListBootstrap :exec INSERT INTO list_bootstraps(author, bootstrap_us) VALUES ((SELECT id FROM identities WHERE did = CAST(?1 AS TEXT)), ?2) ON CONFLICT(author) DO UPDATE SET bootstrap_us = excluded.bootstrap_us ` type PutListBootstrapParams struct { Author string BootstrapUs int64 } func (q *Queries) PutListBootstrap(ctx context.Context, arg PutListBootstrapParams) error { _, err := q.exec(ctx, q.putListBootstrapStmt, putListBootstrap, arg.Author, arg.BootstrapUs) return err } const putListRecord = `-- name: PutListRecord :exec INSERT INTO list_records(author, source, record_key, list_uri, subject, purpose, created_at) VALUES ((SELECT id FROM identities WHERE did = CAST(?1 AS TEXT)), ?2, ?3, ?4, (SELECT id FROM identities WHERE did = NULLIF(CAST(?5 AS TEXT), '')), ?6, ?7) ON CONFLICT(author, source, record_key) DO UPDATE SET list_uri = excluded.list_uri, subject = excluded.subject, purpose = excluded.purpose, created_at = excluded.created_at WHERE list_uri != excluded.list_uri OR subject IS NOT excluded.subject OR purpose != excluded.purpose OR created_at != excluded.created_at ` type PutListRecordParams struct { Author string Source string RecordKey string ListUri string Subject string Purpose string CreatedAt string } func (q *Queries) PutListRecord(ctx context.Context, arg PutListRecordParams) error { _, err := q.exec(ctx, q.putListRecordStmt, putListRecord, arg.Author, arg.Source, arg.RecordKey, arg.ListUri, arg.Subject, arg.Purpose, arg.CreatedAt, ) return err } const putListVersion = `-- name: PutListVersion :exec INSERT INTO list_versions(author, source, record_key, time_us) VALUES ((SELECT id FROM identities WHERE did = CAST(?1 AS TEXT)), ?2, ?3, ?4) ON CONFLICT(author, source, record_key) DO UPDATE SET time_us = excluded.time_us ` type PutListVersionParams struct { Author string Source string RecordKey string TimeUs int64 } func (q *Queries) PutListVersion(ctx context.Context, arg PutListVersionParams) error { _, err := q.exec(ctx, q.putListVersionStmt, putListVersion, arg.Author, arg.Source, arg.RecordKey, arg.TimeUs, ) return err } const putListWatermark = `-- name: PutListWatermark :exec INSERT INTO list_snapshots(list_uri, owner, bootstrap_us) VALUES (?1, (SELECT id FROM identities WHERE did = CAST(?2 AS TEXT)), ?3) ON CONFLICT(list_uri) DO UPDATE SET bootstrap_us = excluded.bootstrap_us ` type PutListWatermarkParams struct { ListUri string Owner string BootstrapUs int64 } func (q *Queries) PutListWatermark(ctx context.Context, arg PutListWatermarkParams) error { _, err := q.exec(ctx, q.putListWatermarkStmt, putListWatermark, arg.ListUri, arg.Owner, arg.BootstrapUs) return err } const putSecret = `-- name: PutSecret :exec INSERT INTO secrets(kind, id, value, expires) VALUES (?, ?, ?, ?) ON CONFLICT(kind, id) DO UPDATE SET value = excluded.value, expires = excluded.expires ` type PutSecretParams struct { Kind string ID string Value []byte Expires int64 } func (q *Queries) PutSecret(ctx context.Context, arg PutSecretParams) error { _, err := q.exec(ctx, q.putSecretStmt, putSecret, arg.Kind, arg.ID, arg.Value, arg.Expires, ) return err } const recordVersion = `-- name: RecordVersion :one SELECT time_us FROM record_versions WHERE author = ? AND record_key = ? ` type RecordVersionParams struct { Author string RecordKey string } func (q *Queries) RecordVersion(ctx context.Context, arg RecordVersionParams) (int64, error) { row := q.queryRow(ctx, q.recordVersionStmt, recordVersion, arg.Author, arg.RecordKey) var time_us int64 err := row.Scan(&time_us) return time_us, err } const removeSecret = `-- name: RemoveSecret :exec DELETE FROM secrets WHERE kind = ? AND id = ? ` type RemoveSecretParams struct { Kind string ID string } func (q *Queries) RemoveSecret(ctx context.Context, arg RemoveSecretParams) error { _, err := q.exec(ctx, q.removeSecretStmt, removeSecret, arg.Kind, arg.ID) return err } const replaceReplaySoft = `-- name: ReplaceReplaySoft :exec INSERT INTO soft_vouches(author, subject, source, record_key, score, created_at) VALUES (?1, (SELECT id FROM identities WHERE did = CAST(?2 AS TEXT)), ?3, ?4, ?5, ?6) ON CONFLICT(author, source, record_key) DO UPDATE SET subject = excluded.subject, score = excluded.score, created_at = excluded.created_at WHERE subject != excluded.subject OR score != excluded.score OR created_at != excluded.created_at ` type ReplaceReplaySoftParams struct { Author int64 Subject string Source string RecordKey string Score float64 CreatedAt string } func (q *Queries) ReplaceReplaySoft(ctx context.Context, arg ReplaceReplaySoftParams) error { _, err := q.exec(ctx, q.replaceReplaySoftStmt, replaceReplaySoft, arg.Author, arg.Subject, arg.Source, arg.RecordKey, arg.Score, arg.CreatedAt, ) return err } const replaceSoft = `-- name: ReplaceSoft :exec INSERT INTO soft_vouches(author, subject, source, record_key, score, created_at) VALUES ((SELECT id FROM identities WHERE did = CAST(?1 AS TEXT)), (SELECT id FROM identities WHERE did = CAST(?2 AS TEXT)), ?3, ?4, ?5, ?6) ON CONFLICT(author, source, record_key) DO UPDATE SET subject = excluded.subject, score = excluded.score, created_at = excluded.created_at WHERE subject != excluded.subject OR score != excluded.score OR created_at != excluded.created_at ` type ReplaceSoftParams struct { Author string Subject string Source string RecordKey string Score float64 CreatedAt string } func (q *Queries) ReplaceSoft(ctx context.Context, arg ReplaceSoftParams) error { _, err := q.exec(ctx, q.replaceSoftStmt, replaceSoft, arg.Author, arg.Subject, arg.Source, arg.RecordKey, arg.Score, arg.CreatedAt, ) return err } const replaceVouch = `-- name: ReplaceVouch :exec INSERT INTO vouches(author, subject, tag, score, created_at, record_key, comment) VALUES (?, ?, ?, ?, ?, ?, ?) ON CONFLICT(author, subject, tag) DO UPDATE SET score = excluded.score, created_at = excluded.created_at, record_key = excluded.record_key, comment = excluded.comment WHERE score != excluded.score OR created_at != excluded.created_at OR record_key != excluded.record_key OR comment != excluded.comment ` type ReplaceVouchParams struct { Author string Subject string Tag string Score int64 CreatedAt string RecordKey string Comment string } func (q *Queries) ReplaceVouch(ctx context.Context, arg ReplaceVouchParams) error { _, err := q.exec(ctx, q.replaceVouchStmt, replaceVouch, arg.Author, arg.Subject, arg.Tag, arg.Score, arg.CreatedAt, arg.RecordKey, arg.Comment, ) return err } const replayClearLists = `-- name: ReplayClearLists :exec DELETE FROM list_records WHERE author = (SELECT id FROM identities WHERE did = CAST(?1 AS TEXT)) AND NOT EXISTS (SELECT 1 FROM list_snapshots s WHERE s.list_uri = list_records.list_uri AND s.bootstrap_us >= ?2) AND (source != 'app.bsky.graph.listblock' OR NOT EXISTS (SELECT 1 FROM list_bootstraps b WHERE b.author = list_records.author AND b.bootstrap_us >= ?2)) ` type ReplayClearListsParams struct { Author string TimeUs int64 } func (q *Queries) ReplayClearLists(ctx context.Context, arg ReplayClearListsParams) error { _, err := q.exec(ctx, q.replayClearListsStmt, replayClearLists, arg.Author, arg.TimeUs) return err } const replayIndexState = `-- name: ReplayIndexState :one SELECT source, deferred FROM replay_indexes WHERE singleton = 1 ` type ReplayIndexStateRow struct { Source string Deferred int64 } func (q *Queries) ReplayIndexState(ctx context.Context) (ReplayIndexStateRow, error) { row := q.queryRow(ctx, q.replayIndexStateStmt, replayIndexState) var i ReplayIndexStateRow err := row.Scan(&i.Source, &i.Deferred) return i, err } const replaySequence = `-- name: ReplaySequence :one SELECT i.id, CAST(COALESCE(r.sequence, 0) AS INTEGER) AS sequence FROM identities i LEFT JOIN replay_accounts r ON r.author = i.id AND r.source = ?1 WHERE i.did = CAST(?2 AS TEXT) ` type ReplaySequenceParams struct { Source string Author string } type ReplaySequenceRow struct { ID int64 Sequence int64 } func (q *Queries) ReplaySequence(ctx context.Context, arg ReplaySequenceParams) (ReplaySequenceRow, error) { row := q.queryRow(ctx, q.replaySequenceStmt, replaySequence, arg.Source, arg.Author) var i ReplaySequenceRow err := row.Scan(&i.ID, &i.Sequence) return i, err } const resumeTrustInvalidation = `-- name: ResumeTrustInvalidation :exec UPDATE cache_policy SET deferred = 0 WHERE singleton = 1 ` func (q *Queries) ResumeTrustInvalidation(ctx context.Context) error { _, err := q.exec(ctx, q.resumeTrustInvalidationStmt, resumeTrustInvalidation) return err } const saveDependency = `-- name: SaveDependency :exec INSERT OR IGNORE INTO trust_dependencies(cache_key, author, source, record_key) VALUES (?1, (SELECT id FROM identities WHERE did = CAST(?2 AS TEXT)), ?3, ?4) ` type SaveDependencyParams struct { CacheKey string Author string Source string RecordKey string } func (q *Queries) SaveDependency(ctx context.Context, arg SaveDependencyParams) error { _, err := q.exec(ctx, q.saveDependencyStmt, saveDependency, arg.CacheKey, arg.Author, arg.Source, arg.RecordKey, ) return err } const saveTrust = `-- name: SaveTrust :exec INSERT INTO trust_cache(cache_key, status, score, expires_us) VALUES (?, ?, ?, ?) ` type SaveTrustParams struct { CacheKey string Status string Score sql.NullFloat64 ExpiresUs int64 } func (q *Queries) SaveTrust(ctx context.Context, arg SaveTrustParams) error { _, err := q.exec(ctx, q.saveTrustStmt, saveTrust, arg.CacheKey, arg.Status, arg.Score, arg.ExpiresUs, ) return err } const saveTrustPath = `-- name: SaveTrustPath :exec INSERT INTO trust_cache_paths(cache_key, position, did) VALUES (?, ?, ?) ` type SaveTrustPathParams struct { CacheKey string Position int64 Did string } func (q *Queries) SaveTrustPath(ctx context.Context, arg SaveTrustPathParams) error { _, err := q.exec(ctx, q.saveTrustPathStmt, saveTrustPath, arg.CacheKey, arg.Position, arg.Did) return err } const saveTrustScore = `-- name: SaveTrustScore :exec INSERT INTO trust_cache_scores(cache_key, position, did, assertion, source, list_uri, score, comment) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ` type SaveTrustScoreParams struct { CacheKey string Position int64 Did string Assertion sql.NullFloat64 Source string ListUri string Score float64 Comment string } func (q *Queries) SaveTrustScore(ctx context.Context, arg SaveTrustScoreParams) error { _, err := q.exec(ctx, q.saveTrustScoreStmt, saveTrustScore, arg.CacheKey, arg.Position, arg.Did, arg.Assertion, arg.Source, arg.ListUri, arg.Score, arg.Comment, ) return err } const setAccount = `-- name: SetAccount :exec UPDATE participants SET active = ?, account_us = ?, synced_at = ? WHERE did = ? ` type SetAccountParams struct { Active int64 AccountUs int64 SyncedAt string Did string } func (q *Queries) SetAccount(ctx context.Context, arg SetAccountParams) error { _, err := q.exec(ctx, q.setAccountStmt, setAccount, arg.Active, arg.AccountUs, arg.SyncedAt, arg.Did, ) return err } const setBootstrap = `-- name: SetBootstrap :exec UPDATE participants SET bootstrap_us = ?, account_us = ?, active = 1, synced_at = ? WHERE did = ? ` type SetBootstrapParams struct { BootstrapUs int64 AccountUs int64 SyncedAt string Did string } func (q *Queries) SetBootstrap(ctx context.Context, arg SetBootstrapParams) error { _, err := q.exec(ctx, q.setBootstrapStmt, setBootstrap, arg.BootstrapUs, arg.AccountUs, arg.SyncedAt, arg.Did, ) return err } const setDeleted = `-- name: SetDeleted :exec UPDATE participants SET active = 0, account_us = ?, bootstrap_us = ?, synced_at = ? WHERE did = ? ` type SetDeletedParams struct { AccountUs int64 BootstrapUs int64 SyncedAt string Did string } func (q *Queries) SetDeleted(ctx context.Context, arg SetDeletedParams) error { _, err := q.exec(ctx, q.setDeletedStmt, setDeleted, arg.AccountUs, arg.BootstrapUs, arg.SyncedAt, arg.Did, ) return err } const setLegacyKey = `-- name: SetLegacyKey :exec UPDATE vouches SET record_key = ? WHERE author = ? AND subject = ? AND tag = ? ` type SetLegacyKeyParams struct { RecordKey string Author string Subject string Tag string } func (q *Queries) SetLegacyKey(ctx context.Context, arg SetLegacyKeyParams) error { _, err := q.exec(ctx, q.setLegacyKeyStmt, setLegacyKey, arg.RecordKey, arg.Author, arg.Subject, arg.Tag, ) return err } const setRecordVersion = `-- name: SetRecordVersion :exec INSERT INTO record_versions(author, record_key, time_us) VALUES (?, ?, ?) ON CONFLICT(author, record_key) DO UPDATE SET time_us = excluded.time_us ` type SetRecordVersionParams struct { Author string RecordKey string TimeUs int64 } func (q *Queries) SetRecordVersion(ctx context.Context, arg SetRecordVersionParams) error { _, err := q.exec(ctx, q.setRecordVersionStmt, setRecordVersion, arg.Author, arg.RecordKey, arg.TimeUs) return err } const setReplaySoftVersion = `-- name: SetReplaySoftVersion :exec INSERT INTO soft_versions(author, source, record_key, time_us) VALUES (?1, ?2, ?3, ?4) ON CONFLICT(author, source, record_key) DO UPDATE SET time_us = excluded.time_us ` type SetReplaySoftVersionParams struct { Author int64 Source string RecordKey string TimeUs int64 } func (q *Queries) SetReplaySoftVersion(ctx context.Context, arg SetReplaySoftVersionParams) error { _, err := q.exec(ctx, q.setReplaySoftVersionStmt, setReplaySoftVersion, arg.Author, arg.Source, arg.RecordKey, arg.TimeUs, ) return err } const setSoftVersion = `-- name: SetSoftVersion :exec INSERT INTO soft_versions(author, source, record_key, time_us) VALUES ((SELECT id FROM identities WHERE did = CAST(?1 AS TEXT)), ?2, ?3, ?4) ON CONFLICT(author, source, record_key) DO UPDATE SET time_us = excluded.time_us ` type SetSoftVersionParams struct { Author string Source string RecordKey string TimeUs int64 } func (q *Queries) SetSoftVersion(ctx context.Context, arg SetSoftVersionParams) error { _, err := q.exec(ctx, q.setSoftVersionStmt, setSoftVersion, arg.Author, arg.Source, arg.RecordKey, arg.TimeUs, ) return err } const setSynced = `-- name: SetSynced :exec UPDATE participants SET synced_at = ? WHERE did = ? ` type SetSyncedParams struct { SyncedAt string Did string } func (q *Queries) SetSynced(ctx context.Context, arg SetSyncedParams) error { _, err := q.exec(ctx, q.setSyncedStmt, setSynced, arg.SyncedAt, arg.Did) return err } const setThreshold = `-- name: SetThreshold :execrows UPDATE participants SET threshold = ? WHERE did = ? ` type SetThresholdParams struct { Threshold float64 Did string } func (q *Queries) SetThreshold(ctx context.Context, arg SetThresholdParams) (int64, error) { result, err := q.exec(ctx, q.setThresholdStmt, setThreshold, arg.Threshold, arg.Did) if err != nil { return 0, err } return result.RowsAffected() } const softAccount = `-- name: SoftAccount :one SELECT i.did, a.active, a.account_us, a.bootstrap_us FROM soft_accounts a JOIN identities i ON i.id = a.did WHERE i.did = ? ` type SoftAccountRow struct { Did string Active int64 AccountUs int64 BootstrapUs int64 } func (q *Queries) SoftAccount(ctx context.Context, did string) (SoftAccountRow, error) { row := q.queryRow(ctx, q.softAccountStmt, softAccount, did) var i SoftAccountRow err := row.Scan( &i.Did, &i.Active, &i.AccountUs, &i.BootstrapUs, ) return i, err } const softAccountState = `-- name: SoftAccountState :exec UPDATE soft_accounts SET active = ?1, account_us = ?2 WHERE did = (SELECT id FROM identities WHERE did = CAST(?3 AS TEXT)) ` type SoftAccountStateParams struct { Active int64 AccountUs int64 Did string } func (q *Queries) SoftAccountState(ctx context.Context, arg SoftAccountStateParams) error { _, err := q.exec(ctx, q.softAccountStateStmt, softAccountState, arg.Active, arg.AccountUs, arg.Did) return err } const softBootstrap = `-- name: SoftBootstrap :exec UPDATE soft_accounts SET active = 1, account_us = ?1, bootstrap_us = ?2 WHERE did = (SELECT id FROM identities WHERE did = CAST(?3 AS TEXT)) ` type SoftBootstrapParams struct { AccountUs int64 BootstrapUs int64 Did string } func (q *Queries) SoftBootstrap(ctx context.Context, arg SoftBootstrapParams) error { _, err := q.exec(ctx, q.softBootstrapStmt, softBootstrap, arg.AccountUs, arg.BootstrapUs, arg.Did) return err } const softDeleted = `-- name: SoftDeleted :exec UPDATE soft_accounts SET active = 0, account_us = ?1, bootstrap_us = ?2 WHERE did = (SELECT id FROM identities WHERE did = CAST(?3 AS TEXT)) ` type SoftDeletedParams struct { AccountUs int64 BootstrapUs int64 Did string } func (q *Queries) SoftDeleted(ctx context.Context, arg SoftDeletedParams) error { _, err := q.exec(ctx, q.softDeletedStmt, softDeleted, arg.AccountUs, arg.BootstrapUs, arg.Did) return err } const softGraph = `-- name: SoftGraph :many SELECT s.author, s.subject, s.source, s.record_key, s.score, s.created_at FROM soft_edges s WHERE (CAST(?1 AS INTEGER) = 1 OR EXISTS (SELECT 1 FROM participants p WHERE p.did = s.author AND p.active = 1)) AND NOT EXISTS (SELECT 1 FROM vouches v WHERE v.author = s.author AND v.subject = s.subject AND (v.tag = ?2 OR (CAST(?3 AS INTEGER) = 1 AND v.tag = ''))) LIMIT ?4 ` type SoftGraphParams struct { AllAuthors int64 Tag string Fallback int64 MaxRows int64 } // The caller sorts complete results. Avoid a global DID sort before the edge limit. func (q *Queries) SoftGraph(ctx context.Context, arg SoftGraphParams) ([]SoftEdge, error) { rows, err := q.query(ctx, q.softGraphStmt, softGraph, arg.AllAuthors, arg.Tag, arg.Fallback, arg.MaxRows, ) if err != nil { return nil, err } defer rows.Close() items := []SoftEdge{} for rows.Next() { var i SoftEdge if err := rows.Scan( &i.Author, &i.Subject, &i.Source, &i.RecordKey, &i.Score, &i.CreatedAt, ); 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 } const softIncoming = `-- name: SoftIncoming :many SELECT s.author, s.subject, s.source, s.record_key, s.score, s.created_at FROM soft_edges s WHERE s.subject = ?1 AND (CAST(?2 AS INTEGER) = 1 OR EXISTS (SELECT 1 FROM participants p WHERE p.did = s.author AND p.active = 1)) AND NOT EXISTS (SELECT 1 FROM vouches v WHERE v.author = s.author AND v.subject = s.subject AND (v.tag = ?3 OR (CAST(?4 AS INTEGER) = 1 AND v.tag = ''))) ORDER BY s.author LIMIT ?5 ` type SoftIncomingParams struct { Subject string AllAuthors int64 Tag string Fallback int64 MaxRows int64 } func (q *Queries) SoftIncoming(ctx context.Context, arg SoftIncomingParams) ([]SoftEdge, error) { rows, err := q.query(ctx, q.softIncomingStmt, softIncoming, arg.Subject, arg.AllAuthors, arg.Tag, arg.Fallback, arg.MaxRows, ) if err != nil { return nil, err } defer rows.Close() items := []SoftEdge{} for rows.Next() { var i SoftEdge if err := rows.Scan( &i.Author, &i.Subject, &i.Source, &i.RecordKey, &i.Score, &i.CreatedAt, ); 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 } const softOutgoing = `-- name: SoftOutgoing :many SELECT s.author, s.subject, s.source, s.record_key, s.score, s.created_at FROM soft_edges s WHERE s.author = ?1 AND (CAST(?2 AS INTEGER) = 1 OR EXISTS (SELECT 1 FROM participants p WHERE p.did = s.author AND p.active = 1)) AND NOT EXISTS (SELECT 1 FROM vouches v WHERE v.author = s.author AND v.subject = s.subject AND (v.tag = ?3 OR (CAST(?4 AS INTEGER) = 1 AND v.tag = ''))) LIMIT ?5 ` type SoftOutgoingParams struct { Author string AllAuthors int64 Tag string Fallback int64 MaxRows int64 } func (q *Queries) SoftOutgoing(ctx context.Context, arg SoftOutgoingParams) ([]SoftEdge, error) { rows, err := q.query(ctx, q.softOutgoingStmt, softOutgoing, arg.Author, arg.AllAuthors, arg.Tag, arg.Fallback, arg.MaxRows, ) if err != nil { return nil, err } defer rows.Close() items := []SoftEdge{} for rows.Next() { var i SoftEdge if err := rows.Scan( &i.Author, &i.Subject, &i.Source, &i.RecordKey, &i.Score, &i.CreatedAt, ); 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 } const softRecords = `-- name: SoftRecords :many SELECT author, subject, source, record_key, score, created_at FROM soft_vouches WHERE author = (SELECT id FROM identities WHERE did = CAST(?1 AS TEXT)) ` func (q *Queries) SoftRecords(ctx context.Context, author string) ([]SoftVouch, error) { rows, err := q.query(ctx, q.softRecordsStmt, softRecords, author) if err != nil { return nil, err } defer rows.Close() items := []SoftVouch{} for rows.Next() { var i SoftVouch if err := rows.Scan( &i.Author, &i.Subject, &i.Source, &i.RecordKey, &i.Score, &i.CreatedAt, ); 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 } const softReplayState = `-- name: SoftReplayState :one SELECT a.bootstrap_us, v.time_us FROM (SELECT CAST(?1 AS INTEGER) AS id) i LEFT JOIN soft_accounts a ON a.did = i.id LEFT JOIN soft_versions v ON v.author = i.id AND v.source = ?2 AND v.record_key = ?3 ` type SoftReplayStateParams struct { Author int64 Source string RecordKey string } type SoftReplayStateRow struct { BootstrapUs sql.NullInt64 TimeUs sql.NullInt64 } func (q *Queries) SoftReplayState(ctx context.Context, arg SoftReplayStateParams) (SoftReplayStateRow, error) { row := q.queryRow(ctx, q.softReplayStateStmt, softReplayState, arg.Author, arg.Source, arg.RecordKey) var i SoftReplayStateRow err := row.Scan(&i.BootstrapUs, &i.TimeUs) return i, err } const softVersion = `-- name: SoftVersion :one SELECT time_us FROM soft_versions WHERE author = (SELECT id FROM identities WHERE did = CAST(?1 AS TEXT)) AND source = ?2 AND record_key = ?3 ` type SoftVersionParams struct { Author string Source string RecordKey string } func (q *Queries) SoftVersion(ctx context.Context, arg SoftVersionParams) (int64, error) { row := q.queryRow(ctx, q.softVersionStmt, softVersion, arg.Author, arg.Source, arg.RecordKey) var time_us int64 err := row.Scan(&time_us) return time_us, err } const tags = `-- name: Tags :many SELECT DISTINCT tag FROM vouches JOIN participants ON participants.did = vouches.author WHERE participants.active = 1 AND tag != '' AND substr(tag, 1, length(CAST(?1 AS TEXT))) = CAST(?1 AS TEXT) ORDER BY tag LIMIT ?2 ` type TagsParams struct { Prefix string MaxRows int64 } func (q *Queries) Tags(ctx context.Context, arg TagsParams) ([]string, error) { rows, err := q.query(ctx, q.tagsStmt, tags, arg.Prefix, arg.MaxRows) if err != nil { return nil, err } defer rows.Close() items := []string{} for rows.Next() { var tag string if err := rows.Scan(&tag); err != nil { return nil, err } items = append(items, tag) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } const trustCachePath = `-- name: TrustCachePath :many SELECT did FROM trust_cache_paths WHERE cache_key = ? ORDER BY position ` func (q *Queries) TrustCachePath(ctx context.Context, cacheKey string) ([]string, error) { rows, err := q.query(ctx, q.trustCachePathStmt, trustCachePath, cacheKey) if err != nil { return nil, err } defer rows.Close() items := []string{} for rows.Next() { var did string if err := rows.Scan(&did); err != nil { return nil, err } items = append(items, did) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } const trustCacheScores = `-- name: TrustCacheScores :many SELECT did, assertion, source, list_uri, score, comment FROM trust_cache_scores WHERE cache_key = ? ORDER BY position ` type TrustCacheScoresRow struct { Did string Assertion sql.NullFloat64 Source string ListUri string Score float64 Comment string } func (q *Queries) TrustCacheScores(ctx context.Context, cacheKey string) ([]TrustCacheScoresRow, error) { rows, err := q.query(ctx, q.trustCacheScoresStmt, trustCacheScores, cacheKey) if err != nil { return nil, err } defer rows.Close() items := []TrustCacheScoresRow{} for rows.Next() { var i TrustCacheScoresRow if err := rows.Scan( &i.Did, &i.Assertion, &i.Source, &i.ListUri, &i.Score, &i.Comment, ); 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 } const wantsListOwner = `-- name: WantsListOwner :one SELECT EXISTS(SELECT 1 FROM list_snapshots WHERE owner = (SELECT id FROM identities WHERE did = CAST(?1 AS TEXT))) AS wanted ` func (q *Queries) WantsListOwner(ctx context.Context, owner string) (bool, error) { row := q.queryRow(ctx, q.wantsListOwnerStmt, wantsListOwner, owner) var wanted bool err := row.Scan(&wanted) return wanted, err } const wantsListURI = `-- name: WantsListURI :one SELECT EXISTS(SELECT 1 FROM list_snapshots WHERE list_uri = ?) AS wanted ` func (q *Queries) WantsListURI(ctx context.Context, listUri string) (bool, error) { row := q.queryRow(ctx, q.wantsListURIStmt, wantsListURI, listUri) var wanted bool err := row.Scan(&wanted) return wanted, err }