db

package
v0.12.6 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotConnected = errors.New("not connected to the database")
	ErrNotFound     = errors.New("record not found")
)
View Source
var KeyCurrentStatus = []byte{0, 0, 0, 0, 0, 0, 114, 111, 116, 97, 116, 105, 111, 110, 97, 108}

Functions

func Close

func Close() (err error)

Close the connection to the leveldb and allow reconnect.

func Connect

func Connect(path string, readonly bool) (err error)

Connect to the leveldb, opening the database at the specified path.

func Delete

func Delete(m Model) (err error)

Delete a model from the database.

func Get

func Get(key []byte, m Model) (err error)

Get a value from the database by the key and unmarshal it into the specified model.

func LastServiceStatus

func LastServiceStatus(id uuid.UUID, m Model) (err error)

Because service status keys are ordered by time using ULIDs, it is possible to fetch the last service status for a service ID by using the ID as a prefix to iterate over the keys and return the last item; unmarshaling it into the specified model.

func NewIterator

func NewIterator(slice *util.Range) iterator.Iterator

Create a new iterator - note that it is possible to close the DB connection during iteration, which will cause the iterator to return a leveldb.ErrClosed error.

func Put

func Put(m Model) (err error)

Put a value into the database by marshaling it from the specified model.

Types

type Model

type Model interface {
	Key() ([]byte, error)
	Unmarshal([]byte) error
	Marshal() ([]byte, error)
}

type Transaction

type Transaction struct {
	leveldb.Transaction
}

func BeginTx

func BeginTx() (_ *Transaction, err error)

OpenTransaction opens an atomic DB transaction. Only one transaction can be opened at a time. Subsequent call to Write and OpenTransaction will be blocked until in-flight transaction is committed or discarded. The returned transaction handle is safe for concurrent use.

func (*Transaction) Delete

func (t *Transaction) Delete(m Model) (err error)

func (*Transaction) Get

func (t *Transaction) Get(key []byte, m Model) (err error)

func (*Transaction) NewIterator

func (t *Transaction) NewIterator(slice *util.Range) iterator.Iterator

func (*Transaction) Put

func (t *Transaction) Put(m Model) (err error)

Jump to

Keyboard shortcuts

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