dynamodb

package module
v1.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2021 License: MIT Imports: 12 Imported by: 1

README

Go Reference GitHub go.mod Go version GitHub release (latest by date) Go Report Card Actions Status

DynamoDb Wrapper

This package provides a wrapper to dynamodb to run CRUD actions for items. It expects a table with a composed primary key of ObjectType (Hash) and Id (Range). Sub package testing will support you creating a suitable table for tests.

Documentation

Overview

Package dynamodb provides a wrapper for AWS DynamoDb to run CRUD actions in items.

Index

Constants

View Source
const DEFAULT_AWS_REGION = "eu-central-1"

DEFAULT_AWS_REGION defines the fallback AWS region if nothing has been specified by config.

View Source
const DEFAULT_TABLENAME = "<DynamoDbTableNotSet>"

DEFAULT_TABLENAME defines the default DynamoDb table name.

Variables

This section is empty.

Functions

This section is empty.

Types

type DynamoDbRepository

type DynamoDbRepository struct {
	// contains filtered or unexported fields
}

DynamoDbRepository is a wrapper to AWS DynamoDb SDK.

func (*DynamoDbRepository) Add

func (r *DynamoDbRepository) Add(item ItemKey) error

Add will create a new item or update an existing item in DynamoDb.

func (*DynamoDbRepository) Delete

func (r *DynamoDbRepository) Delete(item ItemKey) error

Delete will try to delete an item from DynamoDb item identified by passed item key.

func (*DynamoDbRepository) Get

func (r *DynamoDbRepository) Get(item ItemKey) error

Get will try to read an item from DynamDb by passed item key. Passed item have to be a pointer, because it will unmarshal DynamiDb item values into it.

func (*DynamoDbRepository) Lock added in v1.0.6

func (r *DynamoDbRepository) Lock(item ItemKey) (*ItemLock, error)

Lock will try to obtain a lock passed item. Default life time of a lock is 5 min.

func (*DynamoDbRepository) Query added in v1.0.3

func (r *DynamoDbRepository) Query(objectType string, receiver interface{}) error

Query will list items for a specific object type. Receiver have to be a slice of expected type and will be used to unmarshal query result. So please pass it as a pointer. If there're no items for passed object type no error is returned, passed slice will stay empty.

func (*DynamoDbRepository) Renew added in v1.0.6

func (r *DynamoDbRepository) Renew(itemLock *ItemLock) (*ItemLock, error)

Renew can be used to extend life time of a lock.

func (*DynamoDbRepository) Unlock added in v1.0.6

func (r *DynamoDbRepository) Unlock(itemLock *ItemLock) error

Unlock will remove given lock from DynamoDb.

type ItemIdentifier

type ItemIdentifier struct {
	Id         string `json:"Id"`
	ObjectType string `json:"ObjectType"`
}

ItemIdentifier can be used in objects which should be persisted in DynamoDb.

func NewItemIdentifier

func NewItemIdentifier(id, objectType string) *ItemIdentifier

NewItemIdentifier returns a new ItemIdentifier with passed id and object type.

func (*ItemIdentifier) GetId

func (id *ItemIdentifier) GetId() string

GetId returns the id of a DynamoDb item.

func (*ItemIdentifier) GetObjectType

func (id *ItemIdentifier) GetObjectType() string

GetObjectType returns the object type of a DynamoDb item.

type ItemKey

type ItemKey interface {
	GetId() string
	GetObjectType() string
}

ItemKey is an interface each object have to fulfill to be persisted in DynamoDb.

type ItemLock added in v1.0.6

type ItemLock struct {

	// ItemIdentifier for locked item.
	*ItemIdentifier

	// ExpiresAt is the life time of a lock in epoch seconds.
	ExpiresAt int64

	// LockId is an id to identify a lock.
	LockId string
}

ItemLock is a lock for an item in DynamoDb.

type QueryRequest added in v1.0.3

type QueryRequest struct {

	// ObjectType items should be read for.
	ObjectType string

	// Items will contain a pointer to a slice of desired items.
	// It's used to define the type of items which should be returned.
	Items interface{}
}

QueryRequest is used to query items for a partition key.

type Repository

type Repository interface {

	// Add or update an item in DynamoDb.
	Add(ItemKey) error

	// Get will try to read an item by specified key from DynamoDb.
	Get(ItemKey) error

	// Query will list all items for an object type.
	Query(string, interface{}) error

	// Delete will remove an item with specified key from DynamoDb.
	Delete(ItemKey) error

	// Lock will try to obtain a lock for an items identified by passed key.
	Lock(ItemKey) (*ItemLock, error)

	// Renew can be used to extend lease of an item lock.
	Renew(*ItemLock) (*ItemLock, error)

	// Unlock will delete passed object lock from DynamoDb.
	Unlock(*ItemLock) error
}

Repository provides CRUD access for DynamoDb items.

func NewRepository

func NewRepository(conf config.Config, logger log.Logger) Repository

NewRepository creates a new DynamoDb repository by passed coinfig. By config you can defins the table name, region and endpoint for a local dynamodb.

Directories

Path Synopsis
testing module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL