db

package
v0.0.0-...-b0e10ae Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2016 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExpandNone = 0
	ExpandAll  = 1 << iota
	ExpandSpecs
	ExpandStats
)

Expansion flags

Variables

View Source
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

type Component struct {
	ID                      int64
	DeviceID                int64 `db:"device_id"`
	Name, Make, Model, Type string
}

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

type Location struct {
	ID   int64
	Name string
}

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

func Open(pathToDBFile string) (*SiftDB, error)

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) Close

func (sdb *SiftDB) Close() error

Close closes any temporary files that were used

func (*SiftDB) DB

func (sdb *SiftDB) DB() (*sqlx.DB, error)

DB returns a connection to the sift database

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

func (sdb *SiftDB) GetExternalDeviceID(id types.DeviceID) (types.ExternalDeviceID, error)

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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