Documentation ¶
Index ¶
- func Add(name string, value interface{}) func(*Opts)
- func Delete(name string, value interface{}) func(*Opts)
- func DisableAutoGenerateTimestamps(flag timestamp.AutoGenerateFlag) func(*Opts)
- func DisableOptimisticLocking() func(*Opts)
- func Remove(name string) func(*Opts)
- func ReturnAllNewValues() func(*Opts)
- func ReturnAllOldValues() func(*Opts)
- func ReturnUpdatedNewValues() func(*Opts)
- func ReturnUpdatedOldValues() func(*Opts)
- func Set(name string, value interface{}) func(*Opts)
- func SetOrRemove(set, remove bool, name string, value interface{}) func(*Opts)
- func SetOrRemoveStringPointer(name string, ptr *string) func(*Opts)
- func WithTableName(tableName string) func(*Opts)
- type Opts
- func (opts *Opts) Add(name string, value interface{}) *Opts
- func (opts *Opts) Delete(name string, value interface{}) *Opts
- func (opts *Opts) Remove(name string) *Opts
- func (opts *Opts) Set(name string, value interface{}) *Opts
- func (opts *Opts) SetOrRemove(set, remove bool, name string, value interface{}) *Opts
- func (opts *Opts) SetOrRemoveStringPointer(name string, ptr *string) *Opts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Add ¶
Add is the global variant of Opts.Add.
This is useful if you only have one or two actions in the update expression and don't need chaining.
func Delete ¶
Delete is the global variant of Opts.Delete.
This is useful if you only have one or two actions in the update expression and don't need chaining.
func DisableAutoGenerateTimestamps ¶
func DisableAutoGenerateTimestamps(flag timestamp.AutoGenerateFlag) func(*Opts)
DisableAutoGenerateTimestamps disables logic around model.HasCreatedTimestamp and model.HasModifiedTimestamp.
func DisableOptimisticLocking ¶
func DisableOptimisticLocking() func(*Opts)
DisableOptimisticLocking disables logic around model.Versioned.
func Remove ¶
Remove is the global variant of Opts.Remove.
This is useful if you only have one or two actions in the update expression and don't need chaining.
func ReturnAllNewValues ¶
func ReturnAllNewValues() func(*Opts)
ReturnAllNewValues sets the dynamodb.UpdateItemInput's ReturnValues to ALL_NEW.
func ReturnAllOldValues ¶
func ReturnAllOldValues() func(*Opts)
ReturnAllOldValues sets the dynamodb.UpdateItemInput's ReturnValues to ALL_OLD.
func ReturnUpdatedNewValues ¶
func ReturnUpdatedNewValues() func(*Opts)
ReturnUpdatedNewValues sets the dynamodb.UpdateItemInput's ReturnValues to UPDATED_NEW.
func ReturnUpdatedOldValues ¶
func ReturnUpdatedOldValues() func(*Opts)
ReturnUpdatedOldValues sets the dynamodb.UpdateItemInput's ReturnValues to UPDATED_OLD.
func Set ¶
Set is the global variant of Opts.Set.
This is useful if you only have one or two actions in the update expression and don't need chaining.
func SetOrRemove ¶
SetOrRemove is the global variant of Opts.SetOrRemove.
This is useful if you only have one or two actions in the update expression and don't need chaining.
func SetOrRemoveStringPointer ¶
SetOrRemoveStringPointer is the global variant of Opts.SetOrRemoveStringPointer.
This is useful if you only have one or two actions in the update expression and don't need chaining.
func WithTableName ¶
WithTableName changes the table name in Opts.Input.
Types ¶
type Opts ¶
type Opts struct { Item model.Item Input *dynamodb.UpdateItemInput Condition *expression.ConditionBuilder Update *expression.UpdateBuilder DisableOptimisticLocking bool DisableAutoGenerateTimestamps timestamp.AutoGenerateFlag }
Opts provides customisation to the dynamodb.UpdateItemInput made with github.com/nguyengg/golambda/ddb.Wrapper.Update.
Opts.Input is guaranteed to exist when passed into the first modifier. Opts.Item is the original reference item. Changes to Opts.Item don't automatically update Opts.Input. Changes to Opts.Condition and Opts.Update will affect the final Opts.Input.
func (*Opts) SetOrRemove ¶
SetOrRemove adds either Set or Remove action to the update expression.
If set is true, a SET action will be added. If set is false, only when remove is true then a REMOVE action will be added.
| set | remove | action | true | * | SET | false | true | REMOVE | false | false | no-op
This is useful for distinguishing between PUT/POST (remove=true) that replaces attributes with clobbering behaviour vs. PATCH (remove=false) that will only update attributes that are non-nil. An example is given:
func PUT(body Struct) { // because it's a PUT request, if notes is empty, instead of writing empty string to database, we'll remove it. wrapper.Update(..., SetOrRemove(true, true, "notes", body.Notes)) } func PATCH(body Struct) { // only when notes is non-empty that we'll update it. an empty notes just means caller didn't try to update it. wrapper.Update(..., opts.SetOrRemove(body.Notes != "", false, "notes", body.Notes)) } func Update(method string, body Struct) { // an attempt to unify the methods may look like this. wrapper.Update(..., opts.SetOrRemove(body.Notes != "", method != "PATCH", "notes", body.Notes)) }
If you have multiple actions to be added to the update expression, use this function. If you only have one or two actions, you can use the global SetOrRemove as well.
func (*Opts) SetOrRemoveStringPointer ¶
SetOrRemoveStringPointer is a specialization of SetOrRemove for string pointer value.
If ptr is a nil pointer, no action is taken. If ptr dereferences to an empty string, a REMOVE action is used. A non-empty string otherwise will result in a SET action.