dynamo

package
v0.0.0-...-1b91eb5 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package dynamo contains controls and objects for DynamoDB CRUD operations. Operations in this package are abstracted from all other application logic and are designed to be used with any DynamoDB table and any object schema. This file contains objects for implementing an exponential backoff algorithm for DynamoDB error handling.

Package dynamo contains controls and objects for DynamoDB CRUD operations. Operations in this package are abstracted from all other application logic and are designed to be used with any DynamoDB table and any object schema. This file contains CRUD operations for working with DynamoDB.

Package dynamo contains controls and objects for DynamoDB CRUD operations. Operations in this package are abstracted from all other application logic and are designed to be used with any DynamoDB table and any object schema. This file defines the Table and Query objects, and functions for creating them. It also defines functions for creating DynamoDB AttributeValue objects and database keys in map format.

Index

Constants

This section is empty.

Variables

View Source
var DefaultFailConfig = &FailConfig{50, 60000, 0, 0, false}

DefaultFailConfig is the default configuration for the exponential backoff alogrithm with a base wait time of 50 miliseconds, and max wait time of 1 minute (60000 ms).

Functions

func BatchGet

func BatchGet(svc *dynamodb.DynamoDB, t *Table, fc *FailConfig, queries []*Query, refObjs []interface{}) ([]interface{}, error)

BatchGet retrieves a list of items from the database refObjs must be non-nil pointers of the same type, 1 for each query/object returned.

  • Returns err if len(queries) != len(refObjs).

func BatchWriteCreate

func BatchWriteCreate(svc *dynamodb.DynamoDB, t *Table, fc *FailConfig, items []interface{}) error

BatchWriteCreate writes a list of items to the database.

func BatchWriteDelete

func BatchWriteDelete(svc *dynamodb.DynamoDB, t *Table, fc *FailConfig, queries []*Query) error

BatchWriteDelete deletes a list of items from the database.

func CreateItem

func CreateItem(svc *dynamodb.DynamoDB, item interface{}, table *Table) error

CreateItem puts a new item in the table.

func CreateTable

func CreateTable(svc *dynamodb.DynamoDB, table *Table) error

CreateTable creates a new table with the parameters passed to the Table struct. NOTE: CreateTable creates Table in * On-Demand * billing mode.

func DeleteItem

func DeleteItem(svc *dynamodb.DynamoDB, q *Query, t *Table) error

DeleteItem deletes the specified item defined in the Query

func DeleteTable

func DeleteTable(svc *dynamodb.DynamoDB, t *Table) error

DeleteTable deletes the selected table.

func GetItem

func GetItem(svc *dynamodb.DynamoDB, q *Query, t *Table, item interface{}) (interface{}, error)

GetItem reads an item from the database. Returns Attribute Value map interface (map[stirng]interface{}) if object found. Returns interface of type item if object not found.

func InitSesh

func InitSesh() *dynamodb.DynamoDB

InitSesh initializes a new session with default config/credentials.

func ListTables

func ListTables(svc *dynamodb.DynamoDB) ([]string, int, error)

ListTables lists the tables in the database.

func UpdateItem

func UpdateItem(svc *dynamodb.DynamoDB, q *Query, t *Table) error

UpdateItem updates the specified item's attribute defined in the Query object with the UpdateValue defined in the Query.

Types

type DbInfo

type DbInfo struct {
	Svc        *dynamodb.DynamoDB
	Tables     map[string]*Table
	FailConfig *FailConfig
}

DbInfo holds different variables to be passed to db operation functions Contains the Db Svc, map of tables, and FailConfig.

func InitDbInfo

func InitDbInfo() *DbInfo

InitDbInfo constructs a DbInfo object with default values.

func (*DbInfo) AddTable

func (d *DbInfo) AddTable(t *Table)

AddTable adds a new Table obj to the Tables field of the DbInfo obj. TableName field is used for map key.

func (*DbInfo) SetFailConfig

func (d *DbInfo) SetFailConfig(fc *FailConfig)

SetFailConfig sets the FailConfig field of the DbInfo obj.

func (*DbInfo) SetSvc

func (d *DbInfo) SetSvc(svc *dynamodb.DynamoDB)

SetSvc sets the Svc field of the DbInfo obj.

type FailConfig

type FailConfig struct {
	Base              float64
	Cap               float64
	Attempt           float64
	Elapsed           float64
	MaxRetriesReached bool
}

FailConfig stores parameters for the exponential backoff algorithm. Attempt, Elapsed, MaxRetiresReached should always be initialized to 0, 0, false.

func (*FailConfig) ExponentialBackoff

func (fc *FailConfig) ExponentialBackoff()

ExponentialBackoff implements the exponential backoff algorithm for request retries and returns true when the max number of retries has been reached (fc.Elapsed > fc.Cap).

func (*FailConfig) Reset

func (fc *FailConfig) Reset()

Reset resets Attempt and Elapsed fields.

type Query

type Query struct {
	PrimaryValue    interface{}
	SortValue       interface{}
	UpdateFieldName string
	UpdateValue     interface{}
}

Query holds the search values for both the Partition and Sort Keys. Query also holds data for updating a specific item in the UpdateFieldName column.

func CreateNewQueryObj

func CreateNewQueryObj(pval, sval interface{}) *Query

CreateNewQueryObj creates a new Query struct. pval, sval == Primary/Partition key, Sort Key

func (*Query) New

func (q *Query) New(pv, sv interface{})

New creates a new query by setting the Partition Key and Sort Key values.

func (*Query) Reset

func (q *Query) Reset()

Reset clears all fields.

func (*Query) UpdateCurrent

func (q *Query) UpdateCurrent(fieldName string, value interface{})

UpdateCurrent sets the update fields for the current item.

func (*Query) UpdateNew

func (q *Query) UpdateNew(pv, sv, fieldName string, value interface{})

UpdateNew selects a new item for an update.

type Table

type Table struct {
	TableName      string
	PrimaryKeyName string
	PrimaryKeyType string
	SortKeyName    string
	SortKeyType    string
}

Table represents a table and holds basic information about it. This object is used to access the Dynamo Table requested for each CRUD op.

func CreateNewTableObj

func CreateNewTableObj(tableName, pKeyName, pType, sKeyName, sType string) *Table

CreateNewTableObj creates a new Table struct. The Table's key's Go types must be declared as strings. ex: t := CreateNewTableObj("my_table", "Year", "int", "MovieName", "string")

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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