persistence

package
v0.1.0-M4 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: Apache-2.0, EPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDatabaseNil for nil database.
	ErrDatabaseNil = errors.New("database is nil")

	// ErrDatabaseClosed is returned when the accessed database instance is closed.
	ErrDatabaseClosed = errors.New("database is closed")

	// ErrNotFound if the key does not exist.
	ErrNotFound = errors.New("not found")
)
View Source
var (
	// ErrThingNotFound indicates that a thing with such ID does not exist.
	ErrThingNotFound = errors.Wrap(ErrNotFound, "thing could not be found")

	// ErrFeatureNotFound indicates that a feature with such ID does not exist within the specified thing's features.
	ErrFeatureNotFound = errors.Wrap(ErrNotFound, "feature could not be found")
)

Functions

This section is empty.

Types

type Database

type Database interface {
	// GetName returns the database system name.
	GetName() (string, error)
	// SetName sets the database system name.
	SetName(name string) error

	// Get returns raw value.
	Get(key string) ([]byte, error)
	// GetAs reads the value decoded to the specified type.
	GetAs(key string, value interface{}) error
	// GetAllAs reads all values matching the key prefix and decoded to the specified type.
	GetAllAs(keyPrefix string, valuesType interface{}) ([]interface{}, error)

	// Set updates key data.
	Set(key string, data []byte) error
	// SetAs updates key data encoded using its type.
	SetAs(key string, value interface{}) error
	// SetAllAs updates a bunch of key-value pairs, using their types while encoding data.
	SetAllAs(data map[string]interface{}) error

	// UpdateAllAs combines clean and set of new data.
	// It's equivalent to Delete All and SetAllAs called as one operation.
	UpdateAllAs(keyPrefix string, data map[string]interface{}) error

	// Delete removes key and its data.
	Delete(key string) error
	// DeleteAll removes all keys matching the prefix and their data.
	DeleteAll(keyPrefix string) error

	// Close closes the opened database.
	Close() error
}

Database access interface

func NewDatabase

func NewDatabase(path string) (Database, error)

NewDatabase opens the database

type ThingsStorage

type ThingsStorage interface {
	// GetThingIDs returns the identifiers of the currently stored things.
	// ErrDatabaseClosed is returned on invocation if the database is closed.
	GetThingIDs() ([]string, error)

	// AddThing persists the thing data and its features data.
	// Updates the data if the thing data is already available.
	// Returns the thing's unsynchronized revision value on success.
	AddThing(thing *model.Thing) (int64, error)

	// GetThing retrieves the stored thing data into the pointed thing.
	// Returns ErrorThingNotFound if no thing is found with the provided thing ID.
	GetThing(thingID string, thing *model.Thing) error

	// GetThingData retrieves the stored thing's data into the pointed thing without any features data.
	// To  retrieve the thing with its features also, please use the GetThing function.
	// Returns ErrorThingNotFound if no thing is found with the provided thing ID.
	GetThingData(thingID string, thing *model.Thing) error

	// RemoveThing removes the thing data and all of its features data.
	// Returns ErrorThingNotFound if no thing is found with the provided thing ID.
	RemoveThing(thingID string) error

	// AddFeature persists the feature data. Updates the data if the feature data is already available.
	// Returns ErrorThingNotFound if no thing is found with the provided thing ID.
	// Returns the feature's unsynchronized revision value on success.
	AddFeature(thingID string, featureID string, feature *model.Feature) (int64, error)

	// GetFeature retrieves the stored feature data into the pointed feature.
	// Returns ErrorThingNotFound if no thing is found with the provided thing ID or
	// ErrorFeatureNotFound if the referenced thing has no feature with the provided feature ID.
	GetFeature(thingID string, featureID string, feature *model.Feature) error

	// RemoveFeature removes the persisted feature data.
	// Returns ErrorThingNotFound if no thing is found with the provided thing ID or
	// ErrorFeatureNotFound if the referenced thing has no feature with the provided feature ID.
	RemoveFeature(thingID string, featureID string) error

	// ThingSynchronized removes all thing's system data that is related to thing's synchronization state
	// if the revision matches the current thing's revision. Returns true in such case.
	ThingSynchronized(thingID string, revision int64) (bool, error)

	// FeatureSynchronized removes all data that is related to feature's synchronization state if the revision
	// matches the current feature modification revision or it's marked as deleted.
	// Returns false if the provided revision does not match the system unsynch revision, false otherwise.
	// If the feature is marked as unsynchronized or deleted, its system synchronization data is removed.
	FeatureSynchronized(thingID string, featureID string, revision int64) (bool, error)

	// GetSystemThingData retrieves the system data related to the thing and its features synchronization state.
	GetSystemThingData(thingID string) (*data.SystemThingData, error)

	// GetDeviceID returns the device ID which data is stored into the database.
	GetDeviceID() string

	// Close closes the opened database.
	// ErrDatabaseClosed is returned on invocation of database operation on closed database.
	Close() error
}

ThingsStorage provides handles things and features model data persistency.

func NewThingsDB

func NewThingsDB(path, deviceID string) (ThingsStorage, error)

NewThingsDB opens the things database.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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