Documentation ¶
Index ¶
- Constants
- Variables
- type Component
- type Device
- type DeviceUpsertResponse
- type ExpansionFlags
- type Location
- type SiftDB
- func (sdb *SiftDB) Close() error
- func (sdb *SiftDB) DB() (*sqlx.DB, error)
- func (sdb SiftDB) GetComponents(exFlags ExpansionFlags) (comps map[types.ComponentID]types.Component, err error)
- func (sdb SiftDB) GetDevices(exFlags ExpansionFlags) (devs map[types.DeviceID]types.Device, err error)
- func (sdb *SiftDB) GetExternalDeviceID(id types.DeviceID) (types.ExternalDeviceID, error)
- func (sdb SiftDB) UpsertDevice(extID types.ExternalDeviceID, d types.Device) (resp DeviceUpsertResponse, err error)
Constants ¶
const ( ExpandNone = 0 ExpandAll = 1 << iota ExpandSpecs ExpandStats )
Expansion flags
Variables ¶
var Log = logging.Log.New("pkg", "db/components")
Log is used to log messages for the auth package. Logs are disabled by default; use sift/logging.SetLevel() to set log levels for all packages, or Log.SetHandler() to set a custom handler for this package (see: https://godoc.org/gopkg.in/inconshreveable/log15.v2)
Functions ¶
This section is empty.
Types ¶
type Component ¶
Component contains fields matching those in the 'component' table in the SIFT database, which is useful when querying the database using sqlx.
type Device ¶
type Device struct { ID int64 Manufacturer string ExternalID string `db:"external_id"` Name sql.NullString LocationID sql.NullInt64 `db:"location_id"` IsOnline bool `db:"is_online"` }
Device contains fields matching those in the 'device' table in the SIFT database, which is useful when querying the database using sqlx.
type DeviceUpsertResponse ¶
type DeviceUpsertResponse struct { DeviceID types.DeviceID UpsertedComponents map[string]types.Component DeletedComponents map[string]types.Component HasDeviceChanged bool }
A DeviceUpsertResponse describes the result of a call to UpsertDevice
type ExpansionFlags ¶
type ExpansionFlags byte
ExpansionFlags are used when retrieving SIFT Devices and Components to specify which parts should be gathered (expanded) from the database
type Location ¶
Location contains fields matching those in the 'location' table in the SIFT database, which is useful when querying the database using sqlx.
type SiftDB ¶
type SiftDB struct {
// contains filtered or unexported fields
}
A SiftDB manages interactions with the underlying SIFT database
func Open ¶
Open opens the SIFT database at the provided file path. If the file does not exist, it is created and initialized with the SIFT schema.
func (SiftDB) GetComponents ¶
func (sdb SiftDB) GetComponents(exFlags ExpansionFlags) (comps map[types.ComponentID]types.Component, err error)
GetComponents returns a map of all Components in the SIFT database, indexed by their SIFT-internal ComponentIDs, and expanded to the degree indicated by exFlags
func (SiftDB) GetDevices ¶
func (sdb SiftDB) GetDevices(exFlags ExpansionFlags) (devs map[types.DeviceID]types.Device, err error)
GetDevices returns a map of all Devices in the SIFT database, indexed by their SIFT-internal DeviceIDs, and expanded to the degree indicated by exFlags
func (*SiftDB) GetExternalDeviceID ¶
GetExternalDeviceID determines the types.ExternalDeviceID that matches the given SIFT-internal types.DeviceID in the SIFT database.
func (SiftDB) UpsertDevice ¶
func (sdb SiftDB) UpsertDevice(extID types.ExternalDeviceID, d types.Device) (resp DeviceUpsertResponse, err error)
UpsertDevice updates or inserts a Device into the SIFT database using the provided types.ExternalDeviceID. This also includes Upserting any Components which are attached to the Device. UpsertDevice considers the Device to be "whole"; if any Components which were previously attached to the Device are not present in the Device's Components map, those Components will be deleted from the SIFT database.
If successful, the response object contains the new or updated Device's SIFT ID, as well as indications of which specific components were upserted or deleted.