Documentation ¶
Overview ¶
Package record is a database system build on badgerDB
Index ¶
Constants ¶
const TimeBytesLength = 12
TimeBytesLength is the byte count of the array returned by TimeToBytes
Variables ¶
var ErrDupRecordNames = errors.New("record.Config.Records() returned duplicate record names")
ErrDupRecordNames more than one record with same name defined by Config.Records()
var ErrNoConfigRecords = errors.New("record.Config.Records() returned empty slice")
ErrNoConfigRecords no record types defined by Config.Records()
var ErrNotFound = errors.New("not found")
ErrNotFound indicates the requested item was not found
var ErrRecordNameLenNot3 = errors.New(
"record.Config.Records() returned record with name not length 3 in bytes",
)
ErrRecordNameLenNot3 a record with name of length not 3 defined by Config.Records()
var ErrRecordNotDefined = errors.New("Record type used that was not included in config")
ErrRecordNotDefined indicates a method was called with a record that was not defined in the config
Functions ¶
func BytesToTime ¶
BytesToTime converts a []byte to time.Time
func TimeToBytes ¶
TimeToBytes convert time.Time to []byte in a sortable way
Types ¶
type Record ¶
type Record interface { // Name must return the three character code that represents this record type. This must be a // constant for a specific implementation and must be unique across all record types provided // by Config.Records. This code must consist of all lowercase letters and be exactly 3 // characters long Name() string // Index must return a byte slice representation of the indicated index, ErrInvalidIndex, or // some other error indicating the current index value can not be marshaled. Index(0) must not // return ErrInvalidIndex and there can be no gaps. currently a max of 3 indexes is supported. Key() ([]byte, error) SetKey(data []byte) error // TTL should return the time to live of the record once written. If this returns 0 the // record will not have a time to live set TTL() time.Duration // Record must return a pointer to the struct representation of this record Record() interface{} }
Record represents an individual record as well as the record type
type Recorder ¶
type Recorder interface { // Write saves a record in the database, the provided records Key() and Record() are // what will be saved. If a record with the same key already exists it will be // overwritten Write(record Record) error // Read retrives a record from the database using the key in the provided Record. The // provided records Record() will be overwritten with the retrived data. If the // requested record is not found ErrNotFound will be returned Read(record Record) error // Delete removes the record from the database with a key index matching the provided // records key. record.Record() will not be used or updated. Delete(record Record) error // Range reads records starting at the key in the provided record until the call back function // returns false or the last record of the provided type is read Range(record Record, prefixBytes int, reverse bool, cb func(record Record) bool) error }
Recorder allows writting, reading and searching records
type RecorderDB ¶
type RecorderDB interface { Recorder // WriteBuffered works like Write except the record is queued to be written by a background // worked thread. This should allow several writes to be done under the same transaction for // better efficiency. Should only be used for non-critical writes like log messages. WriteBuffered(record Record) error DeletePrefix(record Record, keyPrefix []byte) error GetSequence(record Record, key []byte) (store.Sequence, error) NewTransaction(update bool) RecorderTxn }
RecorderDB is an interface to a base database
func New ¶
func New(store store.Store, records []Record) (RecorderDB, error)
New creates a RecorderDB records must have one instance of each record type that will be used in this database. New will check that the Name() of all these records are unique. These records may be used as work areas and should be considered owned by this library
type RecorderTxn ¶
RecorderTxn is an interface to a transaction created by RecorderDB.NewTransaction. Discard or Commit must be called to end the transaction. There is no harm in calling Discard after Commit so a good pattern is to defer Discard() right after RecorderDB.NewTransaction