tiny

package module
v0.0.0-...-8c94665 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2016 License: MIT Imports: 5 Imported by: 0

README

tinytable

TinyTable is a small database abstraction built on top of Bolt DB modeled after Google's Big Table.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	Key   []byte
	Value []byte
}

Column represents a single column for a record.

func (Column) Int64

func (c Column) Int64() int64

Int64 reads a int64 from the value. If the length of the value is not 8 bytes, 0 will be returned.

func (Column) Uint64

func (c Column) Uint64() uint64

Uint64 reads a uint64 from the value. If the length of the value is not 8 bytes, 0 will be returned.

type ColumnFamily

type ColumnFamily struct {

	// Name is the name of the column family.
	Name []byte

	// Columns is a list of columns in the column family.
	Columns []Column
}

ColumnFamily is a group of columns for a single record.

func (ColumnFamily) GetColumn

func (cf ColumnFamily) GetColumn(key []byte) (Column, error)

GetColumn returns a column by key if it exists for this row. Otherwise, an error is returned.

type DB

type DB interface {

	// ListTables lists all the table names in the database.
	ListTables() [][]byte

	// GetOrCreateTable returns a table and creating it if id doesn't exist.
	GetOrCreateTable(name []byte) (Table, error)

	// DropTable drops a table from the database.
	DropTable(name []byte) error

	// Close closes the database for future reads and writes.
	Close() error
}

DB is a small database abstraction built on top of Bolt DB modelled after Google's Big Table.

func Open

func Open(filename string, mode os.FileMode) (DB, error)

Open creates a new database if it doesn't exist or opens an existing database if it does.

type Row

type Row struct {

	// RowKey is the unique record ID.
	RowKey []byte

	// ColumnFamilies is a list of column families for a single row.
	ColumnFamilies []ColumnFamily
}

Row represents a single record in a Table.

func (Row) GetColumnFamily

func (r Row) GetColumnFamily(name []byte) (ColumnFamily, error)

GetColumnFamily returns a column family by name if it exists for this row. Otherwise an error is returned.

type Table

type Table interface {

	// GetName returns the name of the table.
	GetName() []byte

	// WriteRows writes a list of rows to the table overwritting any existing values that overlap.
	WriteRows(r ...Row) error

	// WriteColumns writes a column to a row and column family returning an error if there is one. The row and column family
	// will be created if they do not exist.
	WriteColumns(r []byte, cf []byte, c ...Column) error

	// IncrementColumn increments the value of a column by one. If the row or column family does not exist, they will be
	// created and return an error if it fails. If the column does not exist, a value will be created to store an
	// unsigned 64-bit integer. If the existing value is not 8 bytes, an error will be returned. Otherwise the value will be
	// incremented.
	IncrementColumn(r, cf, c []byte, v int) error

	// ReadRow reads a single row from the table. Returns an error if the row does not exist.
	ReadRow(key []byte) (Row, error)

	// ScanRows scans a table for all rows with the given prefix. Note: All rows should be read from the channel to avoid memory leak.
	ScanRows(prefix []byte) chan Row

	// ScanColumns scans a row and column family for all columns with the given prefix. Note: All columns should be read from the channel to avoid memory leaks.
	ScanColumns(r, cf []byte, prefix []byte) chan Column
}

Table represents a table in the database.

Jump to

Keyboard shortcuts

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