engine

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2024 License: MIT Imports: 12 Imported by: 0

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

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 New

func New(tr facade.Transactor, opts ...Option) Engine

func (*Engine) Clear

func (x *Engine) Clear(query keyval.KeyValue) error

Clear performs a clear operation for a single key-value. The given query must belong to class.Clear.

func (*Engine) Directories

func (x *Engine) Directories(ctx context.Context, query keyval.Directory) chan stream.DirErr

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

func (x *Engine) ReadSingle(query keyval.KeyValue, opts SingleOpts) (*keyval.KeyValue, error)

ReadSingle performs a read operation for a single key-value. The given query must belong to class.ReadSingle.

func (*Engine) Set

func (x *Engine) Set(query keyval.KeyValue) error

Set preforms a write operation for a single key-value. The given query must belong to class.Constant.

func (*Engine) Transact

func (x *Engine) Transact(f func(Engine) (interface{}, error)) (interface{}, error)

Transact wraps a group of Engine method calls under a single transaction. The newly created Engine inherits the logger & byte order of the parent engine. Any changes to the logger or byte order of the new Engine has no effect on the parent Engine.

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.

func ByteOrder

func ByteOrder(order binary.ByteOrder) Option

ByteOrder sets the endianness used for encoding/decoding values. This method must not be called concurrently with other methods.

func Logger

func Logger(log zerolog.Logger) Option

Logger enables debug logging using the provided logger. This method must not be called concurrently with other methods.

type RangeOpts

type RangeOpts struct {
	Reverse bool
	Filter  bool
	Limit   int
}

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.

Directories

Path Synopsis
Package facade provide interfaces for FDB APIs.
Package facade provide interfaces for FDB APIs.
Package stream performs range-reads and filtering.
Package stream performs range-reads and filtering.

Jump to

Keyboard shortcuts

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