boltql

package module
v0.0.0-...-fa5532c Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2017 License: MIT Imports: 6 Imported by: 0

README

boltql

A layer above BoltDB that allows table and indices

Install

go get github.com/raff/boltql

Documentation

https://godoc.org/github.com/raff/boltql

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NO_TABLE         = bolt.ErrBucketNotFound
	NO_INDEX         = bolt.ErrBucketNotFound
	ALREADY_EXISTS   = bolt.ErrBucketExists
	NO_SCHEMA        = errors.New("no schema for table")
	SCHEMA_CORRUPTED = errors.New("schema corrupted")
	NO_KEY           = errors.New("key not found")
	BAD_VALUES       = errors.New("bad values")

	// this is just a marker for auto-increment fields
	AUTOINCREMENT = &struct{}{}
)

Functions

This section is empty.

Types

type DataRecord

type DataRecord interface {
	ToFieldList() []interface{}
	FromFieldList([]interface{})
}

A DataRecord is the interface for elements that can be stored in a table. A DataRecord needs to implement two methods:

ToFieldList() should convert the record fields into a list of values, preserving their order (i.e. the same fields should always be in the same position)

FromFieldList() should fill the record with values from the input list. The order of values is the same as what was returned from ToFieldList()

type DataStore

type DataStore bolt.DB

A DataStore is the main interface to a BoltDB database

func Open

func Open(dbfile string) (*DataStore, error)

Open the database (create if it doesn't exist)

func (*DataStore) Close

func (d *DataStore) Close() error

Close the database

func (*DataStore) CreateTable

func (d *DataStore) CreateTable(name string) (*Table, error)

Create table if doesn't exist

func (*DataStore) GetTable

func (d *DataStore) GetTable(name string) (*Table, error)

Get existing Table

func (*DataStore) SetBulk

func (d *DataStore) SetBulk(b bool)

type Table

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

A Table is a container for the table name and indices

func (*Table) CreateIndex

func (t *Table) CreateIndex(index string, nilFirst bool, fields ...uint64) error

Create an index given the name (index) and a list of field positions used to create a composite key.

nilFirst specifies if nil values should sort first (lowest possible value) or last (highest possible value)

The field position should corrispond to the entries in DataRecord ToFieldList() and FromFieldList()

func (*Table) Delete

func (t *Table) Delete(index string, key DataRecord) error

Delete a record from the table, given the index and the key

func (*Table) ForEach

func (t *Table) ForEach(index string, callback func(k, v []byte) error) error

Scan through all records in an index. Calls specified callback with key and value (as []byte, not decoded)

func (*Table) Get

func (t *Table) Get(index string, key, res DataRecord) error

Get a record from the table, given the index and the key

func (*Table) Put

func (t *Table) Put(rec DataRecord) (uint64, error)

Add a record to the table, updating all indices. If a record with the same key exists, it's updated.

func (*Table) Scan

func (t *Table) Scan(index string, ascending bool, start, res DataRecord, callback func(DataRecord, error) bool) error

Get all records sorted by index keys (ascending or descending) Call user function with record content or error

func (*Table) String

func (t *Table) String() string

Implement the Stringer interface

Jump to

Keyboard shortcuts

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