database

package
v0.0.0-...-2698fcb Latest Latest
Warning

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

Go to latest
Published: May 13, 2021 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(db Datastore) func(http.Handler) http.Handler

Middleware packs a pointer to the datastore into context

Types

type ConnectorFunc

type ConnectorFunc func() (*gorm.DB, error)

ConnectorFunc is used to inject a database connection method into NewDatabaseConnection

func NewPostgreSQLConnector

func NewPostgreSQLConnector(log logging.Logger) ConnectorFunc

NewPostgreSQLConnector opens a connection to a postgresql database

func NewSQLiteConnector

func NewSQLiteConnector() ConnectorFunc

NewSQLiteConnector opens a connection to a local sqlite database

type Datastore

type Datastore interface {
	CreateDevice(device *fiware.Device) (*models.Device, error)
	CreateDeviceModel(deviceModel *fiware.DeviceModel) (*models.DeviceModel, error)
	GetDeviceFromID(id string) (*models.Device, error)
	GetDevices() ([]models.Device, error)
	GetDeviceModels() ([]models.DeviceModel, error)
	GetDeviceModelFromID(id string) (*models.DeviceModel, error)
	GetDeviceModelFromPrimaryKey(id uint) (*models.DeviceModel, error)
	UpdateDeviceValue(deviceID, value string) error
}

Datastore is an interface that is used to inject the database into different handlers to improve testability

func GetFromContext

func GetFromContext(ctx context.Context) (Datastore, error)

GetFromContext extracts the database wrapper, if any, from the provided context

func NewDatabaseConnection

func NewDatabaseConnection(connect ConnectorFunc, log logging.Logger) (Datastore, error)

NewDatabaseConnection initializes a new connection to the database and wraps it in a Datastore

Jump to

Keyboard shortcuts

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