Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions dynamo_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ func (repository *Repository) GetItemWithContext(ctx context.Context, key KeyInt
query = query.Range(*key.RangeKeyName(), dynamo.Equal, key.RangeKey())
}

// index
if key.Index() != nil {
query = query.Index(*key.Index())
}

err := query.OneWithContext(ctx, item)
if err != nil {
if err == dynamo.ErrNotFound {
Expand Down Expand Up @@ -144,14 +149,14 @@ func (repository *Repository) DeleteItemWithContext(ctx context.Context, key Key
return err
}
// by hash
delete := repository.table(key.TableName()).Delete(*key.HashKeyName(), key.HashKey())
del := repository.table(key.TableName()).Delete(*key.HashKeyName(), key.HashKey())

// by range
if key.RangeKeyName() != nil && key.RangeKey() != nil {
delete = delete.Range(*key.RangeKeyName(), key.RangeKey())
del = del.Range(*key.RangeKeyName(), key.RangeKey())
}

err := delete.RunWithContext(ctx)
err := del.RunWithContext(ctx)
if err != nil {
repository.log.error(ctx, key.TableName(), err.Error())
return err
Expand Down Expand Up @@ -249,7 +254,15 @@ func (repository *Repository) GetItemsWithContext(ctx context.Context, key KeyIn
return false, err
}

err := repository.table(key.TableName()).Get(*key.HashKeyName(), key.HashKey()).AllWithContext(ctx, items)
query := repository.table(key.TableName()).Get(*key.HashKeyName(), key.HashKey())

// index
if key.Index() != nil {
query = query.Index(*key.Index())
}

err := query.AllWithContext(ctx, items)

if err != nil {
if err == dynamo.ErrNotFound {
repository.log.info(ctx, key.TableName(), ErrNoItemFound.Error())
Expand Down Expand Up @@ -303,15 +316,6 @@ func (repository Repository) GetItems(key KeyInterface, items interface{}) (bool
return repository.GetItemsWithContext(context.TODO(), key, items)
}

// GIndex creates an index repository by name
func (repository Repository) GIndex(name string) GlobalIndexInterface {
return GlobalIndex{
name: name,
log: repository.log,
dynamoClient: repository.dynamoClient,
}
}

func (repository Repository) table(tableName string) dynamo.Table {
return repository.dynamoClient.Table(tableName)
}
3 changes: 0 additions & 3 deletions dynamo_repository_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,4 @@ type RepositoryInterface interface {
// GetItems by key; it accepts key of item to get it; context which used to enable log with context
// returns true if items are found, returns false and nil if no items found, returns false and error in case of error
GetItemsWithContext(ctx context.Context, key KeyInterface, out interface{}) (bool, error)

// GIndex returns index repository
GIndex(name string) GlobalIndexInterface
}
4 changes: 2 additions & 2 deletions examples/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package examples
import (
"context"
"fmt"
"github.com/djoemo"
"github.com/djoemo/mock"
"github.com/adjoeio/djoemo"
"github.com/adjoeio/djoemo/mock"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
"time"
Expand Down
81 changes: 0 additions & 81 deletions global_index.go

This file was deleted.

10 changes: 10 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/adjoeio/djoemo

require (
github.com/aws/aws-sdk-go v1.19.1
github.com/golang/mock v1.2.0
github.com/guregu/dynamo v1.2.1
github.com/onsi/ginkgo v1.8.0
github.com/onsi/gomega v1.5.0
github.com/pkg/errors v0.8.1
)
46 changes: 46 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
github.com/aws/aws-sdk-go v1.18.5/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.19.1 h1:8kOP0/XGJwXIFlYoD1DAtA39cAjc15Iv/QiDMKitD9U=
github.com/aws/aws-sdk-go v1.19.1/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/cenkalti/backoff v2.1.1+incompatible h1:tKJnvO2kl0zmb/jA5UKAt4VoEVw1qxKWjE/Bpp46npY=
github.com/cenkalti/backoff v2.1.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE=
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/golang/mock v1.2.0 h1:28o5sBqPkBsMGnC6b4MvE2TzSr5/AT4c/1fLqVGIwlk=
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/guregu/dynamo v1.2.1 h1:1jKHg3GSTo4/JpmnlaLawqhh8XoYCrTCD5IrWs4ONp8=
github.com/guregu/dynamo v1.2.1/go.mod h1:ZS3tuE64ykQlCnuGfOnAi+ztGZlq0Wo/z5EVQA1fwFY=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w=
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo=
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190318221613-d196dffd7c2b h1:ZWpVMTsK0ey5WJCu+vVdfMldWq7/ezaOcjnKWIHWVkE=
golang.org/x/net v0.0.0-20190318221613-d196dffd7c2b/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
12 changes: 12 additions & 0 deletions key.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package djoemo

type key struct {
tableName string
index *string
hashKeyName *string
rangeKeyName *string
hashKey interface{}
Expand All @@ -19,6 +20,12 @@ func (k *key) WithTableName(tableName string) *key {
return k
}

// WithIndex set djoemo index
func (k *key) WithIndex(index *string) *key {
k.index = index
return k
}

// WithHashKeyName set djoemo key hash key name
func (k *key) WithHashKeyName(hashKeyName string) *key {
k.hashKeyName = &hashKeyName
Expand Down Expand Up @@ -48,6 +55,11 @@ func (k *key) TableName() string {
return k.tableName
}

// Index returns the djoemo index
func (k *key) Index() *string {
return k.index
}

// HashKeyName returns the name of hash key if exists
func (k *key) HashKeyName() *string {
return k.hashKeyName
Expand Down
2 changes: 2 additions & 0 deletions key_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package djoemo
type KeyInterface interface {
// TableName returns the djoemo table name
TableName() string
// Index returns the djoemo index to use
Index() *string
// HashKeyName returns the name of hash key if exists
HashKeyName() *string
// RangeKeyName returns the name of range key if exists
Expand Down
2 changes: 1 addition & 1 deletion mock/log_interface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mock/metrics_interface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion reflect_helper_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package djoemo_test

import (
. "djoemo"
. "github.com/adjoeio/djoemo"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
Expand Down
4 changes: 2 additions & 2 deletions repository_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package djoemo_test
import (
"context"
"errors"
. "github.com/djoemo"
"github.com/djoemo/mock"
. "github.com/adjoeio/djoemo"
"github.com/adjoeio/djoemo/mock"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down
4 changes: 2 additions & 2 deletions repository_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package djoemo_test

import (
"errors"
. "github.com/djoemo"
"github.com/djoemo/mock"
. "github.com/adjoeio/djoemo"
"github.com/adjoeio/djoemo/mock"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down
Loading