Documentation ¶
Overview ¶
Package engine executes queries.
Example ¶
package main import ( "github.com/apple/foundationdb/bindings/go/src/fdb" "github.com/apple/foundationdb/bindings/go/src/fdb/directory" "github.com/janderland/fdbq/engine" "github.com/janderland/fdbq/engine/facade" "github.com/janderland/fdbq/keyval" ) func main() { eg := engine.New(facade.NewTransactor(fdb.MustOpenDefault(), directory.Root())) key := keyval.Key{ Directory: keyval.Directory{keyval.String("hello"), keyval.String("there")}, Tuple: keyval.Tuple{keyval.Float(33.3)}, } // /hello/there{33.3}=10 query := keyval.KeyValue{Key: key, Value: keyval.Int(10)} if err := eg.Set(query); err != nil { panic(err) } didWrite, err := eg.Transact(func(e engine.Engine) (interface{}, error) { // /hello/there{33.3}=<> query = keyval.KeyValue{Key: key, Value: keyval.Variable{}} result, err := eg.ReadSingle(query, engine.SingleOpts{}) if err != nil { return nil, err } if result != nil { return false, nil } // /hello/there{33.3}=15 query = keyval.KeyValue{Key: key, Value: keyval.Int(15)} if err := eg.Set(query); err != nil { return nil, err } return true, nil }) if err != nil { panic(err) } if didWrite.(bool) { panic("didWrite should be false") } }
Output:
Index ¶
- type Engine
- func (x *Engine) Clear(query keyval.KeyValue) error
- func (x *Engine) Directories(ctx context.Context, query keyval.Directory) chan stream.DirErr
- func (x *Engine) ReadRange(ctx context.Context, query keyval.KeyValue, opts RangeOpts) chan stream.KeyValErr
- func (x *Engine) ReadSingle(query keyval.KeyValue, opts SingleOpts) (*keyval.KeyValue, error)
- func (x *Engine) Set(query keyval.KeyValue) error
- func (x *Engine) Transact(f func(Engine) (interface{}, error)) (interface{}, error)
- type Option
- type RangeOpts
- type SingleOpts
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine provides methods which execute queries. Each valid class.Class has a corresponding method for executing that class of query. The methods will fail if a query of the wrong class in provided. Unless Engine.Transact is used, each query is executed in its own transaction.
func (*Engine) Clear ¶
Clear performs a clear operation for a single key-value. The given query must belong to class.Clear.
func (*Engine) Directories ¶
Directories reads directories from the directory layer. If the query contains a keyval.Variable, multiple directories may be returned. If the query doesn't contain a keyval.Variable, at most a single directory will be returned. After an error occurs or all directories have been read, the returned channel is closed. If the provided context is canceled, then the read operation will be stopped after the latest FDB call finishes.
func (*Engine) ReadRange ¶
func (x *Engine) ReadRange(ctx context.Context, query keyval.KeyValue, opts RangeOpts) chan stream.KeyValErr
ReadRange performs a read across a range of key-values. The given query must belong to class.ReadRange. After an error occurs or the entire range is read, the returned channel is closed. If the provided context is canceled, then the read operation will be stopped after the latest FDB call finishes.
func (*Engine) ReadSingle ¶
ReadSingle performs a read operation for a single key-value. The given query must belong to class.ReadSingle.
func (*Engine) Set ¶
Set preforms a write operation for a single key-value. The given query must belong to class.Constant.
type Option ¶
type Option func(*Engine)
Option can be passed as a trailing argument to the New function to modify properties of the created Engine.
type RangeOpts ¶
RangeOpts configures how an Engine.ReadRange call is executed.
type SingleOpts ¶
type SingleOpts struct {
Filter bool
}
SingleOpts configures how an Engine.ReadSingle call is executed.