database

package
v0.0.0-...-9bd6792 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRecentSensorMessages

func GetRecentSensorMessages(db *DB, ipAddr string) (sensorMessages [][]byte, insertErr error)

GetRecentSensorMessages returns the most recent sensor messages (1 minute) of a client

func InsertSensorMessage

func InsertSensorMessage(db *DB, payload *map[string]interface{}, remoteAddress string) (err error)

InsertSensorMessage inserts a sensor message into the database

func UpsertClient

func UpsertClient(db *DB, remoteAddr string) *entities.ClientEntity

UpsertClient inserts a new client into the database if it doesn't exist, otherwise updates the last seen time

Types

type DB

type DB struct {
	*bun.DB
}

func Connect

func Connect(env *database_models.PostgresEnv) *DB

Connect creates a new database connection using exponential backoff when failing to connect

func (*DB) InsertClient

func (db *DB) InsertClient(ipAddr string) (*entities.ClientEntity, error)

InsertClient inserts a new client into the database

type DBClient

type DBClient struct {
	// contains filtered or unexported fields
}

DBClient manages the lifecycle of database operations

func NewClient

func NewClient() *DBClient

func (*DBClient) GetDB

func (dbc *DBClient) GetDB() DB

func (*DBClient) Init

func (dbc *DBClient) Init(config *serverConfig.ServerConfig)

Init initializes the database client

func (*DBClient) Start

func (dbc *DBClient) Start() error

Start initializes the database client

func (*DBClient) Stop

func (dbc *DBClient) Stop() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL