inputbuilder

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: 11 Imported by: 0

README

Input Builder

Input builder is a package that provides an easy way to construct dynamic input objects for scan, query and update dynamoDB actions.

There are currenlty three different input builders for three different kind of operations

  • Query Input Builder QueryBuilder: for building DynamoDB query input objects
  • Scan Input Builder ScanBuilder: for building DynamoDB scan input objects
  • Update Input Builder UpdateBuilder: for building DynamoDB update input objects

The focus of the package is to dynamically create filter, condition, query and update expression as well as correct the marshalling of the related values.

Examples

Query input builder
func foo() (*dynamodb.QueryInput, error) {
	qb := inputbuilder.NewQueryBuilder()
	qb.WithTableName("SomeTableName")
	qb.WithHashKeyCondition(conditionexpression.Equal("PK", "partitionKeyValue"))
	qb.WithRangeKeyCondition(conditionexpression.BeginsWith("SK", "startOfSK"))
	
	queryInput := dynamodb.QueryInput{}
	
	err := qb.Build(&queryInput)
	if err != nil {
		return nil, err
	}
	
	return &queryInput, nil
}
Scan input builder
func foo() (*dynamodb.ScanInput, error) {
	sb := inputbuilder.NewScanBuilder()
	sb.WithTableName("SomeTableName")
	sb.WithFilterExpression(conditionexpression.And(conditionexpression.Equal("attribute1", "value1")),conditionexpression.NotEqual("attribute2", "value2")))
	
	scanInput := dynamodb.ScanInput{}
	
	err := sb.Build(&scanInput)
	if err != nil {
		return nil, err
	}
	
	return &scanInput, nil
}
Update input builder
func foo() (*dynamodb.UpdateItemInput, error) {
	ub := inputbuilder.NewUpdateBuilder()
	ub.WithTableName("SomeTableName")
	
	ub.WithKey("PK", "partitionKeyValue")
	ub.WithKey("SK", "sortKeyValue")
	
	ub.AppendSet(updateexpression.SET("attribute1", "value1"), 
		updateexpression.SET("attribute2", updateexpression.IfNotExists("attribute2", updateexpression.Addition("attribute2", 7))
    )
	
	updateItemInput := dynamodb.UpdateItemInput{}
	
	err := ub.BuildUpdateItemInput(&updateItemInput)
	if err != nil {
		return nil, err
	}
	
	return &updateItemInput, nil
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type QueryBuilder

type QueryBuilder struct {
	TableName         string
	HashKeyCondition  *conditionexpression.EqualComparisonOperator
	RangeKeyCondition conditionexpression.RangeKeyConditionExpressionItem
	FilterExpression  conditionexpression.ExpressionItem
	ConsistentRead    bool
	IndexName         *string
	Limit             *int32
	ForwardScan       *bool
}

QueryBuilder is a builder to create dynamodb.QueryInput objects

func NewQueryBuilder

func NewQueryBuilder() QueryBuilder

NewQueryBuilder creates a new and empty QueryBuilder

func (*QueryBuilder) Build

func (b *QueryBuilder) Build(queryInput *dynamodb.QueryInput) error

Build builds the dynamodb.QueryInput object

func (*QueryBuilder) SetConsistentRead

func (b *QueryBuilder) SetConsistentRead()

SetConsistentRead ensures the DynamoDB query is executed as consistent read

func (*QueryBuilder) WithFilterExpression

func (b *QueryBuilder) WithFilterExpression(filterExpression conditionexpression.ExpressionItem)

WithFilterExpression sets the filter expression for the dynamodb.QueryInput object

func (*QueryBuilder) WithForwardScan

func (b *QueryBuilder) WithForwardScan(forwardScan bool)

WithForwardScan sets the forward scan for the dynamodb.QueryInput object

func (*QueryBuilder) WithHashKeyCondition

func (b *QueryBuilder) WithHashKeyCondition(hashKeyCondition *conditionexpression.EqualComparisonOperator)

WithHashKeyCondition sets the hash key condition for the dynamodb.QueryInput object The hash key condition must be a conditionexpression.EqualComparisonOperator representing an equality between the tables Partition Key and a corresponding scalar of correct type.

func (*QueryBuilder) WithIndexName

func (b *QueryBuilder) WithIndexName(indexName string)

WithIndexName sets the index name for the dynamodb.QueryInput object

func (*QueryBuilder) WithLimit

func (b *QueryBuilder) WithLimit(limit int32)

WithLimit sets the limit for the dynamodb.QueryInput object

func (*QueryBuilder) WithRangeKeyCondition

func (b *QueryBuilder) WithRangeKeyCondition(rangeKeyCondition conditionexpression.RangeKeyConditionExpressionItem)

WithRangeKeyCondition sets the range key condition for the dynamodb.QueryInput object The range key condition must be a conditionexpression.RangeKeyConditionExpressionItem representing a valid comparison between the Sort Key and a corresponding scalar.

func (*QueryBuilder) WithTableName

func (b *QueryBuilder) WithTableName(tableName string)

WithTableName sets the table name for the dynamodb.QueryInput object

type ScanBuilder

type ScanBuilder struct {
	TableName        string
	FilterExpression conditionexpression.ExpressionItem
	ConsistentRead   bool
	IndexName        *string
	Limit            *int32
}

ScanBuilder is a builder to create dynamodb.ScanInput objects

func NewScanBuilder

func NewScanBuilder() ScanBuilder

NewScanBuilder creates a new and empty ScanBuilder

func (*ScanBuilder) Build

func (b *ScanBuilder) Build(input *dynamodb.ScanInput) error

Build builds the dynamodb.ScanInput object

func (*ScanBuilder) SetConsistentRead

func (b *ScanBuilder) SetConsistentRead()

SetConsistentRead ensures the DynamoDB scan is executed as consistent read

func (*ScanBuilder) WithConsistentRead added in v0.0.14

func (b *ScanBuilder) WithConsistentRead(consistentRead bool)

WithConsistentRead sets the consistent read flag for the dynamodb.QueryInput object

func (*ScanBuilder) WithFilterExpression

func (b *ScanBuilder) WithFilterExpression(filterExpression conditionexpression.ExpressionItem)

WithFilterExpression sets the filter expression for the dynamodb.ScanInput object

func (*ScanBuilder) WithIndexName

func (b *ScanBuilder) WithIndexName(indexName string)

WithIndexName sets the index name for the dynamodb.QueryInput object

func (*ScanBuilder) WithLimit

func (b *ScanBuilder) WithLimit(limit int32)

WithLimit sets the limit for the dynamodb.QueryInput object

func (*ScanBuilder) WithTableName

func (b *ScanBuilder) WithTableName(tableName string)

WithTableName sets the table name for the dynamodb.ScanInput object

type UpdateBuilder

type UpdateBuilder struct {
	TableName string
	Key       map[string]interface{}

	Set    []*updateexpression.SetOperationItem
	Add    []*updateexpression.AddOperationItem
	Delete []*updateexpression.DeleteOperationItem
	Remove []expressionutils.AttributePath

	ConditionExpression conditionexpression.ExpressionItem
}

UpdateBuilder is a builder to create dynamodb.UpdateItemInput and types.Update objects

func NewUpdateBuilder

func NewUpdateBuilder() *UpdateBuilder

NewUpdateBuilder creates a new and empty UpdateBuilder

func (*UpdateBuilder) AppendAdd

func (b *UpdateBuilder) AppendAdd(addOperations ...*updateexpression.AddOperationItem)

AppendAdd appends DynamoDB ADD operations to the update query https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html#Expressions.UpdateExpressions.ADD

func (*UpdateBuilder) AppendDelete

func (b *UpdateBuilder) AppendDelete(deleteOperations ...*updateexpression.DeleteOperationItem)

AppendDelete appends DynamoDB DELETE operations to the update query https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html#Expressions.UpdateExpressions.DELETE

func (*UpdateBuilder) AppendRemove

func (b *UpdateBuilder) AppendRemove(removeOperations ...expressionutils.AttributePath)

AppendRemove appends DynamoDB REMOVE operations to the update query https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html#Expressions.UpdateExpressions.REMOVE

func (*UpdateBuilder) AppendSet

func (b *UpdateBuilder) AppendSet(setOperations ...*updateexpression.SetOperationItem)

AppendSet appends DynamoDB SET operations to the update query https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html#Expressions.UpdateExpressions.SET

func (*UpdateBuilder) BuildUpdateItemInput

func (b *UpdateBuilder) BuildUpdateItemInput(input *dynamodb.UpdateItemInput) error

BuildUpdateItemInput builds a dynamodb.UpdateItemInput object

func (*UpdateBuilder) BuildUpdateTransactItem

func (b *UpdateBuilder) BuildUpdateTransactItem(input *types.Update) error

BuildUpdateTransactItem builds a types.Update object that can be used in a dynamodb.TransactWriteItemsInput object

func (*UpdateBuilder) WithConditionExpression

func (b *UpdateBuilder) WithConditionExpression(conditionExpression conditionexpression.ExpressionItem)

WithConditionExpression sets the condition expression on the Update Input object

func (*UpdateBuilder) WithKey

func (b *UpdateBuilder) WithKey(attribute expressionutils.AttributePath, value interface{})

WithKey appends the given key and value pair to the key defining the item to update value will be marshalled during when the update object is build. If the value is of type types.AttributeValue, the marshaling will be skipped and the value is directly used instead.

func (*UpdateBuilder) WithKeyMap

func (b *UpdateBuilder) WithKeyMap(key map[string]interface{})

WithKeyMap sets the key on the Update Input object. The key of the map represents the key attribute names. The values of the map represents the attribute values. The values of the map are marshalled when the update object is build. If a value is of type types.AttributeValue, the marshaling will be skipped and the value is directly used instead.

func (*UpdateBuilder) WithTableName

func (b *UpdateBuilder) WithTableName(tableName string)

WithTableName sets the table name on the Update Input object

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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