DatabaseConnector

package
Version: v0.0.0-...-96f3fa0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2016 License: MIT Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var WorkQueue = make(chan WorkRequest, 100)

WorkQueue where works get put in for the DatabaseConnector.

View Source
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

func AddSensor(sensor mdl.Sensor) error

AddSensor Adds the sensor in the database. If needed it will create the sensor type first.

func ChangeSensorActivationState

func ChangeSensorActivationState(sensors []mdl.Sensor)

ChangeSensorActivationState calls for every sensor the ChangeSingleSensorActivationState function.

func ChangeSingleSensorActivationState

func ChangeSingleSensorActivationState(sensor mdl.Sensor)

ChangeSingleSensorActivationState sets the softdelete state in the database.

func CheckDevEUI

func CheckDevEUI(devEUI string) bool

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

func GetFullHeader(devEUI string) ([]mdl.Sensor, error)

GetFullHeader returns all sensors connected to a node.

func GetNodeSensors

func GetNodeSensors(devEUI string) []mdl.Sensor

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

type DatabaseConnector struct {
	Database *sql.DB
	// contains filtered or unexported fields
}

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.

Jump to

Keyboard shortcuts

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