db

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package db implements a plugin system for data storage options. The db package itself implements the registration and initialization functions that provide a uniform interface to underlying storage mechanisms.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnknownEntity is returned for requests to load an entity
	// that does not exist.
	ErrUnknownEntity = errors.New("The specified entity does not exist")

	// ErrUnknownGroup is returned for requests to load a group
	// that does not exist.
	ErrUnknownGroup = errors.New("The specified group does not exist")

	// ErrUnknownDatabase is returned for an attempt to create a
	// new database that hasn't been registered.
	ErrUnknownDatabase = errors.New("The specified database does not exist")

	// ErrInternalError is used for all other errors that occur
	// within a database implementation.
	ErrInternalError = errors.New("The database has encountered an internal error")

	// ErrBadSearch is returned when a search request cannot be
	// filled for some reason.
	ErrBadSearch = errors.New("The provided SearchRequest is invalid")
)

Functions

func DeregisterCallback added in v0.1.0

func DeregisterCallback(name string)

DeregisterCallback is used to drop a callback from the list. This is effectively for use in tests only to clean up the registration list in test cases.

func FireEvent added in v0.0.12

func FireEvent(e Event)

FireEvent fires an event to all callbacks.

func GetBackendList

func GetBackendList() []string

GetBackendList returns a string list of the backends that are available

func Register added in v0.0.10

func Register(name string, newFunc Factory)

Register takes in a name of the database to register and a function signature to bind to that name.

func RegisterCallback added in v0.0.12

func RegisterCallback(name string, c Callback)

RegisterCallback takes a callback name and handle and registers them for later calling.

Types

type Callback added in v0.0.12

type Callback func(Event)

Callback is a function type registered by an external customer that is interested in some change that might happen in the storage system. These are returned with a DBEvent populated of whether or not the event pertained to an entity or a group, and the relavant primary key.

type DB

type DB interface {
	// Entity handling
	DiscoverEntityIDs() ([]string, error)
	LoadEntity(string) (*pb.Entity, error)
	SaveEntity(*pb.Entity) error
	DeleteEntity(string) error
	NextEntityNumber() (int32, error)
	SearchEntities(SearchRequest) ([]*pb.Entity, error)

	// Group handling
	DiscoverGroupNames() ([]string, error)
	LoadGroup(string) (*pb.Group, error)
	SaveGroup(*pb.Group) error
	DeleteGroup(string) error
	NextGroupNumber() (int32, error)
	SearchGroups(SearchRequest) ([]*pb.Group, error)
}

DB specifies the methods that a DB engine must provide.

func New

func New() (DB, error)

New returns a db struct.

type Event added in v0.0.12

type Event struct {
	Type EventType
	PK   string
}

Event is a type of message that can be fed to callbacks describing the event and the key of the thing that happened.

func (*Event) IsEmpty added in v0.1.0

func (e *Event) IsEmpty() bool

IsEmpty is used to test for an empty event being returned.

type EventType added in v0.1.0

type EventType int

An EventType is used to specify what kind of event has happened and is constrained for consumption in downstream select cases. As these IDs are entirely internal and are maintained within a compiled version, iota is used here to make it easier to patch this list in the future.

const (
	EventEntityCreate EventType = iota
	EventEntityUpdate
	EventEntityDestroy

	EventGroupCreate
	EventGroupUpdate
	EventGroupDestroy
)

The callbacks defined below are used to signal what events are handled by the Event subsystem.

type Factory

type Factory func() (DB, error)

Factory defines the function which can be used to register new implementations.

type SearchRequest added in v0.0.12

type SearchRequest struct {
	Expression string
}

SearchRequest is an expression that can be interpreted by the default util search system, or translated by a storage layer to provide a more optimized searching experience.

Directories

Path Synopsis
Package memdb is an entirely in-memory database with no persistence and no concurrency guarantees.
Package memdb is an entirely in-memory database with no persistence and no concurrency guarantees.
Package protodb is one of the simplest databases that just reads and writes protos to the local disk.
Package protodb is one of the simplest databases that just reads and writes protos to the local disk.
Package util handles synthetic functions that aren't implemented natively on a datastore.
Package util handles synthetic functions that aren't implemented natively on a datastore.

Jump to

Keyboard shortcuts

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