database

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: BSD-2-Clause Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const FossilDBVersion = 2

FossilDBVersion is the version of the database as recorded on disk. This is primarily used for migration.

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

Variables

This section is empty.

Functions

func MigrateDatabaseIfNeeded added in v0.2.0

func MigrateDatabaseIfNeeded(p string) error

MigrateDatabaseIfNeeded has all the logic necessary to migrate from an old database through an arbitrary number of versions to the current database version. It does this through use of 3 types of handler functions:

  • A deserialization function, specific to a source DB version. This function is responsible for reading the on-disk structure of a specific database format.

  • Some number of migration functions. Migration functions map from version n - 1 -> n, so each function will be called in succession, passing the results of the previous migration.

  • A cleanup function, specific to a source DB version. This function is responsible for cleaning up any un-needed files after migration.

Types

type Database

type Database struct {
	Version      uint32
	Segments     []Segment
	Current      uint32
	TopicLookup  []string
	SchemaLookup []schema.Object
	TopicCount   int
	STime        time.Time // Last serialize time
	Name         string    // <-- We do not save to disk, starting here
	Path         string
	// contains filtered or unexported fields
}

func NewDatabase

func NewDatabase(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, schema string) int

func (*Database) Append

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

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

func (*Database) SchemaForTopic added in v0.2.0

func (d *Database) SchemaForTopic(topic string) schema.Object

func (*Database) Stats added in v0.2.0

func (db *Database) Stats() Stats

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 `json:"time"`
	Topic  string    `json:"topic"`
	Schema string    `json:"schema"`
	Data   []byte    `json:"data"`
}

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 Stats added in v0.2.0

type Stats struct {
	Segments      int
	TopicCount    int
	SerializeTime time.Time
}

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, s 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