Documentation
¶
Index ¶
- func EnsureSchema(db *sql.DB, expectedDB string) error
- func OpenDatabase(cfg pq.Config) (*sql.DB, error)
- func Run(ctx context.Context, cfg Config) error
- func UpsertDevices(ctx context.Context, db *sql.DB, records []*inventoryv1.DeviceRecord) (int, error)
- func UpsertNeighbors(ctx context.Context, db *sql.DB, records []*inventoryv1.NeighborRecord) (int, error)
- type Config
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureSchema ¶
EnsureSchema checks that the connection targets the expected database and creates any missing tables.
func OpenDatabase ¶
OpenDatabase creates and verifies a connection to the PostgreSQL database using the provided pq.Config.
func UpsertDevices ¶
func UpsertDevices(ctx context.Context, db *sql.DB, records []*inventoryv1.DeviceRecord) (int, error)
UpsertDevices inserts or updates device records into the PostgreSQL inventory table. Conflicts on serial_number trigger an update when any mutable column differs.
func UpsertNeighbors ¶
func UpsertNeighbors(ctx context.Context, db *sql.DB, records []*inventoryv1.NeighborRecord) (int, error)
UpsertNeighbors inserts or updates neighbor records into the PostgreSQL neighbors table. Conflicts on (host_identifier, local_interface) trigger an update when attributes differ.
Types ¶
type Server ¶
type Server struct {
inventoryv1.UnimplementedInventoryAggregatorServer
// contains filtered or unexported fields
}
Server implements the InventoryAggregator gRPC service.
func (*Server) SubmitInventory ¶
func (s *Server) SubmitInventory(ctx context.Context, req *inventoryv1.SubmitInventoryRequest) (*inventoryv1.SubmitInventoryResponse, error)
SubmitInventory receives a batch of device and neighbor records and persists them to the PostgreSQL database.