Documentation ¶
Overview ¶
Package DatabaseConnector handels the communication with the database. It only contains prepared querys that are needed for the backend. It has a maximum amount of querys that can happen simultaniously
Index ¶
- Variables
- func AddMessage(devEUI string) (mdl.MessageUplinkI, error)
- func AddSensor(sensor mdl.Sensor) error
- func ChangeSensorActivationState(sensors []mdl.Sensor)
- func ChangeSingleSensorActivationState(sensor mdl.Sensor)
- func CheckDevEUI(devEUI string) bool
- func Close() error
- func Connect() error
- func GetFullHeader(devEUI string) ([]mdl.Sensor, error)
- func GetNodeSensors(devEUI string) []mdl.Sensor
- func StoreDownlinkMessage(message *mdl.MessageDownLink) error
- func StoreMessagePayloads(message mdl.MessageUplinkI) error
- type DatabaseConnector
- type WorkRequest
- type WorkResult
- type Worker
Constants ¶
This section is empty.
Variables ¶
var WorkQueue = make(chan WorkRequest, 100)
WorkQueue where works get put in for the DatabaseConnector.
var WorkerQueue chan chan WorkRequest
WorkerQueue contains a channel with WorkRequests
Functions ¶
func AddMessage ¶
func AddMessage(devEUI string) (mdl.MessageUplinkI, error)
AddMessage Adds a message into the messages table and returnes an MessageUplink with the id of the inserted record.
func AddSensor ¶
AddSensor Adds the sensor in the database. If needed it will create the sensor type first.
func ChangeSensorActivationState ¶
ChangeSensorActivationState calls for every sensor the ChangeSingleSensorActivationState function.
func ChangeSingleSensorActivationState ¶
ChangeSingleSensorActivationState sets the softdelete state in the database.
func CheckDevEUI ¶
CheckDevEUI Checks if the devEUI exists in the database. Uses a database worker to execute the query.
func Close ¶
func Close() error
Close wil call the close() function on the connection. This however means that the connection cannot be opened again.
func Connect ¶
func Connect() error
Connect will Ping the database, which actualy opens the connection. After this it will setup all the prepared statements. It will return an error as soon as it finds a problem.
func GetFullHeader ¶
GetFullHeader returns all sensors connected to a node.
func GetNodeSensors ¶
GetNodeSensors Gets the sensors that belong to one node
func StoreDownlinkMessage ¶
func StoreDownlinkMessage(message *mdl.MessageDownLink) error
StoreDownlinkMessage Stores a DownlinkMessage which has an id,payload and deveui set. if no time is set NOW() will be used
func StoreMessagePayloads ¶
func StoreMessagePayloads(message mdl.MessageUplinkI) error
StoreMessagePayloads Get a message
Types ¶
type DatabaseConnector ¶
DatabaseConnector contains the connection to the database and all the prepared statements that are used.
func GetInstance ¶
func GetInstance() *DatabaseConnector
GetInstance gets the instantiated instance of the DatabaseConnector or create it. When creating it will use the configuration to set up the connection. IDEA move the sql.Open function to the Connect function. As this code gets executed only once here it means that after closing the connection there is no way to open it again.
type WorkRequest ¶
type WorkRequest struct { Query string ResultChannel chan (WorkResult) Arguments []interface{} F func(w *WorkRequest) }
WorkRequest is ment to store work for in the Dispatcher. These should be querys. Arguments for a stament are passed as an array in the interface{} Results can be passed back via the the result channel in an WorkResult. F is a function wherein the query is executed and proccesed. Keep this function as short as possible because it is blocking one DBCworker
type WorkResult ¶
type WorkResult struct { Result interface{} // contains filtered or unexported fields }
WorkResult is a result from a WorkRequest. Contains a generic Result and a error interface.
type Worker ¶
type Worker struct { ID int Work chan WorkRequest WorkerQueue chan chan WorkRequest QuitChan chan bool }
Worker contains an ID, a channel is the channel where it gets work from. QuitChan is a channel that tells to stop the worker.
func NewWorker ¶
func NewWorker(id int, workerQueue chan chan WorkRequest) Worker
NewWorker returns a new worker with the workerQueue set.