dynamodb

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2021 License: MIT Imports: 10 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 Id (Hash) and ObjectType (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"
View Source
const DEFAULT_TABLENAME = "<DynamoDbTableNotSet>"

Variables

This section is empty.

Functions

This section is empty.

Types

type DynamoDbRepository

type DynamoDbRepository struct {

	// Config contains the AWS config to access DynamoDb.
	Config *aws.Config

	// TableName defines the DynamoDb table which should be used.
	TableName *string
	// 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.

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 Repository

type Repository interface {
	Add(ItemKey) error
	Get(ItemKey) error
	//Query(ListItemRequest) (ListItemResponse, error)
	//Scan(ListItemRequest) (ListItemResponse, error)
	Delete(ItemKey) 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