database

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2022 License: BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const IndexSize int = 100
View Source
const SegmentSize int = 10000

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database struct {
	Version  int
	Name     string
	Path     string
	Segments []Segment
	Current  int

	TopicLookup []string
	TopicCount  int
	// contains filtered or unexported fields
}

func NewDatabase

func NewDatabase(log zerolog.Logger, name string, location string) (*Database, error)

NewDatabase creates a new database object in memory and creates the directory and files on disk for storing the data location is the base directory for creating the database

func (*Database) AddTopic

func (d *Database) AddTopic(topic string) int

func (*Database) Append

func (d *Database) Append(data []byte, topic string)

Append to the end of the database

func (*Database) Retrieve

func (d *Database) Retrieve(q Query) []Entry

Retrieve a list of datum from the database matching some query TODO: Eventually, this should return a proper result set

type Datum

type Datum struct {
	Delta   time.Duration
	TopicID int
	Data    []byte
}

type Entries

type Entries []Entry

type Entry

type Entry struct {
	Time  time.Time
	Topic string
	Data  []byte
}

An Entry is a hydrated Datum, where the time and topic have been expanded.

func ParseEntry

func ParseEntry(s string) (Entry, error)

func (*Entry) ToString

func (e *Entry) ToString() string

type Filter

type Filter func(Entries) Entries

A Filter that takes a list of Datum and returns a filtered list of Datum.

type Filters

type Filters []Filter

func (*Filters) Execute

func (f *Filters) Execute() Result

type Query

type Query struct {
	Quantifier     string
	Topics         []string
	Range          *TimeRange // nil means entire history (no time range)
	RangeSemantics string     // none, before, since, between
}

The Query object represents a single query on a database. It contains the 4 main variables of a query:

  • Quantifier
  • Topic(s)
  • Time Range
  • Data Predicate (TODO!)

type Result

type Result struct {
	Data Entries
}

Result wraps a slice of Items. TODO: Track query statistics and the like in here

type Segment

type Segment struct {
	HeadTime time.Time
	Series   [SegmentSize]Datum
	Size     int
}

func (*Segment) Append

func (s *Segment) Append(d *Datum) (bool, error)

func (*Segment) FindApproximateDatum

func (s *Segment) FindApproximateDatum(desired time.Time) (int, Datum)

type TimeRange

type TimeRange struct {
	Start time.Time
	End   time.Time
}

type WriteAheadLog

type WriteAheadLog struct {
	LogPath string
}

func (*WriteAheadLog) AddEvent

func (w *WriteAheadLog) AddEvent(d *Datum)

func (*WriteAheadLog) AddSegment

func (w *WriteAheadLog) AddSegment(t time.Time)

func (*WriteAheadLog) AddTopic

func (w *WriteAheadLog) AddTopic(t string)

func (*WriteAheadLog) ApplyToDB

func (w *WriteAheadLog) ApplyToDB(d *Database)

Jump to

Keyboard shortcuts

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