Skip to content

Commit

Permalink
[GUILD-436] Add new method to find using an index
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarriere committed Mar 18, 2019
1 parent fd8e9b2 commit 9b273b4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
22 changes: 22 additions & 0 deletions repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,28 @@ func (r *Repo) FindWithFilter(ctx context.Context, expr string, args ...interfac
return result, nil
}

// FindUsingIndex allows to find entities using an index
func (r *Repo) FindUsingIndex(ctx context.Context, indexName string, partitionKey string, partitionKeyValue interface{}, sortKey string, sortKeyValue interface{}) ([]eh.Entity, error) {
if r.factoryFn == nil {
return nil, eh.RepoError{
Err: ErrModelNotSet,
Namespace: eh.NamespaceFromContext(ctx),
}
}

table := r.service.Table(r.config.TableName)

iter := table.Get(partitionKey, partitionKeyValue).Range(sortKey, dynamo.Equal, sortKeyValue).Index(indexName).Consistent(true).Iter()
result := []eh.Entity{}
entity := r.factoryFn()
for iter.Next(entity) {
result = append(result, entity)
entity = r.factoryFn()
}

return result, nil
}

// Save implements the Save method of the eventhorizon.WriteRepo interface.
func (r *Repo) Save(ctx context.Context, entity eh.Entity) error {
table := r.service.Table(r.config.TableName)
Expand Down
1 change: 0 additions & 1 deletion repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"

"github.com/stretchr/testify/suite"

"github.com/stretchr/testify/assert"
Expand Down

0 comments on commit 9b273b4

Please sign in to comment.