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 ¶
- Variables
- func BatchGet(svc *dynamodb.DynamoDB, t *Table, fc *FailConfig, queries []*Query, ...) ([]interface{}, error)
- func BatchWriteCreate(svc *dynamodb.DynamoDB, t *Table, fc *FailConfig, items []interface{}) error
- func BatchWriteDelete(svc *dynamodb.DynamoDB, t *Table, fc *FailConfig, queries []*Query) error
- func CreateItem(svc *dynamodb.DynamoDB, item interface{}, table *Table) error
- func CreateTable(svc *dynamodb.DynamoDB, table *Table) error
- func DeleteItem(svc *dynamodb.DynamoDB, q *Query, t *Table) error
- func DeleteTable(svc *dynamodb.DynamoDB, t *Table) error
- func GetItem(svc *dynamodb.DynamoDB, q *Query, t *Table, item interface{}) (interface{}, error)
- func InitSesh() *dynamodb.DynamoDB
- func ListTables(svc *dynamodb.DynamoDB) ([]string, int, error)
- func UpdateItem(svc *dynamodb.DynamoDB, q *Query, t *Table) error
- type DbInfo
- type FailConfig
- type Query
- type Table
Constants ¶
This section is empty.
Variables ¶
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 ¶
BatchWriteDelete deletes a list of items from the database.
func CreateItem ¶
CreateItem puts a new item in the table.
func CreateTable ¶
CreateTable creates a new table with the parameters passed to the Table struct. NOTE: CreateTable creates Table in * On-Demand * billing mode.
func DeleteItem ¶
DeleteItem deletes the specified item defined in the Query
func DeleteTable ¶
DeleteTable deletes the selected table.
func GetItem ¶
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 ListTables ¶
ListTables lists the tables in the database.
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 ¶
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.
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).
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) UpdateCurrent ¶
UpdateCurrent sets the update fields for the current item.
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 ¶
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")