diff --git a/db/sqlc/querier.go b/db/sqlc/querier.go new file mode 100644 index 0000000..e915c53 --- /dev/null +++ b/db/sqlc/querier.go @@ -0,0 +1,200 @@ +// 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 { + // 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 + 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) + // 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) + 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) + // Returns observation counts grouped by payload type for the given window and IATA. + GetStatsPayloadBreakdown(ctx context.Context, arg GetStatsPayloadBreakdownParams) ([]GetStatsPayloadBreakdownRow, error) + // Returns the top N observers by observation count for the given window and IATA. + GetStatsTopObservers(ctx context.Context, arg GetStatsTopObserversParams) ([]GetStatsTopObserversRow, 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) + // Returns channels ordered by last seen, optionally filtered by hash and/or IATA. + // Pass NULL for hash to skip hash filtering. Pass empty string for iata to skip IATA filtering. + // IATA filter returns channels that have active packets in that IATA (case-insensitive). + // 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. + 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) + // ============================================================ + // REGIONS + // ============================================================ + ListRegions(ctx context.Context) ([]ListRegionsRow, error) + // ============================================================ + // TRACES + // ============================================================ + // Returns distinct trace tags with summary info, ordered by most recent first. + 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 + RefreshRadioPresets(ctx context.Context) error + RefreshTopNodes(ctx context.Context) error + // ============================================================ + // HELPERS + // ============================================================ + ResolvePathHashes(ctx context.Context, arg ResolvePathHashesParams) ([]ResolvePathHashesRow, 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 + 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) + // 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. + 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 + // ============================================================ + // TRANSPORT CODES + // ============================================================ + UpsertTransportScope(ctx context.Context, arg UpsertTransportScopeParams) error +} + +var _ Querier = (*Queries)(nil) diff --git a/db/store.go b/db/store.go index c4ace41..6ae1d32 100644 --- a/db/store.go +++ b/db/store.go @@ -20,7 +20,7 @@ import ( // Store wraps the sqlc-generated Queries and implements both ingest.DB and api.Reader. type Store struct { - q *sqlc.Queries + q sqlc.Querier } // New creates a Store backed by the given pgxpool connection pool. diff --git a/sqlc.yaml b/sqlc.yaml index d443e9b..892a782 100644 --- a/sqlc.yaml +++ b/sqlc.yaml @@ -14,6 +14,7 @@ sql: emit_json_tags: true emit_pointers_for_null_types: true emit_empty_slices: true + emit_interface: true overrides: - db_type: "uuid" go_type: "github.com/google/uuid.UUID"