Documentation ¶
Index ¶
- Constants
- Variables
- func DeleteEach(ctx context.Context, d Deleter, f *Filter) error
- func FilterIterator(it LazyTuple, f *Filter, next func() bool) bool
- func TableSize(ctx context.Context, t Table, f *Filter, exact bool) (int64, error)
- func Update(ctx context.Context, s Store, update func(tx Tx) error) error
- func View(ctx context.Context, s Store, view func(tx Tx) error) error
- type Data
- type DataFilter
- type DataFilters
- type Deleter
- type Field
- type Filter
- type Header
- func (t Header) Clone() Header
- func (t Header) DataByName(name string) (*Field, int)
- func (t Header) KeyByName(name string) (*KeyField, int)
- func (t Header) Validate() error
- func (t Header) ValidateData(d Data) error
- func (t Header) ValidateKey(k Key, insert bool) error
- func (t Header) ValidatePref(k Key) error
- type Iterator
- type Key
- type KeyField
- type KeyFilter
- type KeyFilters
- type KeyType
- type Keys
- type LazyTuple
- type ScanOptions
- type Scanner
- type Sortable
- type Sorting
- type Store
- type Table
- type TableInfo
- type Tuple
- type Tx
- type Type
- type UpdateOpt
- type Value
Constants ¶
const ( SortAsc = Sorting(+1) SortAny = Sorting(0) SortDesc = Sorting(-1) )
Variables ¶
var ( ErrNotFound = errors.New("tuple: not found") ErrTableNotFound = errors.New("tuple: table not found") ErrTableExists = errors.New("tuple: table already exists") ErrExists = errors.New("tuple: this key already exists") ErrReadOnly = errors.New("tuple: read-only database") )
var ErrWildGuess = errors.New("can only guess the size")
ErrWildGuess returned if the the size can only be randomly guessed by the backend without scanning the data.
Functions ¶
func TableSize ¶
TableSize returns a number of records in a table matching the filter. If exact is set to false, an estimate will be returned. If estimate cannot be obtained without scanning the whole table, ErrWildGuess will be returned with some random number.
Types ¶
type DataFilter ¶
DataFilter controls if a payload should be considered or not.
type DataFilters ¶
type DataFilters []filter.ValueFilter
DataFilters applies value filters to individual payload components. Filter will reject the value if its length is different. Nil filters are allowed in the slice to indicate no filtering.
func (DataFilters) FilterData ¶
func (arr DataFilters) FilterData(d Data) bool
type Filter ¶
type Filter struct { KeyFilter DataFilter }
Filter is a tuple filter.
func (*Filter) FilterData ¶
func (*Filter) FilterTuple ¶
type Header ¶
type Header struct { Name string // name of the table Key []KeyField // primary key fields Data []Field // payload fields }
Header describes a schema of tuples table.
func (Header) DataByName ¶
DataByName finds a payload field by a name, or returns nil if it not exists. It also returns an index in the tuple payload.
func (Header) KeyByName ¶
KeyByName finds a key field by a name, or returns nil if it not exists. It also returns an index in the tuple key.
func (Header) ValidateData ¶
ValidateData verifies that specific payload is valid for this table.
func (Header) ValidateKey ¶
ValidateKey verifies that specific key is valid for this table.
func (Header) ValidatePref ¶
ValidatePref verifies that specific key prefix is valid for this table.
type Iterator ¶
type Iterator interface { base.Iterator // Reset the iterator to the starting state. Closed iterator can not reset. Reset() // Key returns a primary key of the tuple. Key() Key // Data returns a payload the tuple. Data() Data }
Iterator is an iterator over a tuple store.
type KeyField ¶
type KeyField struct { Name string // field name Type KeyType // field type Auto bool // autoincrement }
KeyField is a single primary key field used in tuple.
type KeyFilters ¶
type KeyFilters []filter.ValueFilter
KeyFilters applies value filters to individual key components. If key is shorter, nil value is passed to the filter.
func (KeyFilters) FilterKey ¶
func (arr KeyFilters) FilterKey(k Key) bool
type KeyType ¶
type KeyType = values.SortableType
KeyType is a value type that can be sorted after serialization.
type ScanOptions ¶
type ScanOptions struct { // KeysOnly is a hint for backend to omit fetching keys for an iterator. KeysOnly bool // Sort is an optional sorting order for a tuple key. Defaults to a native order of the backend. Sort Sorting // Filter is an optional filter for tuples. Filter *Filter // Limit limits the maximal number of tuples to return. Limit <= 0 indicates an unlimited number of results. Limit int }
type Scanner ¶
type Scanner interface { // Scan iterates over all tuples matching specific parameters. Scan(ctx context.Context, opt *ScanOptions) Iterator }
type Store ¶
type Store interface { base.DB // Tx opens a read-only or read-write transaction in the tuple store. Tx(ctx context.Context, rw bool) (Tx, error) // View provides functional-style read-only transactional access the tuple store. View(ctx context.Context, view func(tx Tx) error) error // Update provides functional-style read-write transactional access to the tuple store. Update(ctx context.Context, update func(tx Tx) error) error // Table returns a table info. It returns ErrTableNotFound if table does not exists. // TableInfo can be used to open a Table from transactions more efficiently. Table(ctx context.Context, name string) (TableInfo, error) // ListTables lists all available tables. ListTables(ctx context.Context) ([]TableInfo, error) }
Store is an interface for tuple stores with a strict schema.
type Table ¶
type Table interface { TableInfo // Drop clears the data and removes the table. Drop(ctx context.Context) error // Clear removes all tuples from the table. Clear(ctx context.Context) error // GetTuple fetches one tuple with a specific key. // It returns ErrNotFound if tuple does not exists. GetTuple(ctx context.Context, key Key) (Data, error) // GetTupleBatch fetches multiple tuples with provided keys. // Nil values in the returned slice indicates that specific key does not exists. GetTupleBatch(ctx context.Context, keys []Key) ([]Data, error) // InsertTuple creates a new tuple. If the tuple with specified key already exists it returns ErrExists. InsertTuple(ctx context.Context, t Tuple) (Key, error) // UpdateTuple rewrites specified tuple. Options can be provided to create a tuple if ti does not exists. // If this flag is not provided and the tuple is missing, it returns ErrNotFound. UpdateTuple(ctx context.Context, t Tuple, opt *UpdateOpt) error // DeleteTuples removes all tuples that matches a filter. DeleteTuples(ctx context.Context, f *Filter) error // Scanner adds the Scan function. Scanner }
Table represents an opened tuples table with a specific type (schema).
type TableInfo ¶
type TableInfo interface { // Header returns a tuple header used in this table. Header() Header // Open binds a table to the transaction and opens it for further operations. Open(ctx context.Context, tx Tx) (Table, error) }
TableInfo represent a metadata of a tuple table.
type Tx ¶
type Tx interface { base.Tx // Table opens a tuple table. It returns ErrTableNotFound if table does not exists. Table(ctx context.Context, name string) (Table, error) // ListTables lists all available tables. ListTables(ctx context.Context) ([]Table, error) // CreateTable creates and opens a table with a specific schema. CreateTable(ctx context.Context, table Header) (Table, error) }
Tx is a transaction over a tuple store.
Directories ¶
Path | Synopsis |
---|---|
Package tuplepb is a generated protocol buffer package.
|
Package tuplepb is a generated protocol buffer package. |