Documentation ¶
Overview ¶
Package ddbextras provides a builder for DynamoDB transactions.
Index ¶
- Constants
- func BuildExpression(item ItemBuilder) (expression.Expression, error)
- func HasCondition(cond expression.ConditionBuilder) bool
- func IsCancelReason(r *dynamodb.CancellationReason, code string) bool
- func IsConditionalCheckFailed(r *dynamodb.CancellationReason) bool
- type ConditionCheck
- type Delete
- type ItemBuilder
- type Put
- type Transaction
- type Update
Constants ¶
const ErrCodeConditionalCheckFailed = "ConditionalCheckFailed"
Cannot use dynamodb.ErrCodeConditionalCheckFailedException, the code in the cancellation reason has no 'Exception' suffix
const SetAll = "*"
SetAll is a special attribute name that will set all attributes of a struct/map value.
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
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
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 ¶
func (tx Transaction) Build() (*dynamodb.TransactWriteItemsInput, error)
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.