db

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database interface {
	Close() error
	DeleteDevices(ctx context.Context, deviceIDs ...string) error
	DeleteSensors(ctx context.Context, sensorIDs ...string) error
	InsertDevices(ctx context.Context, devices ...*types.Device) error
	InsertOrUpdateDevices(ctx context.Context, devices ...*types.Device) error
	InsertMeasuredValues(ctx context.Context, measuredValues ...*types.MeasuredValue) error
	InsertOrUpdateMeasuredValues(ctx context.Context, measuredValues ...*types.MeasuredValue) error
	InsertSensors(ctx context.Context, sensors ...*types.Sensor) error
	InsertOrUpdateSensors(ctx context.Context, sensors ...*types.Sensor) error
	Migrate(ctx context.Context) error
	SelectDevice(ctx context.Context, deviceID string) (*types.Device, error)
	SelectDevices(ctx context.Context) ([]*types.Device, error)
	SelectHumidity(ctx context.Context, id string) (*types.MeasuredValue, error)
	SelectHumidities(ctx context.Context) ([]*types.MeasuredValue, error)
	SelectPressure(ctx context.Context, id string) (*types.MeasuredValue, error)
	SelectPressures(ctx context.Context) ([]*types.MeasuredValue, error)
	SelectSensor(ctx context.Context, sensorID string) (*types.Sensor, error)
	SelectSensors(ctx context.Context) ([]*types.Sensor, error)
	SelectTemperature(ctx context.Context, id string) (*types.MeasuredValue, error)
	SelectTemperatures(ctx context.Context) ([]*types.MeasuredValue, error)
	UpdateDevices(ctx context.Context, devices ...*types.Device) error
	UpdateSensors(ctx context.Context, sensors ...*types.Sensor) error
}

Database is a general interface for a database backend like postgres, oracle or sqlite

func New

func New(databaseURL *url.URL, flogger logger.Logger) (Database, error)

New returns a new database backend interface

type Postgres

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

Postgres implementation

func (*Postgres) Close

func (postgres *Postgres) Close() error

Close closes the database and prevents new queries from starting. Close then waits for all queries that have started processing on the server to finish.

func (*Postgres) DeleteDevices

func (postgres *Postgres) DeleteDevices(ctx context.Context, deviceIDs ...string) error

DeleteDevices from the database

func (*Postgres) DeleteSensors

func (postgres *Postgres) DeleteSensors(ctx context.Context, sensorIDs ...string) error

DeleteSensors from the database

func (*Postgres) InsertDevices

func (postgres *Postgres) InsertDevices(ctx context.Context, devices ...*types.Device) error

InsertDevices into the database

func (*Postgres) InsertMeasuredValues

func (postgres *Postgres) InsertMeasuredValues(ctx context.Context, measuredValues ...*types.MeasuredValue) error

InsertMeasuredValues into the database

func (*Postgres) InsertOrUpdateDevices added in v0.3.0

func (postgres *Postgres) InsertOrUpdateDevices(ctx context.Context, devices ...*types.Device) error

func (*Postgres) InsertOrUpdateMeasuredValues added in v0.3.0

func (postgres *Postgres) InsertOrUpdateMeasuredValues(ctx context.Context, measuredValues ...*types.MeasuredValue) error

InsertOrUpdateMeasuredValues into the database

func (*Postgres) InsertOrUpdateSensors added in v0.3.0

func (postgres *Postgres) InsertOrUpdateSensors(ctx context.Context, sensors ...*types.Sensor) error

InsertOrUpdateSensors into the database

func (*Postgres) InsertSensors

func (postgres *Postgres) InsertSensors(ctx context.Context, sensors ...*types.Sensor) error

InsertSensors into the database

func (*Postgres) Migrate added in v0.3.0

func (postgres *Postgres) Migrate(ctx context.Context) error

Migrate creates all required tables if not exist

func (*Postgres) SelectDevice

func (postgres *Postgres) SelectDevice(ctx context.Context, id string) (*types.Device, error)

SelectDevice from database

func (*Postgres) SelectDevices

func (postgres *Postgres) SelectDevices(ctx context.Context) ([]*types.Device, error)

SelectDevices from the database

func (*Postgres) SelectHumidities

func (postgres *Postgres) SelectHumidities(ctx context.Context) ([]*types.MeasuredValue, error)

SelectHumidities returns humidities from the database

func (*Postgres) SelectHumidity

func (postgres *Postgres) SelectHumidity(ctx context.Context, id string) (*types.MeasuredValue, error)

SelectHumidity returns humidity from the database

func (*Postgres) SelectPressure

func (postgres *Postgres) SelectPressure(ctx context.Context, id string) (*types.MeasuredValue, error)

SelectPressure returns pressure from the database

func (*Postgres) SelectPressures

func (postgres *Postgres) SelectPressures(ctx context.Context) ([]*types.MeasuredValue, error)

SelectPressures returns pressure from the database

func (*Postgres) SelectSensor

func (postgres *Postgres) SelectSensor(ctx context.Context, id string) (*types.Sensor, error)

SelectSensor from database

func (*Postgres) SelectSensors

func (postgres *Postgres) SelectSensors(ctx context.Context) ([]*types.Sensor, error)

SelectSensors from the database

func (*Postgres) SelectTemperature

func (postgres *Postgres) SelectTemperature(ctx context.Context, id string) (*types.MeasuredValue, error)

SelectTemperature returns temperatures from the database

func (*Postgres) SelectTemperatures

func (postgres *Postgres) SelectTemperatures(ctx context.Context) ([]*types.MeasuredValue, error)

SelectTemperatures returns temperatures from the database

func (*Postgres) UpdateDevices

func (postgres *Postgres) UpdateDevices(ctx context.Context, devices ...*types.Device) error

UpdateDevices updates a device in the database

func (*Postgres) UpdateSensors

func (postgres *Postgres) UpdateSensors(ctx context.Context, sensors ...*types.Sensor) error

UpdateSensors updates a sensor in the database

type SQLite

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

SQLite implementation

func (*SQLite) Close

func (sqlite *SQLite) Close() error

Close closes the database and prevents new queries from starting. Close then waits for all queries that have started processing on the server to finish.

func (*SQLite) DeleteDevices

func (sqlite *SQLite) DeleteDevices(ctx context.Context, deviceIDs ...string) error

DeleteDevices from the database

func (*SQLite) DeleteSensors

func (sqlite *SQLite) DeleteSensors(ctx context.Context, sensorIDs ...string) error

DeleteSensors from the database

func (*SQLite) ExistDevice added in v0.3.0

func (sqlite *SQLite) ExistDevice(ctx context.Context, deviceID string) (bool, error)

func (*SQLite) ExistDevices added in v0.3.0

func (sqlite *SQLite) ExistDevices(ctx context.Context, deviceIDs ...string) (map[string]bool, error)

func (*SQLite) InsertDevices

func (sqlite *SQLite) InsertDevices(ctx context.Context, devices ...*types.Device) error

InsertDevices into the database

func (*SQLite) InsertMeasuredValues

func (sqlite *SQLite) InsertMeasuredValues(ctx context.Context, measuredValues ...*types.MeasuredValue) error

InsertMeasuredValues into the database

func (*SQLite) InsertOrUpdateDevices added in v0.3.0

func (sqlite *SQLite) InsertOrUpdateDevices(ctx context.Context, devices ...*types.Device) error

InsertOrUpdateDevices into the database

func (*SQLite) InsertOrUpdateMeasuredValues added in v0.3.0

func (sqlite *SQLite) InsertOrUpdateMeasuredValues(ctx context.Context, measuredValues ...*types.MeasuredValue) error

InsertOrUpdateMeasuredValues into the database

func (*SQLite) InsertOrUpdateSensors added in v0.3.0

func (sqlite *SQLite) InsertOrUpdateSensors(ctx context.Context, sensors ...*types.Sensor) error

InsertOrUpdateSensors into the database

func (*SQLite) InsertSensors

func (sqlite *SQLite) InsertSensors(ctx context.Context, sensors ...*types.Sensor) error

InsertSensors into the database

func (*SQLite) Migrate added in v0.3.0

func (sqlite *SQLite) Migrate(ctx context.Context) error

Migrate creates all required tables if not exist

func (*SQLite) SelectDevice

func (sqlite *SQLite) SelectDevice(ctx context.Context, id string) (*types.Device, error)

SelectDevice from database

func (*SQLite) SelectDevices

func (sqlite *SQLite) SelectDevices(ctx context.Context) ([]*types.Device, error)

SelectDevices from the database

func (*SQLite) SelectHumidities

func (sqlite *SQLite) SelectHumidities(ctx context.Context) ([]*types.MeasuredValue, error)

SelectHumidities returns humidities from the database

func (*SQLite) SelectHumidity

func (sqlite *SQLite) SelectHumidity(ctx context.Context, id string) (*types.MeasuredValue, error)

SelectHumidity returns humidity from the database

func (*SQLite) SelectPressure

func (sqlite *SQLite) SelectPressure(ctx context.Context, id string) (*types.MeasuredValue, error)

SelectPressure returns pressure from the database

func (*SQLite) SelectPressures

func (sqlite *SQLite) SelectPressures(ctx context.Context) ([]*types.MeasuredValue, error)

SelectPressures returns pressure from the database

func (*SQLite) SelectSensor

func (sqlite *SQLite) SelectSensor(ctx context.Context, id string) (*types.Sensor, error)

SelectSensor from database

func (*SQLite) SelectSensors

func (sqlite *SQLite) SelectSensors(ctx context.Context) ([]*types.Sensor, error)

SelectSensors from the database

func (*SQLite) SelectTemperature

func (sqlite *SQLite) SelectTemperature(ctx context.Context, id string) (*types.MeasuredValue, error)

SelectTemperature returns temperatures from the database

func (*SQLite) SelectTemperatures

func (sqlite *SQLite) SelectTemperatures(ctx context.Context) ([]*types.MeasuredValue, error)

SelectTemperatures returns temperatures from the database

func (*SQLite) UpdateDevices

func (sqlite *SQLite) UpdateDevices(ctx context.Context, devices ...*types.Device) error

UpdateDevices updates a device in the database

func (*SQLite) UpdateSensors

func (sqlite *SQLite) UpdateSensors(ctx context.Context, sensors ...*types.Sensor) error

UpdateSensors updates a sensor in the database

Jump to

Keyboard shortcuts

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