mirror of
https://github.com/MeshCore-Beacon/beacon-server.git
synced 2026-10-15 20:29:54 +00:00
127 lines
3.6 KiB
Go
127 lines
3.6 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: route_evidence.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const getRouteEvidenceRoute = `-- name: GetRouteEvidenceRoute :one
|
|
SELECT id, path_key, node_ids, hash_prefix, iata, hop_count, first_seen, last_seen, observation_count, last_reconfirmed_at FROM known_routes
|
|
WHERE iata = $1::bpchar AND path_key = $2::bytea
|
|
`
|
|
|
|
type GetRouteEvidenceRouteParams struct {
|
|
Iata string `json:"iata"`
|
|
PathKey []byte `json:"path_key"`
|
|
}
|
|
|
|
func (q *Queries) GetRouteEvidenceRoute(ctx context.Context, arg GetRouteEvidenceRouteParams) (KnownRoute, error) {
|
|
row := q.db.QueryRow(ctx, getRouteEvidenceRoute, arg.Iata, arg.PathKey)
|
|
var i KnownRoute
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.PathKey,
|
|
&i.NodeIds,
|
|
&i.HashPrefix,
|
|
&i.Iata,
|
|
&i.HopCount,
|
|
&i.FirstSeen,
|
|
&i.LastSeen,
|
|
&i.ObservationCount,
|
|
&i.LastReconfirmedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listRouteEvidence = `-- name: ListRouteEvidence :many
|
|
SELECT po.id, po.packet_hash, po.observer_id, o.display_name AS observer_name,
|
|
po.heard_at, po.payload_type, po.rssi, po.snr
|
|
FROM packet_observations po
|
|
JOIN observers o ON o.id = po.observer_id
|
|
WHERE po.iata = $1::bpchar
|
|
AND po.hash_size = $2::smallint
|
|
AND decode(md5(po.path_bytes), 'hex') = $3::bytea
|
|
AND po.path_bytes = $4::bytea
|
|
AND po.hop_count >= 2
|
|
AND po.hop_count = $5::smallint
|
|
AND po.path_bytes IS NOT NULL AND po.payload_type IS NOT NULL AND po.payload_type <> 9
|
|
AND po.heard_at >= $6::timestamptz AND po.heard_at < $7::timestamptz
|
|
AND (po.heard_at, po.id) < ($8::timestamptz, $9::bigint)
|
|
ORDER BY po.heard_at DESC, po.id DESC
|
|
LIMIT $10::integer
|
|
`
|
|
|
|
type ListRouteEvidenceParams struct {
|
|
Iata string `json:"iata"`
|
|
HashSize int16 `json:"hash_size"`
|
|
PathDigest []byte `json:"path_digest"`
|
|
PathBytes []byte `json:"path_bytes"`
|
|
HopCount int16 `json:"hop_count"`
|
|
Since pgtype.Timestamptz `json:"since"`
|
|
Until pgtype.Timestamptz `json:"until"`
|
|
BeforeAt pgtype.Timestamptz `json:"before_at"`
|
|
BeforeID int64 `json:"before_id"`
|
|
PageLimit int32 `json:"page_limit"`
|
|
}
|
|
|
|
type ListRouteEvidenceRow struct {
|
|
ID int64 `json:"id"`
|
|
PacketHash []byte `json:"packet_hash"`
|
|
ObserverID uuid.UUID `json:"observer_id"`
|
|
ObserverName *string `json:"observer_name"`
|
|
HeardAt pgtype.Timestamptz `json:"heard_at"`
|
|
PayloadType *int16 `json:"payload_type"`
|
|
Rssi *int16 `json:"rssi"`
|
|
Snr *float32 `json:"snr"`
|
|
}
|
|
|
|
// Leading index equalities and the time/ID boundary bound both custom and generic plans.
|
|
// Full-byte equality is required even when the compact digest matches. TRACE path bytes
|
|
// carry readings; unclassified legacy observations cannot be safely called ordinary paths.
|
|
func (q *Queries) ListRouteEvidence(ctx context.Context, arg ListRouteEvidenceParams) ([]ListRouteEvidenceRow, error) {
|
|
rows, err := q.db.Query(ctx, listRouteEvidence,
|
|
arg.Iata,
|
|
arg.HashSize,
|
|
arg.PathDigest,
|
|
arg.PathBytes,
|
|
arg.HopCount,
|
|
arg.Since,
|
|
arg.Until,
|
|
arg.BeforeAt,
|
|
arg.BeforeID,
|
|
arg.PageLimit,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListRouteEvidenceRow{}
|
|
for rows.Next() {
|
|
var i ListRouteEvidenceRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.PacketHash,
|
|
&i.ObserverID,
|
|
&i.ObserverName,
|
|
&i.HeardAt,
|
|
&i.PayloadType,
|
|
&i.Rssi,
|
|
&i.Snr,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|