queryer

package
Version: v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidQueryRunnerSignature = errors.New("queryRunner must have 3 input params")
	ErrQueryRunnerIsNotAFunction   = errors.New("queryRunner is not a function")
	ErrFirstArgHasInvalidType      = errors.New("first input argument must have context.Context type")
	ErrSecondArgHasInvalidType     = errors.New("second input argument must be a struct")
	ErrThirdArgHasInvalidType      = errors.New("third input argument must be a pointer to a struct")
)

Guard errors

View Source
var ErrNotFound = errors.New("query runner not found")

ErrNotFound indicates that the query runner was not registered for the given query.

Functions

This section is empty.

Types

type Dispatcher

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

Dispatcher dispatches the given query to a pre-registered query runner.

func NewDispatcher

func NewDispatcher() *Dispatcher

NewDispatcher creates a new instance of Dispatcher.

func (*Dispatcher) RegisterQueryRunner

func (d *Dispatcher) RegisterQueryRunner(queryRunnerFnName string, queryRunnerFn QueryRunnerFn)

RegisterQueryRunner registers a query runner. TODO: add guards for an empty runner name and a nil runner.

func (*Dispatcher) RunQuery

func (d *Dispatcher) RunQuery(ctx context.Context, q interface{}, r interface{}) error

RunQuery dispatches the given query to a pre-registered query runner and runs the query. Implements QueryRunner interface.

type QueryRunner

type QueryRunner interface {
	RunQuery(ctx context.Context, query interface{}, report interface{}) error
}

QueryRunner runs a query and returns the corresponding result setting report value by ref.

type QueryRunnerFn

type QueryRunnerFn func(ctx context.Context, query interface{}, report interface{}) error

QueryRunnerFn defines a query runner signature.

func Adapt

func Adapt(queryRunner interface{}) (QueryRunnerFn, error)

Adapt transforms a concrete query runner into a generic one. A concrete runner function should have 3 arguments: - ctx context.Context, - q - a query struct, - r - a pointer to a report struct.

The returned param must have error type. An example signature may look like:

func(ctx context.Context, q TestQuery, r *TestReport) error

func MustAdapt

func MustAdapt(queryRunner interface{}) QueryRunnerFn

MustAdapt acts Like Adapt, but panics on error.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL