transact

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2021 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package ddbextras provides a builder for DynamoDB transactions.

Index

Constants

View Source
const ErrCodeConditionalCheckFailed = "ConditionalCheckFailed"

Cannot use dynamodb.ErrCodeConditionalCheckFailedException, the code in the cancellation reason has no 'Exception' suffix

View Source
const SetAll = "*"

SetAll is a special attribute name that will set all attributes of a struct/map value.

View Source
const SetIfNotExists = "?"

Variables

This section is empty.

Functions

func BuildExpression added in v1.16.0

func BuildExpression(item ItemBuilder) (expression.Expression, error)

func HasCondition

func HasCondition(cond expression.ConditionBuilder) bool

func IsCancelReason

func IsCancelReason(r *dynamodb.CancellationReason, code string) bool

func IsConditionalCheckFailed

func IsConditionalCheckFailed(r *dynamodb.CancellationReason) bool

Types

type ConditionCheck

type ConditionCheck struct {
	// TableName is the DynamoDB table name
	TableName string
	// Key to check the condition against (gets marshalled to map[string]*dynamodb.AttributeValue)
	Key interface{}
	// Condition to check
	Condition expression.ConditionBuilder
	// ReturnValues values if the condition fails
	ReturnValues bool
	// Cancel maps a cancellation reason to an error
	Cancel func(r *dynamodb.CancellationReason) error
}

ConditionCheck checks a condition and aborts the transaction if it fails

func (*ConditionCheck) BuildItem

func (c *ConditionCheck) BuildItem() (*dynamodb.TransactWriteItem, error)

type Delete

type Delete struct {
	// TableName is the DynamoDB table name
	TableName string
	// Key to delete
	Key interface{}
	// Condition to check before deleting
	Condition expression.ConditionBuilder
	// ReturnValues values if the condition fails
	ReturnValues bool
	// Cancel maps a cancellation reason to an error
	Cancel func(r *dynamodb.CancellationReason) error
}

Delete deletes a key

func (*Delete) BuildItem

func (d *Delete) BuildItem() (*dynamodb.TransactWriteItem, error)

type ItemBuilder

type ItemBuilder interface {
	BuildItem() (*dynamodb.TransactWriteItem, error)
	// contains filtered or unexported methods
}

type Put

type Put struct {
	// TableName is the DynamoDB table name
	TableName string
	// Item to put in the table (gets marshalled to map[string]*dynamodb.AttributeValue)
	Item interface{}
	// Condition to check before the item is put
	Condition expression.ConditionBuilder
	// ReturnValues values if the condition fails
	ReturnValues bool
	// Cancel maps a cancellation reason to an error
	Cancel func(r *dynamodb.CancellationReason) error
}

Put creates or replaces a key value

func (*Put) BuildItem

func (p *Put) BuildItem() (*dynamodb.TransactWriteItem, error)

type Transaction

type Transaction []ItemBuilder

Transaction describes a write transaction and builds a dynamodb.TransactWriteItemsInput. It also allows to bind transaction cancellation reasons to errors for each dynamodb.TransactWriteItem. For more info on how the write transactions work see https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactWriteItems.html

func (Transaction) Build

Build builds a dynamodb.TransactWriteItemsInput from a batch

func (Transaction) ExplainTransactionError

func (tx Transaction) ExplainTransactionError(err error) error

ExplainTransactionError maps transaction cancelled errors to the error handlers specified in the batch items.

type Update

type Update struct {
	// TableName is the DynamoDB table name
	TableName string
	// Key to update (gets marshalled to map[string]*dynamodb.AttributeValue)
	Key interface{}
	// Set attributes to values
	Set map[string]interface{}
	// Add values to attributes
	Add map[string]interface{}
	// Delete values from attributes
	Delete map[string]interface{}
	// Remove attribute names
	Remove []string
	// Condition check if the update should happen
	Condition expression.ConditionBuilder
	// ReturnValuesOnConditionCheckFailure controls how to get the item attributes if the
	// Update condition fails. For ReturnValuesOnConditionCheckFailure, the valid
	// values are: NONE, ALL_OLD, UPDATED_OLD, ALL_NEW, UPDATED_NEW.
	ReturnValuesOnConditionCheckFailure string
	// Cancel maps a cancellation reason to an error
	Cancel func(r *dynamodb.CancellationReason) error
}

Update updates attributes of an item.

func (*Update) BuildItem

func (u *Update) BuildItem() (*dynamodb.TransactWriteItem, error)

Jump to

Keyboard shortcuts

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