executor

package
v0.0.25 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

README

Executor

The executor package providers a DynamoDB Query/Scan executor. The executor returns a channel containing the returning elements or corresponding errors.

The executor abstracts the paginated complexity that can occurs during a DynamoDB query or scan execution, as well as the unmarshalling of all objects. The executor and corresponding channel can be closed by the provided context.

Example

type DBObject struct {
    PK         string `dynamodbav:"PK"`
    SK         string `dynamodbav:"SK"`
    Attribute1 string `dynamodbav:"attr1,omitempty"`
    Attribute2 int    `dynamodbav:"attr2,omitempty"`
}

func query(ctx context.Context, client *dynamodb.Client, query *dynamodb.QueryInput) error {
	e := executor.New(client)
	
	queryContext, cancelFn := context.WithCancel(ctx)
	defer cancelFn()
	
	for object := range e.Query(queryContext, query, executor.WithUnmarshalToItemMapFn[DBOject]()) {
		switch o := object.(type) {
		case error:
		    return o
		case DBObject:
		    fmt.Printf("Get element of partition %s: %+v\n", o.PK, o)
        } 
    }
	
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithLock

func WithLock(lock Lock) func(options *Options)

WithLock will ensure that a lock is refreshed after ever call to the DynamoDB service. The returned options modifier function can be used in a Query or Scan execution

func WithMapFn

func WithMapFn(mapFn func(map[string]types.AttributeValue) (interface{}, error)) func(options *Options)

WithMapFn returns an options modifier function that sets an unmarshalling method of a Scan or Query execution

func WithUnmarshalToItemMapFn added in v0.0.2

func WithUnmarshalToItemMapFn[T any]() func(options *Options)

WithUnmarshalToItemMapFn returns an options modifier function that sets an attributevalue unmarshalling . The returned options modifier function can be used in a Query or Scan execution

Types

type DynamodbClient

type DynamodbClient interface {
	Query(ctx context.Context, params *dynamodb.QueryInput, optFns ...func(*dynamodb.Options)) (*dynamodb.QueryOutput, error)
	Scan(ctx context.Context, params *dynamodb.ScanInput, optFns ...func(options *dynamodb.Options)) (*dynamodb.ScanOutput, error)
}

type Executor

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

Executor can execute DynamoDB query and scan executions while abstracting pagination and unmarshalling complexity

func New added in v0.0.2

func New(client DynamodbClient) *Executor

New creates a new DynamoDB query/scan executor. The executor will execute on the DynamodbClient given as client parameter.

func (*Executor) Query

func (e *Executor) Query(ctx context.Context, query *dynamodb.QueryInput, optFns ...func(options *Options)) <-chan interface{}

Query executes a DynamoDB query. The method returns a channel containing the objects or errors if the execution or unmarshalling fails

func (*Executor) Scan

func (e *Executor) Scan(ctx context.Context, scan *dynamodb.ScanInput, optFns ...func(options *Options)) <-chan interface{}

Scan executes a DynamoDB scan. The method returns a channel containing the objects or errors if the execution or unmarshalling fails

type Lock

type Lock interface {
	Refresh(ctx context.Context) error
}

type Options

type Options struct {
	// MapFn is used to map all returned elements in the executor
	MapFn func(map[string]types.AttributeValue) (interface{}, error)

	// Lock if not nil Lock is refreshed after every call
	// Note there are no guarantees that retrieved data is still locked by the lock
	Lock Lock
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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