db

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2019 License: Apache-2.0 Imports: 1 Imported by: 1

Documentation

Overview

package db provides some overarching variables, structs, and interfaces that different database implementations can use and implement and consumers can expect.

Index

Constants

View Source
const (
	// TypeLabel is for labeling metrics; if there is a single metric for
	// successful queries, the typeLabel and corresponding type can be used
	// when incrementing the metric.
	TypeLabel         = "type"
	InsertType        = "insert"
	DeleteType        = "delete"
	ReadType          = "read"
	PingType          = "ping"
	BlacklistReadType = "blacklistRead"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type EventType added in v0.3.2

type EventType int

EventType is an enum for specifying the type of event being stored.

const (
	// default event type
	Default EventType = iota

	// event type for online and offline events
	State
)

func ParseEventType added in v0.3.2

func ParseEventType(event string) EventType

ParseEventType returns the enum when given a string.

func (EventType) String added in v0.3.2

func (i EventType) String() string

type Inserter added in v0.2.0

type Inserter interface {
	InsertRecords(records ...Record) error
}

Inserter is something that can insert records into the database.

type Pruner added in v0.2.0

type Pruner interface {
	GetRecordsToDelete(shard int, limit int, deathDate int64) ([]RecordToDelete, error)
	// PruneRecords(records []int) error
	DeleteRecord(shard int, deathdate int64, recordID int64) error
}

Pruner is something that can get a list of expired records and delete them. Deleting is done individually.

type Record added in v0.2.0

type Record struct {
	Type      EventType `json:"type" bson:"type" gorm:"type:int"`
	DeviceID  string    `json:"deviceid" bson:"deviceid"`
	BirthDate int64     `json:"birthdate" bson:"birthdate"`
	DeathDate int64     `json:"deathdate" bson:"deathdate"`
	Data      []byte    `json:"data" bson:"data"`
	Nonce     []byte    `json:"nonce" bson:"nonce"`
	Alg       string    `json:"alg" bson:"alg"`
	KID       string    `json:"kid" bson:"kid" gorm:"Column:kid"`
}

Record is the struct used to insert an event into the database. It includes the marshaled, and possibly encrypted, event ("Data") and then other metadata to be used for the record. If the data is encrypted, the Nonce, Alg, and KID values will be needed to determine how to correctly decrypt it.

func (Record) TableName added in v0.2.0

func (Record) TableName() string

TableName sets Record's table name to be "events"; for the GORM driver.

type RecordGetter added in v0.2.0

type RecordGetter interface {
	GetRecords(deviceID string, limit int) ([]Record, error)
	GetRecordsOfType(deviceID string, limit int, eventType EventType) ([]Record, error)
}

RecordGetter is something that can get records, including only getting records of a certain type.

type RecordToDelete added in v0.8.0

type RecordToDelete struct {
	DeathDate int64 `json:"deathdate" bson:"deathdate"`
	RecordID  int64 `json:"recordid" bson:"recordid"`
}

RecordToDelete is the information needed to get out of the database in order to call the DeleteRecord function

Directories

Path Synopsis
package batchDeleter provides a wrapper around the db.Pruner to provide a way to get expired records at a given interval and delete them at a separate given interval.
package batchDeleter provides a wrapper around the db.Pruner to provide a way to get expired records at a given interval and delete them at a separate given interval.
package batchInserter provides a wrapper around the db.Inserter to provide a way to group records together before inserting, in order to decrease database requests needed for inserting.
package batchInserter provides a wrapper around the db.Inserter to provide a way to group records together before inserting, in order to decrease database requests needed for inserting.
package postgresql provides a way to connect to a postgresql database to keep track of device events.
package postgresql provides a way to connect to a postgresql database to keep track of device events.
package dbretry contains structs that implement various db interfaces as well as consume them.
package dbretry contains structs that implement various db interfaces as well as consume them.

Jump to

Keyboard shortcuts

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