Skip to content

Commit

Permalink
Merge branch '4-add-partitionsort-key-overloads'
Browse files Browse the repository at this point in the history
  • Loading branch information
junderhill committed Jun 14, 2023
2 parents bf1d210 + 8a7b475 commit f6379ad
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
5 changes: 5 additions & 0 deletions conditioncheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ func (check *ConditionCheck) Range(rangeKey string, value interface{}) *Conditio
return check
}

// SortKey is a synonym for Range. Specifies the sort key (a.k.a. range key) for this item.
func (check *ConditionCheck) SortKey(rangeKey string, value interface{}) *ConditionCheck {
return check.Range(rangeKey, value)
}

// If specifies a conditional expression for this coniditon check to succeed.
// Use single quotes to specificy reserved names inline (like 'Count').
// Use the placeholder ? within the expression to substitute values, and use $ for names.
Expand Down
7 changes: 7 additions & 0 deletions delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ func (d *Delete) Range(name string, value interface{}) *Delete {
return d
}

// SortKey is a synonym for Range. Specify the sort key (a.k.a. range key) to delete.
// Name is the name of the sort key.
// Value is the value of the sort key.
func (d *Delete) SortKey(name string, value interface{}) *Delete {
return d.Range(name, value)
}

// If specifies a conditional expression for this delete to succeed.
// Use single quotes to specificy reserved names inline (like 'Count').
// Use the placeholder ? within the expression to substitute values, and use $ for names.
Expand Down
10 changes: 9 additions & 1 deletion keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ const (
NoneType KeyType = ""
)

// Keyed provides hash key and range key values.
// Keyed provides hash/partition key and range/sort key values.
type Keyed interface {
HashKey() interface{}
RangeKey() interface{}
PartitionKey() interface{}
SortKey() interface{}
}

// Keys provides an easy way to specify the hash and range keys.
Expand All @@ -29,3 +31,9 @@ func (k Keys) HashKey() interface{} { return k[0] }

// RangeKey returns the range key's value.
func (k Keys) RangeKey() interface{} { return k[1] }

// PartitionKey returns the hash key's value. (Synonym for HashKey)
func (k Keys) PartitionKey() interface{} { return k[0] }

// SortKey returns the sort key's value. (Synonym for RangeKey)
func (k Keys) SortKey() interface{} { return k[1] }
12 changes: 10 additions & 2 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,24 @@ func (q *Query) Range(name string, op Operator, values ...interface{}) *Query {
q.setError(err)
for i, v := range q.rangeValues {
if v == nil {
q.setError(fmt.Errorf("dynamo: query range key value is nil or omitted for attribute %q (range key #%d of %d)", q.rangeKey, i+1, len(q.rangeValues)))
q.setError(fmt.Errorf("dynamo: query range/sort key value is nil or omitted for attribute %q (range key #%d of %d)", q.rangeKey, i+1, len(q.rangeValues)))
break
}
}
if len(q.rangeValues) == 0 {
q.setError(fmt.Errorf("dynamo: query range key values are missing for attribute %q", q.rangeKey))
q.setError(fmt.Errorf("dynamo: query range/sort key values are missing for attribute %q", q.rangeKey))
}
return q
}

// SortKey is an alias for Range. Specify the sort key(s) to get.
// For single item requests using One, op must be Equal.
// Name is the name of the sort key.
// Op specifies the operator to use when comparing values.
func (q *Query) SortKey(name string, op Operator, values ...interface{}) *Query {
return q.Range(name, op, values...)
}

// StartFrom makes this query continue from a previous one.
// Use Query.Iter's LastEvaluatedKey.
func (q *Query) StartFrom(key PagingKey) *Query {
Expand Down
7 changes: 6 additions & 1 deletion update.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,16 @@ func (u *Update) Range(name string, value interface{}) *Update {
u.rangeValue, err = marshal(value, flagNone)
u.setError(err)
if u.rangeValue == nil {
u.setError(fmt.Errorf("dynamo: update range key value is nil or omitted for attribute %q", u.rangeKey))
u.setError(fmt.Errorf("dynamo: update range/sort key value is nil or omitted for attribute %q", u.rangeKey))
}
return u
}

// SortKey is an alias for Range. Specify the sort key for the item to update.
func (u *Update) SortKey(name string, value interface{}) *Update {
return u.Range(name, value)
}

// Set changes path to the given value.
// If value is an empty string or nil, path will be removed instead.
// Paths that are reserved words are automatically escaped.
Expand Down

0 comments on commit f6379ad

Please sign in to comment.