mrT

package module
v0.0.0-...-70a847a Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2018 License: MIT Imports: 15 Imported by: 5

README

Mr.T GoDoc Status Go Report Card

Mr.T (Mr. Transaction) is a database persistence layer. The goal of this library is to provide a simple and elegant way for a database to manage it's data file persistence. Some of the core features:

  • Key/Value support*
  • Thread-safe transactions
  • ACID-compliant safety for database actions

*To support multi-level maps, please use concatinated strings to represent buckets

Usage

For usage examples, please see the examples directory OR see direct links below:

Documentation

Index

Constants

View Source
const (
	// NilLine represents a zero-value for line types
	NilLine byte = iota
	// TransactionLine is a line with the transaction tag for the data lines following it
	TransactionLine
	// ReplayLine is a line which signals the replay through a transaction
	ReplayLine
	// CommentLine is a comment line, will be ignored when parsing data
	// Note: This line type will always ignore middleware
	CommentLine
	// PutLine is for setting data
	PutLine
	// DeleteLine is for removing data
	DeleteLine
)
View Source
const (
	// ErrInvalidLine is returned when an invalid line is encountered while parsing
	ErrInvalidLine = errors.Error("invalid line")
	// ErrNoTxn is returned when no transactions are available
	ErrNoTxn = errors.Error("no transactions available")
	// ErrInvalidTxn is returned when an invalid transaction is provided
	ErrInvalidTxn = errors.Error("transaction does not exist")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionInfo

type ActionInfo struct {
	Put   bool   `json:"put"`
	Key   string `json:"key"`
	Value string `json:"value"`
}

ActionInfo is information about an action

type Filter

type Filter interface {
	Filter(buf *bytes.Buffer) (ok bool, err error)
}

Filter is a basic filtering interface

type FilterFn

type FilterFn func(*bytes.Buffer) error

FilterFn is a basic filter fn

type ForEachFn

type ForEachFn func(lineType byte, key, value []byte) (err error)

ForEachFn is used for iterating through entries

type ForEachRawFn

type ForEachRawFn func(line []byte) (err error)

ForEachRawFn is used for iterating through raw entries

type ForEachTxnFn

type ForEachTxnFn func(ti *TxnInfo) (err error)

ForEachTxnFn is used for iterating through transactions

type Match

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

Match is a transaction matching filter

func NewMatch

func NewMatch(txnID string) *Match

NewMatch will return a new match filter

func (*Match) Filter

func (m *Match) Filter(buf *bytes.Buffer) (ok bool, err error)

Filter interface fulfillment

type MrT

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

MrT is Mister Transaction, he manages file transactions He also pities a fool

func New

func New(dir, name string, mws ...middleware.Middleware) (mp *MrT, err error)

New will return a new instance of MrT

func (*MrT) Archive

func (m *MrT) Archive(populate TxnFn) (err error)

Archive will archive the current data

func (*MrT) Close

func (m *MrT) Close() (err error)

Close will close MrT

func (*MrT) Comment

func (m *MrT) Comment(b []byte) (err error)

Comment will write a comment line

func (*MrT) Export

func (m *MrT) Export(txnID string, w io.Writer) (err error)

Export will export from a given transaction id

func (*MrT) Filter

func (m *MrT) Filter(txnID string, archive bool, fn FilterFn, filters ...Filter) (err error)

Filter will iterate through filtered lines

func (*MrT) ForEach

func (m *MrT) ForEach(txnID string, archive bool, fn ForEachFn) (err error)

ForEach will iterate through all the file lines starting from the provided transaction id

func (*MrT) ForEachRaw

func (m *MrT) ForEachRaw(txnID string, archive bool, fn ForEachRawFn) (err error)

ForEachRaw will iterate through all the raw file lines starting from the provided transaction id

func (*MrT) ForEachTxn

func (m *MrT) ForEachTxn(txnID string, archive bool, fn ForEachTxnFn) (err error)

ForEachTxn will iterate through all the file transactions starting from the provided transaction id

func (*MrT) GetFromRaw

func (m *MrT) GetFromRaw(raw []byte) (key, value []byte, err error)

GetFromRaw will get a key and value line from a raw entry

func (*MrT) Import

func (m *MrT) Import(r io.Reader, fn ForEachFn) (lastTxn string, err error)

Import will import a reader

func (*MrT) LastTxn

func (m *MrT) LastTxn() (txnID string, err error)

LastTxn will get the last transaction id

func (*MrT) Txn

func (m *MrT) Txn(fn TxnFn) (err error)

Txn will create a transaction

type ReadSeekCloser

type ReadSeekCloser interface {
	io.Reader
	io.Seeker
	io.Closer
}

ReadSeekCloser incorporates reader, seeker, and closer interfaces

type Txn

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

Txn is a transaction for persistence actions

func (*Txn) Delete

func (t *Txn) Delete(key []byte) error

Delete will remove a value

func (*Txn) Put

func (t *Txn) Put(key, value []byte) error

Put will set a value

type TxnFn

type TxnFn func(txn *Txn) error

TxnFn is used for transactions

type TxnInfo

type TxnInfo struct {
	// Transaction id
	ID string `json:"id"`
	// Timestamp of transaction
	TS int64 `json:"ts"`
	// List of actions
	Actions []*ActionInfo `json:"actions"`
}

TxnInfo is information about a transaction

type WriteFn

type WriteFn func(buf *bytes.Buffer, lineType byte, key, value []byte) error

WriteFn is the function signature for calling mrT.writeLn

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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