storage

package
v0.0.0-...-3ddd1f0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoRows        = errors.New("no rows in result set")
	ErrTooManyRows   = errors.New("too many rows in result set")
	ErrQueryRow      = errors.New("could not execute query")
	ErrStoreFailed   = errors.New("could not store data")
	ErrNoID          = errors.New("data contains no id")
	ErrMissingTenant = errors.New("missing tenant information")
	ErrAlreadyExist  = errors.New("device already exists")
	ErrDeleted       = errors.New("deleted")
)

Functions

func NewPool

func NewPool(ctx context.Context, config Config) (*pgxpool.Pool, error)

Types

type Box

type Box struct {
	MinX float64 // west
	MaxX float64 // east
	MinY float64 // south
	MaxY float64 // north
}

type Condition

type Condition struct {
	DeviceID          string
	SensorID          string
	DeviceWithAlarmID string
	Types             []string
	Tenants           []string
	ProfileName       []string

	Active *bool
	Online *bool
	Bounds *Box

	AlarmID        string
	RefID          string
	IncludeDeleted bool
	Urn            []string
	Search         string
	LastSeen       time.Time
	// contains filtered or unexported fields
}

func (Condition) Limit

func (c Condition) Limit() int

func (Condition) NamedArgs

func (c Condition) NamedArgs() pgx.NamedArgs

func (Condition) Offset

func (c Condition) Offset() int

func (Condition) SortBy

func (c Condition) SortBy() string

func (Condition) SortOrder

func (c Condition) SortOrder() string

func (Condition) Where

func (c Condition) Where() string

type ConditionFunc

type ConditionFunc func(*Condition) *Condition

func WithActive

func WithActive(active bool) ConditionFunc

func WithAlarmID

func WithAlarmID(alarmID string) ConditionFunc

func WithBounds

func WithBounds(north, south, east, west float64) ConditionFunc

func WithDeleted

func WithDeleted() ConditionFunc

func WithDeviceAlarmID

func WithDeviceAlarmID(alarmID string) ConditionFunc

func WithDeviceID

func WithDeviceID(deviceID string) ConditionFunc

func WithLastSeen

func WithLastSeen(ts time.Time) ConditionFunc

func WithLimit

func WithLimit(limit int) ConditionFunc

func WithOffset

func WithOffset(offset int) ConditionFunc

func WithOnline

func WithOnline(online bool) ConditionFunc

func WithProfileName

func WithProfileName(profileName []string) ConditionFunc

func WithRefID

func WithRefID(refID string) ConditionFunc

func WithSearch

func WithSearch(s string) ConditionFunc

func WithSensorID

func WithSensorID(sensorID string) ConditionFunc

func WithSortBy

func WithSortBy(sortBy string) ConditionFunc

func WithSortDesc

func WithSortDesc(desc bool) ConditionFunc

func WithTenant

func WithTenant(tenant string) ConditionFunc

func WithTenants

func WithTenants(tenants []string) ConditionFunc

func WithTypes

func WithTypes(types []string) ConditionFunc

func WithUrn

func WithUrn(urn []string) ConditionFunc

type Config

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

func LoadConfiguration

func LoadConfiguration(ctx context.Context) Config

func NewConfig

func NewConfig(host, user, password, port, dbname, sslmode string) Config

func (Config) ConnStr

func (c Config) ConnStr() string

type Storage

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

func New

func New(ctx context.Context, config Config) (*Storage, error)

func NewWithPool

func NewWithPool(pool *pgxpool.Pool) *Storage

func (*Storage) AddAlarm

func (s *Storage) AddAlarm(ctx context.Context, alarm types.Alarm) error

func (*Storage) AddDevice

func (s *Storage) AddDevice(ctx context.Context, device types.Device) error

func (*Storage) Close

func (s *Storage) Close()

func (*Storage) CloseAlarm

func (s *Storage) CloseAlarm(ctx context.Context, alarmID, tenant string) error

func (*Storage) CreateTables

func (s *Storage) CreateTables(ctx context.Context) error

func (*Storage) GetAlarm

func (s *Storage) GetAlarm(ctx context.Context, conditions ...ConditionFunc) (types.Alarm, error)

func (*Storage) GetDevice

func (s *Storage) GetDevice(ctx context.Context, conditions ...ConditionFunc) (types.Device, error)

func (*Storage) GetTags

func (s *Storage) GetTags(ctx context.Context, deviceID, tenant string) ([]types.Tag, error)

func (*Storage) GetTenants

func (s *Storage) GetTenants(ctx context.Context) ([]string, error)

func (*Storage) QueryAlarms

func (s *Storage) QueryAlarms(ctx context.Context, conditions ...ConditionFunc) (types.Collection[types.Alarm], error)

func (*Storage) QueryDevices

func (s *Storage) QueryDevices(ctx context.Context, conditions ...ConditionFunc) (types.Collection[types.Device], error)

func (*Storage) QueryInformation

func (s *Storage) QueryInformation(ctx context.Context, conditions ...ConditionFunc) (types.Collection[types.InformationItem], error)

func (*Storage) SetActive

func (s *Storage) SetActive(ctx context.Context, deviceID, tenant string, active bool) error

func (*Storage) SetTenant

func (s *Storage) SetTenant(ctx context.Context, deviceID, tenant string) error

func (*Storage) UpdateDevice

func (s *Storage) UpdateDevice(ctx context.Context, device types.Device) error

func (*Storage) UpdateState

func (s *Storage) UpdateState(ctx context.Context, deviceID, tenant string, deviceState types.DeviceState) error

func (*Storage) UpdateStatus

func (s *Storage) UpdateStatus(ctx context.Context, deviceID, tenant string, deviceStatus types.DeviceStatus) error

func (*Storage) UpdateTags

func (s *Storage) UpdateTags(ctx context.Context, deviceID, tenant string, tags []types.Tag) error

Jump to

Keyboard shortcuts

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