db

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2022 License: MIT Imports: 8 Imported by: 1

README

db

The database at the heart of SegmentQ

Go Report Card Go Reference Build Reliability Rating Quality Gate Status Coverage

Install

Usage

Documentation

Index

Constants

View Source
const (
	RAM      DurabilityProfile = 0
	FastSync DurabilityProfile = 1
	Disk     DurabilityProfile = 2
	InMemory string            = ":memory:"
)

Variables

View Source
var (
	// ErrInternalDBError is used when the internal database returns an error
	ErrInternalDBError   = errors.New("internal database returned an error")
	ErrIndexExists       = errors.New("index already exists")
	ErrIndexUnknown      = errors.New("index is unknown")
	ErrUnknownDataType   = errors.New("data type not supported")
	ErrFieldUnknown      = errors.New("field not part of the index")
	ErrIndexNotSet       = errors.New("index must be set before lookup")
	ErrLookupFailure     = errors.New("could not complete lookup")
	ErrLookupEmpty       = errors.New("no results for lookup")
	ErrSegmentMissing    = errors.New("segment was not available for lookup")
	ErrSegmentNotFound   = errors.New("segment does not exist")
	ErrMarshallingFailed = errors.New("marshalling failed")
	ErrPrimaryKeyMissing = errors.New("index is missing a primary key")
)

Functions

This section is empty.

Types

type Action

type Action interface {
	// contains filtered or unexported methods
}

type ClientConfig

type ClientConfig struct {
	Path       string
	Durability DurabilityProfile
}

type DB

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

func NewDB

func NewDB(ctx context.Context) (*DB, error)

NewDB creates a simple database in memory

func NewDBWithConfig

func NewDBWithConfig(ctx context.Context, config *ClientConfig) (*DB, error)

NewDBWithConfig creates a database using a ClientConfig you specify

func (*DB) CreateIndex

func (db *DB) CreateIndex(indexDefinition *api.IndexDefinition) (*Index, error)

CreateIndex takes an IndexDefinition and returns an Index

func (*DB) DeleteIndex

func (db *DB) DeleteIndex(name string) (*Index, error)

DeleteIndex deletes all segments and the index itself

func (*DB) DeleteSegment

func (db *DB) DeleteSegment(indexName string, segmentKey string) (*Segment, error)

func (*DB) GetAllSegments

func (db *DB) GetAllSegments(indexName string, iter func(segment *api.Segment) bool) error

func (*DB) GetIndexByName

func (db *DB) GetIndexByName(name string) (*Index, error)

GetIndexByName returns the index with the specified name

func (*DB) GetSegmentByKey

func (db *DB) GetSegmentByKey(indexName string, segmentKey string) (*Segment, error)

func (*DB) InsertSegment

func (db *DB) InsertSegment(indexName string, segment *api.Segment) (*Segment, error)

func (*DB) ListIndexes

func (db *DB) ListIndexes() []*api.IndexDefinition

ListIndexes returns an unbuffered list of all indexes TODO maybe some limit to this?

func (*DB) Lookup

func (db *DB) Lookup(indexName string, lookup *api.Lookup) (*Iterator, error)

Lookup is a convenience method on the db object which only returns segment keys

func (*DB) LookupSegments

func (db *DB) LookupSegments(indexName string, lookup *api.Lookup) (*Iterator, error)

LookupSegments returns full segment objects and is slower than Lookup

func (*DB) NewSegment

func (db *DB) NewSegment(indexName string, segment *api.Segment) (*Segment, error)

func (*DB) ReplaceSegment

func (db *DB) ReplaceSegment(indexName string, segmentKey string, newSegment *api.Segment) (*Segment, error)

ReplaceSegment TODO change this to take the Segment as an arg instead of proto

func (*DB) TruncateIndex

func (db *DB) TruncateIndex(name string) error

TruncateIndex is a convenience method to call the Truncate method of an Index, which removes all segments

type DurabilityProfile

type DurabilityProfile int

type Index

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

func (*Index) Create

func (i *Index) Create() error

Create is used when the Index is instantiated directly

func (*Index) Definition

func (i *Index) Definition() *api.IndexDefinition

func (*Index) Delete

func (i *Index) Delete() error

Delete first uses Truncate to clear segment then deletes the index

func (*Index) DeleteSegment

func (i *Index) DeleteSegment(key string) (*Segment, error)

func (*Index) Exists

func (i *Index) Exists() (bool, error)

func (*Index) GetAllSegments

func (i *Index) GetAllSegments(iter func(segment *api.Segment) bool) error

func (*Index) GetSegmentByKey

func (i *Index) GetSegmentByKey(key string) (*Segment, error)

func (*Index) InsertSegment

func (i *Index) InsertSegment(segment *api.Segment) (*Segment, error)

func (*Index) Lookup

func (i *Index) Lookup(lookup *api.Lookup) (*Iterator, error)

Lookup is a convenience method on the index object which only returns segment keys

func (*Index) LookupSegments

func (i *Index) LookupSegments(lookup *api.Lookup) (*Iterator, error)

LookupSegments returns full segment objects and is slower than Lookup

func (*Index) NewSegment

func (i *Index) NewSegment(segment *api.Segment) (*Segment, error)

func (*Index) Proto

func (i *Index) Proto() *api.IndexDefinition

func (*Index) ReplaceSegment

func (i *Index) ReplaceSegment(key string, newSegment *api.Segment) (*Segment, error)

func (*Index) Truncate

func (i *Index) Truncate() error

Truncate deletes all segments from the index

func (*Index) UnmarshallPrimaryValue

func (i *Index) UnmarshallPrimaryValue(value string) (*api.SegmentField, error)

type Iterator

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

func (*Iterator) Next

func (t *Iterator) Next(dst *api.Segment) (key string, err error)

type Key

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

func (*Key) FieldNameAtIndex

func (k *Key) FieldNameAtIndex(fieldIndex int) (string, bool)

FieldNameAtIndex gets the field name from a key at the given index, root == 0

func (*Key) FieldValueIndex

func (k *Key) FieldValueIndex() (string, bool)

FieldValueIndex finds the value index of the segments field value

func (*Key) IndexId

func (k *Key) IndexId() (string, bool)

func (*Key) SegmentKey

func (k *Key) SegmentKey() (string, bool)

SegmentKey finds the value of the segments primary key

func (*Key) String

func (k *Key) String() string

type Lookup

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

func (*Lookup) Run

func (l *Lookup) Run() *Iterator

func (*Lookup) RunOnIndex

func (l *Lookup) RunOnIndex(indexName string) *Iterator

type Segment

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

func (*Segment) Delete

func (s *Segment) Delete() error

func (*Segment) Insert

func (s *Segment) Insert() error

func (*Segment) Proto

func (s *Segment) Proto() *api.Segment

func (*Segment) Replace

func (s *Segment) Replace(new *api.Segment) (*Segment, error)

type Stringer

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

func NewFieldDefinitionStringer

func NewFieldDefinitionStringer(fieldDefinition *api.FieldDefinition) *Stringer

func NewLookupStringer

func NewLookupStringer(field *api.LookupField, iter func(key, value string) bool) *Stringer

func NewSegmentStringer

func NewSegmentStringer(field *api.SegmentField, iter func(key, value string) bool) *Stringer

func (*Stringer) MarshallText

func (s *Stringer) MarshallText() error

func (*Stringer) UnmarshallText

func (s *Stringer) UnmarshallText(value string) (*api.SegmentField, error)

type Txn

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

func NewTxn

func NewTxn(db *DB, safe bool) *Txn

NewTxn requires the DB struct and uses it to perform write safe or non write safe transactions

func (*Txn) AddAction

func (t *Txn) AddAction(action Action)

func (*Txn) Reset

func (t *Txn) Reset()

func (*Txn) Settle

func (t *Txn) Settle() error

Jump to

Keyboard shortcuts

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