db

package
v0.0.33 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2021 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package db implements database store code -- currently Genji and Influxdb. Also contains NATS handlers to receive data. This allows us to keep the db write functions private and force all write data through NATS, and thus makes it easy to observe any data changes.

Index

Constants

View Source
const (
	StoreTypeMemory StoreType = "memory"
	StoreTypeBolt             = "bolt"
	StoreTypeBadger           = "badger"
)

define valid store types

Variables

View Source
var DBVersion = 1

DBVersion for this version of siot

Functions

func DumpDb added in v0.0.6

func DumpDb(gen *Db, out io.Writer) error

DumpDb dumps the entire gen to a file

func ImportDb added in v0.0.30

func ImportDb(gen *Db, in io.Reader) error

ImportDb imports contents of file into database

func NatsSendFileFromHTTP added in v0.0.30

func NatsSendFileFromHTTP(nc *natsgo.Conn, deviceID string, url string, callback func(int)) error

NatsSendFileFromHTTP fetchs a file using http and sends via nats. Callback provides % complete (0-100).

Types

type Db

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

Db is used for all db access in the application. We will eventually turn this into an interface to handle multiple Db backends.

func NewDb

func NewDb(storeType StoreType, dataDir string) (*Db, error)

NewDb creates a new Db instance for the app

func (*Db) Close added in v0.0.30

func (gen *Db) Close() error

Close closes the db

func (*Db) NodesForUser added in v0.0.30

func (gen *Db) NodesForUser(userID string) ([]data.NodeEdge, error)

NodesForUser returns all nodes for a particular user FIXME this should be renamed to node children or something like that TODO we should unexport this and somehow do this through nats

func (*Db) UserCheck added in v0.0.6

func (gen *Db) UserCheck(email, password string) (*data.User, error)

UserCheck checks user authentication returns nil, nil if user is not found

type Influx

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

Influx represents and influxdb that we can write points to

func NewInflux

func NewInflux(config *InfluxConfig) *Influx

NewInflux creates an influx helper client

func (*Influx) WritePoints added in v0.0.23

func (i *Influx) WritePoints(nodeID, nodeDesc string, points data.Points) error

WritePoints to influxdb

type InfluxConfig added in v0.0.28

type InfluxConfig struct {
	URL    string
	Token  string
	Org    string
	Bucket string
}

InfluxConfig represents an influxdb config

func NodeToInfluxConfig added in v0.0.28

func NodeToInfluxConfig(node data.NodeEdge) (*InfluxConfig, error)

NodeToInfluxConfig converts a node to an influx config

type Meta added in v0.0.30

type Meta struct {
	Version int    `json:"version"`
	RootID  string `json:"rootID"`
}

Meta contains metadata about the database

type NatsHandler added in v0.0.30

type NatsHandler struct {
	Nc *natsgo.Conn
	// contains filtered or unexported fields
}

NatsHandler implements the SIOT NATS api

func NewNatsHandler added in v0.0.30

func NewNatsHandler(db *Db, authToken, server string) *NatsHandler

NewNatsHandler creates a new NATS client for handling SIOT requests

func (*NatsHandler) Connect added in v0.0.30

func (nh *NatsHandler) Connect() (*natsgo.Conn, error)

Connect to NATS server and set up handlers for things we are interested in

func (*NatsHandler) StartUpdate added in v0.0.30

func (nh *NatsHandler) StartUpdate(id, url string) error

StartUpdate starts an update

type StoreType added in v0.0.30

type StoreType string

StoreType defines the backing store used for the DB

Jump to

Keyboard shortcuts

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