mirror of
https://github.com/MeshCore-Beacon/beacon-server.git
synced 2026-09-01 16:48:19 +00:00
251 lines
16 KiB
Go
251 lines
16 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
type Querier interface {
|
|
// Keeps the channel IATA filter in step with packet retention.
|
|
DeleteOldChannelIATAs(ctx context.Context, lastHeard pgtype.Timestamptz) error
|
|
// Deletes packets and their observations older than the given cutoff.
|
|
// packet_observations cascade-delete via FK.
|
|
DeleteOldPackets(ctx context.Context, lastHeardAt pgtype.Timestamptz) error
|
|
// Deletes telemetry rows older than the given cutoff. Called by the cleanup goroutine.
|
|
DeleteOldTelemetry(ctx context.Context, reportedAt pgtype.Timestamptz) error
|
|
// Keeps the trace IATA filter in step with packet retention.
|
|
DeleteOldTraceIATAs(ctx context.Context, lastHeard pgtype.Timestamptz) error
|
|
GetChannelByID(ctx context.Context, id int32) (Channel, error)
|
|
// Returns neighbors of a node that are in a different IATA.
|
|
GetCrossIATANeighbors(ctx context.Context, arg GetCrossIATANeighborsParams) ([]GetCrossIATANeighborsRow, error)
|
|
GetHourlyStats(ctx context.Context, arg GetHourlyStatsParams) ([]MvHourlyIataStat, error)
|
|
GetIATA(ctx context.Context, iata string) (IataCode, error)
|
|
GetKnownRoutesByNode(ctx context.Context, arg GetKnownRoutesByNodeParams) ([]KnownRoute, error)
|
|
GetNodeByID(ctx context.Context, id uuid.UUID) (GetNodeByIDRow, error)
|
|
GetNodeByPubkey(ctx context.Context, publicKey []byte) (uuid.UUID, error)
|
|
// Returns the neighbors of a node with details, ordered by most recently seen.
|
|
GetNodeNeighbors(ctx context.Context, nodeID uuid.UUID) ([]GetNodeNeighborsRow, error)
|
|
GetNodesByIDs(ctx context.Context, dollar_1 []uuid.UUID) ([]GetNodesByIDsRow, error)
|
|
GetObserverBrokers(ctx context.Context, observerID uuid.UUID) ([]GetObserverBrokersRow, error)
|
|
GetObserverByID(ctx context.Context, id uuid.UUID) (Observer, error)
|
|
GetObserverByPubkey(ctx context.Context, publicKey []byte) (Observer, error)
|
|
GetObserverLastIATA(ctx context.Context, observerID uuid.UUID) (string, error)
|
|
GetObserverRadio(ctx context.Context, id uuid.UUID) (GetObserverRadioRow, error)
|
|
GetObserverScopes(ctx context.Context, observerID uuid.UUID) ([]string, error)
|
|
GetObserverTelemetry(ctx context.Context, arg GetObserverTelemetryParams) ([]GetObserverTelemetryRow, error)
|
|
GetObserverTelemetryBucketed(ctx context.Context, arg GetObserverTelemetryBucketedParams) ([]GetObserverTelemetryBucketedRow, error)
|
|
GetPacketByHash(ctx context.Context, packetHash []byte) (GetPacketByHashRow, error)
|
|
GetPacketObservationCount(ctx context.Context, packetHash []byte) (int64, error)
|
|
// Returns all packets for a given trace tag with observations.
|
|
GetPacketsByTraceTag(ctx context.Context, decode string) ([]GetPacketsByTraceTagRow, error)
|
|
GetRadioPresets(ctx context.Context, arg GetRadioPresetsParams) ([]MvRadioPreset, error)
|
|
GetRegion(ctx context.Context, id int32) (GetRegionRow, error)
|
|
GetRegionBySlug(ctx context.Context, slug string) (GetRegionBySlugRow, error)
|
|
GetRegionIATAs(ctx context.Context, regionID int32) ([]string, error)
|
|
GetScopeByName(ctx context.Context, name string) (GetScopeByNameRow, error)
|
|
GetScopeNames(ctx context.Context) ([]string, error)
|
|
// Count each table on its own; the old cross-join blew up to millions of rows
|
|
// before COUNT(DISTINCT) (~10s).
|
|
GetScopeStats(ctx context.Context) ([]GetScopeStatsRow, error)
|
|
GetScopesByIATAs(ctx context.Context, dollar_1 []string) ([]GetScopesByIATAsRow, error)
|
|
// Returns node counts grouped by type, optionally filtered by IATA.
|
|
GetStatsNodeTypes(ctx context.Context, dollar_1 []string) ([]GetStatsNodeTypesRow, error)
|
|
// ============================================================
|
|
// STATS
|
|
// ============================================================
|
|
GetStatsOverview(ctx context.Context, dollar_1 []string) (GetStatsOverviewRow, error)
|
|
// Payload-type counts for the IATA, from the precomputed view.
|
|
GetStatsPayloadBreakdown(ctx context.Context, dollar_1 []string) ([]GetStatsPayloadBreakdownRow, error)
|
|
// Returns the top N nodes by distinct ADVERT packet count for the given window and IATA.
|
|
// COUNT(DISTINCT p.packet_hash) rather than COUNT(*): the same advert broadcast is commonly
|
|
// heard by more than one observer, and each hearing is its own packet_observations row --
|
|
// this counts adverts sent, not adverts heard.
|
|
GetStatsTopAdvertisers(ctx context.Context, arg GetStatsTopAdvertisersParams) ([]GetStatsTopAdvertisersRow, error)
|
|
// Returns the top N observers by observation count for the given window and IATA.
|
|
GetStatsTopObservers(ctx context.Context, arg GetStatsTopObserversParams) ([]GetStatsTopObserversRow, error)
|
|
// Returns the top N companion names by decrypted channel message count for the given
|
|
// window and IATA. Grouped by sender_name as decrypted from the message itself, not by
|
|
// node identity -- distinct pubkeys sharing a display name are counted together, and a
|
|
// pubkey that changes its display name is split across rows. COUNT(DISTINCT cm.id) guards
|
|
// against the same message being multiplied by the packet_observations join.
|
|
GetStatsTopTalkers(ctx context.Context, arg GetStatsTopTalkersParams) ([]GetStatsTopTalkersRow, error)
|
|
GetTopNodes(ctx context.Context, arg GetTopNodesParams) ([]MvTopNodesByIatum, error)
|
|
GetTransportScopeByName(ctx context.Context, name string) (int32, error)
|
|
GetTransportScopes(ctx context.Context) ([]GetTransportScopesRow, error)
|
|
// ============================================================
|
|
// CHANNEL MESSAGES
|
|
// ============================================================
|
|
InsertChannelMessage(ctx context.Context, arg InsertChannelMessageParams) (int64, error)
|
|
// ============================================================
|
|
// PACKET OBSERVATIONS
|
|
// ============================================================
|
|
InsertObservation(ctx context.Context, arg InsertObservationParams) (PacketObservation, error)
|
|
// Inserts a telemetry snapshot for an observer. The reported_at timestamp should
|
|
// be truncated to the configured resolution before calling to ensure deduplication.
|
|
InsertObserverTelemetry(ctx context.Context, arg InsertObserverTelemetryParams) error
|
|
// Returns all messages across all channels with optional time, IATA, scope and cursor filters.
|
|
// Pass empty string for iata or scope to skip those filters.
|
|
// Pass cursor=0 to start from the beginning.
|
|
ListAllChannelMessages(ctx context.Context, arg ListAllChannelMessagesParams) ([]ListAllChannelMessagesRow, error)
|
|
// Returns messages for a channel identified by integer ID.
|
|
// Pass a zero/null timestamp for since to return all messages up to limit.
|
|
// Pass empty string for iata to skip IATA filtering.
|
|
// Pass cursor=0 to start from the beginning.
|
|
ListChannelMessages(ctx context.Context, arg ListChannelMessagesParams) ([]ListChannelMessagesRow, error)
|
|
// Returns messages for all channels matching a hash byte.
|
|
// May return messages from multiple channels if the hash collides across different keys.
|
|
// Pass empty string for iata or scope to skip those filters.
|
|
// Pass cursor=0 to start from the beginning.
|
|
ListChannelMessagesByHash(ctx context.Context, arg ListChannelMessagesByHashParams) ([]ListChannelMessagesByHashRow, error)
|
|
// Channels ordered by last seen, optionally filtered by hash and/or IATAs
|
|
// (membership via channel_iatas). NULL hash / empty array skip those filters.
|
|
// Pass cursor=0 to start from the beginning (cursor is last_seen epoch ms).
|
|
ListChannels(ctx context.Context, arg ListChannelsParams) ([]Channel, error)
|
|
ListIATAs(ctx context.Context) ([]IataCode, error)
|
|
ListKnownRoutes(ctx context.Context, arg ListKnownRoutesParams) ([]KnownRoute, error)
|
|
// Returns messages after the given message ID, ordered oldest first.
|
|
// Used for WS reconnect backfill.
|
|
ListMessagesAfterID(ctx context.Context, arg ListMessagesAfterIDParams) ([]ListMessagesAfterIDRow, error)
|
|
ListNodeObservations(ctx context.Context, arg ListNodeObservationsParams) ([]ListNodeObservationsRow, error)
|
|
ListNodes(ctx context.Context, arg ListNodesParams) ([]ListNodesRow, error)
|
|
ListObservationsForPacket(ctx context.Context, packetHash []byte) ([]ListObservationsForPacketRow, error)
|
|
// Returns advert packets (payload_type=4) heard by a specific observer.
|
|
// Pass cursor=0 to start from the beginning, or the last seen id for pagination.
|
|
ListObserverAdverts(ctx context.Context, arg ListObserverAdvertsParams) ([]ListObserverAdvertsRow, error)
|
|
// Pass cursor=0 to start from the beginning, or the last seen observer's rownum for pagination.
|
|
// Note: observers use UUID PKs so we order by last_seen and use a keyset on last_seen+id.
|
|
ListObservers(ctx context.Context, arg ListObserversParams) ([]ListObserversRow, error)
|
|
// Returns packets with the latest observation rolled in for display.
|
|
// Pass cursor=0 to start from the beginning. IATA-filtered requests are
|
|
// served by ListPacketsByIATAs instead.
|
|
ListPackets(ctx context.Context, arg ListPacketsParams) ([]ListPacketsRow, error)
|
|
// Returns packets with observations after the given observation ID, ordered oldest first.
|
|
// Used for WS reconnect backfill. Pass afterObservationId=0 to start from the beginning.
|
|
ListPacketsAfterID(ctx context.Context, arg ListPacketsAfterIDParams) ([]ListPacketsAfterIDRow, error)
|
|
// IATA-filtered packet list, driven from idx_observations_iata_heard.
|
|
// Walking packets newest-first and probing for the site probes ~589k packets
|
|
// to fill a page for a quiet site; walking the site's own observation log is
|
|
// proportional to the page size instead. Results are ordered by when the
|
|
// requested sites heard the packet (site-local recency) and the cursor
|
|
// follows that ordering. scan_depth is a multiple of the page size to
|
|
// absorb per-observer duplicates; if duplication exceeds it across a
|
|
// page, pagination ends early (hasMore=false) rather than returning a
|
|
// short page, even though deeper matches exist.
|
|
ListPacketsByIATAs(ctx context.Context, arg ListPacketsByIATAsParams) ([]ListPacketsByIATAsRow, error)
|
|
// ============================================================
|
|
// REGIONS
|
|
// ============================================================
|
|
ListRegions(ctx context.Context) ([]ListRegionsRow, error)
|
|
// ============================================================
|
|
// TRACES
|
|
// ============================================================
|
|
// Returns distinct trace tags with summary info, ordered by most recent first.
|
|
// IATA membership comes from trace_iatas (joining observations here spilled the
|
|
// hash join). Per-tag details filled in only for the returned page.
|
|
ListTraceTags(ctx context.Context, arg ListTraceTagsParams) ([]ListTraceTagsRow, error)
|
|
// Delete node_neighbors where the neighbor has departed from node_short_ids
|
|
// for that IATA, or where its prefix_4 is now ambiguous.
|
|
ReconfirmNeighbors(ctx context.Context) error
|
|
// Delete known_routes where any hop node has departed from node_short_ids for
|
|
// that IATA, or where any hop's prefix_4 is now ambiguous (matches >1 node).
|
|
ReconfirmRoutes(ctx context.Context) error
|
|
RefreshHourlyStats(ctx context.Context) error
|
|
RefreshPayloadBreakdown(ctx context.Context) error
|
|
RefreshRadioPresets(ctx context.Context) error
|
|
RefreshTopNodes(ctx context.Context) error
|
|
// ============================================================
|
|
// HELPERS
|
|
// ============================================================
|
|
// Path hash resolution is split per prefix width so each query gets a
|
|
// cacheable generic plan on its (iata, prefix_N) index; a single CASE
|
|
// predicate forced a fresh custom plan on every call.
|
|
ResolvePathHashesP1(ctx context.Context, arg ResolvePathHashesP1Params) ([]ResolvePathHashesP1Row, error)
|
|
ResolvePathHashesP2(ctx context.Context, arg ResolvePathHashesP2Params) ([]ResolvePathHashesP2Row, error)
|
|
ResolvePathHashesP3(ctx context.Context, arg ResolvePathHashesP3Params) ([]ResolvePathHashesP3Row, error)
|
|
ResolvePathHashesP4(ctx context.Context, arg ResolvePathHashesP4Params) ([]ResolvePathHashesP4Row, error)
|
|
// Returns known routes containing a subsequence from source to destination hash prefix.
|
|
// Verifies source appears before destination in the route.
|
|
SearchKnownRoutes(ctx context.Context, arg SearchKnownRoutesParams) ([]KnownRoute, error)
|
|
SetNodeDefaultScope(ctx context.Context, arg SetNodeDefaultScopeParams) error
|
|
SetNodeMultibytePaths(ctx context.Context, id uuid.UUID) error
|
|
SetNodeMultibyteTraces(ctx context.Context, id uuid.UUID) error
|
|
SetPacketDecrypted(ctx context.Context, packetHash []byte) error
|
|
TouchObserverBrokers(ctx context.Context, arg TouchObserverBrokersParams) error
|
|
// Batched flush of coalesced presence bumps. GREATEST keeps a late flush
|
|
// from regressing a newer write-through (e.g. a status update).
|
|
TouchObservers(ctx context.Context, arg TouchObserversParams) error
|
|
TouchPackets(ctx context.Context, arg TouchPacketsParams) error
|
|
UpdateObserverStatus(ctx context.Context, arg UpdateObserverStatusParams) (uuid.UUID, error)
|
|
// ============================================================
|
|
// CHANNELS
|
|
// ============================================================
|
|
// Upsert a channel by (hash, key_fingerprint). Pass NULL fingerprint for
|
|
// hash-only records (key unknown). Returns the channel row.
|
|
UpsertChannel(ctx context.Context, arg UpsertChannelParams) (Channel, error)
|
|
UpsertChannelHashOnly(ctx context.Context, channelHash []byte) (int32, error)
|
|
// Refreshes at most hourly so repeat hears don't churn the row.
|
|
UpsertChannelIATA(ctx context.Context, arg UpsertChannelIATAParams) error
|
|
// Copyright 2026 Beacon Contributors
|
|
// SPDX-License-Identifier: agpl
|
|
// ============================================================
|
|
// IATA CODES
|
|
// ============================================================
|
|
UpsertIATA(ctx context.Context, iata string) error
|
|
UpsertIATADetails(ctx context.Context, arg UpsertIATADetailsParams) error
|
|
// ============================================================
|
|
// ROUTES
|
|
// ============================================================
|
|
// Inserts or updates a known route (all hops resolved to high confidence).
|
|
// node_ids and hash_prefix are ordered arrays of the resolved node UUIDs and
|
|
// their hash bytes. last_seen is bumped on conflict.
|
|
UpsertKnownRoute(ctx context.Context, arg UpsertKnownRouteParams) error
|
|
// ============================================================
|
|
// NODES
|
|
// ============================================================
|
|
UpsertNode(ctx context.Context, arg UpsertNodeParams) (Node, error)
|
|
// ============================================================
|
|
// NODE IATAS
|
|
// ============================================================
|
|
UpsertNodeIATA(ctx context.Context, arg UpsertNodeIATAParams) error
|
|
// ============================================================
|
|
// NEIGHBORS
|
|
// ============================================================
|
|
// Records or updates a neighbor relationship between two nodes observed in the same IATA.
|
|
// node_id is the advertising node, neighbor_id is the first-hop forwarder.
|
|
// snr is optional; pass NULL when no signal reading is available (the
|
|
// common case). On conflict, snr is only overwritten when a new non-null
|
|
// value is supplied, so a later no-SNR observation doesn't erase an
|
|
// earlier real reading.
|
|
UpsertNodeNeighbor(ctx context.Context, arg UpsertNodeNeighborParams) error
|
|
UpsertNodeShortID(ctx context.Context, arg UpsertNodeShortIDParams) error
|
|
// ============================================================
|
|
// OBSERVERS
|
|
// ============================================================
|
|
UpsertObserver(ctx context.Context, publicKey []byte) (Observer, error)
|
|
// ============================================================
|
|
// OBSERVER BROKERS
|
|
// ============================================================
|
|
UpsertObserverBroker(ctx context.Context, arg UpsertObserverBrokerParams) error
|
|
UpsertObserverScope(ctx context.Context, arg UpsertObserverScopeParams) error
|
|
// ============================================================
|
|
// PACKETS
|
|
// ============================================================
|
|
UpsertPacket(ctx context.Context, arg UpsertPacketParams) (UpsertPacketRow, error)
|
|
UpsertRegion(ctx context.Context, arg UpsertRegionParams) (int32, error)
|
|
UpsertRegionIATA(ctx context.Context, arg UpsertRegionIATAParams) error
|
|
// Refreshes at most hourly so repeat hears don't churn the row.
|
|
UpsertTraceIATA(ctx context.Context, arg UpsertTraceIATAParams) error
|
|
// ============================================================
|
|
// TRANSPORT CODES
|
|
// ============================================================
|
|
UpsertTransportScope(ctx context.Context, arg UpsertTransportScopeParams) error
|
|
}
|
|
|
|
var _ Querier = (*Queries)(nil)
|