Documentation ¶
Overview ¶
Package ddbmap presents a map-like interface for DynamoDB tables.
Index ¶
- Constants
- type CreateTableOptions
- type DynamoMap
- func (d *DynamoMap) CreateTable() error
- func (d *DynamoMap) Delete(key interface{}) (err error)
- func (d *DynamoMap) DeleteItem(key Itemable) error
- func (d *DynamoMap) DescribeTable(setKeys bool) (status dynamodb.TableStatus, err error)
- func (d *DynamoMap) DisableTTL() error
- func (d *DynamoMap) EnableTTL() error
- func (d *DynamoMap) Load(key interface{}) (value interface{}, ok bool, err error)
- func (d *DynamoMap) LoadItem(key Itemable) (item Item, ok bool, err error)
- func (d *DynamoMap) LoadOrStore(val interface{}) (actual interface{}, loaded bool, err error)
- func (d *DynamoMap) LoadOrStoreItem(val Itemable) (actual Item, loaded bool, err error)
- func (d *DynamoMap) Range(consumer func(value interface{}) bool) error
- func (d *DynamoMap) RangeItems(consumer func(Item) bool) error
- func (d *DynamoMap) Store(val interface{}) (err error)
- func (d *DynamoMap) StoreIfAbsent(val interface{}) (stored bool, err error)
- func (d *DynamoMap) StoreIfVersion(val interface{}, version int64) (ok bool)
- func (d *DynamoMap) StoreItem(val Itemable) error
- func (d *DynamoMap) StoreItemIfAbsent(val Itemable) (stored bool, err error)
- func (d *DynamoMap) StoreItemIfVersion(item Itemable, version int64) (ok bool, err error)
- type Item
- type ItemMap
- type ItemUnmarshaller
- type Itemable
- type KeyFromValue
- type Map
- type TableConfig
Constants ¶
const (
// DefaultTimeToLiveName is used if the TTL duration is set but the ttl attribute name is not.
DefaultTimeToLiveName = "TTL"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CreateTableOptions ¶
type CreateTableOptions struct { // CreateTableIfAbsent determines if a table should be created when missing. // If true, users must also set the HashKeyType and, if there is a range key, the RangeKeyType, // and may also choose to set CreateTableReadCapacity and CreateTableWriteCapacity CreateTableIfAbsent bool // CreateTableReadCapacity is the read capacity of the new table, if created. 1 is used if less than 1. CreateTableReadCapacity int // CreateTableReadCapacity is the write capacity of the new table, if created. 1 is used if less than 1. CreateTableWriteCapacity int // The type of the hash key attribute. HashKeyType dynamodb.ScalarAttributeType // The type of the range key attribute, if any. RangeKeyType dynamodb.ScalarAttributeType // If true, Server Side Encryption (SSE) is enabled. ServerSideEncryption bool }
CreateTableOptions contain values used when creating new DynamoDB tables
type DynamoMap ¶
type DynamoMap struct { TableConfig Client *dynamodb.Client }
DynamoMap is a map view of a DynamoDB table. *DynamoMap implements both Map and ItemMap.
func (*DynamoMap) CreateTable ¶ added in v0.0.6
CreateTable creates a new table.
func (*DynamoMap) Delete ¶
Delete delete the value stored under the same key(s) as the given value, if any.
func (*DynamoMap) DeleteItem ¶
DeleteItem deletes any existing item with the same key(s) as the given item.
func (*DynamoMap) DescribeTable ¶ added in v0.0.6
func (d *DynamoMap) DescribeTable(setKeys bool) (status dynamodb.TableStatus, err error)
DescribeTable checks the table description, returning the table status or any errors. If the status is CREATING, the call will poll waiting for the status to change. If the table does not exist, the status will be empty. If setKeys is true, the keys will be set using the table description.
func (*DynamoMap) DisableTTL ¶ added in v0.0.11
DisableTTL will disable TimeToLive on the table if it is enabled.
func (*DynamoMap) EnableTTL ¶ added in v0.0.11
EnableTTL will enable TimeToLive on the table if it is not enabled, or update it if the configured time to live attribute name does not match the one currently in use.
func (*DynamoMap) Load ¶
Load returns any value stored under the same key(s) as the given value, if any. The ok result indicates if there a value was found for the key.
func (*DynamoMap) LoadItem ¶
LoadItem returns the existing item, if present, with the same key(s) as the given item. The ok result returns true if the value was found.
func (*DynamoMap) LoadOrStore ¶
LoadOrStore returns any value stored that has the same key as the given value, if any, else stores and returns the given value. The loaded result is true if the value was loaded, false if stored. The first argument is ignored.
func (*DynamoMap) LoadOrStoreItem ¶
LoadOrStoreItem returns the existing item, if present, with the same key(s) as the given item. Otherwise, it stores and returns the given item. The loaded result is true if the value was loaded, false if stored.
func (*DynamoMap) Range ¶
Range iterates over the map and applies the given function to every value. Iteration eventually stops if the given function returns false. The consumed key will be nil unless KeyUnmarshaller is set. The consumed value will be an Item unless ValueUnmarshaller is set.
func (*DynamoMap) RangeItems ¶
RangeItems calls the given consumer for each stored item. Iteration eventually stops if the given function returns false.
func (*DynamoMap) StoreIfAbsent ¶
StoreIfAbsent stores the given value if there is no existing value with the same key(s), returning true if stored. The first argument is ignored.
func (*DynamoMap) StoreIfVersion ¶
StoreIfVersion stores the given item if there is an existing item with the same key(s) and the given version. Returns true if the item was stored.
func (*DynamoMap) StoreItem ¶
StoreItem stores the given item, clobbering any existing item with the same key(s).
func (*DynamoMap) StoreItemIfAbsent ¶
StoreItemIfAbsent stores the given item if there is no existing item with the same key(s), returning true if stored.
type Item ¶
type Item map[string]dynamodb.AttributeValue
Item is a type underlied by the map type output by dynamodbattribute.MarshalMap. This represents a single row in a DynamoDB table or a 'Map' in the DynamoDB type system.
func MarshalItem ¶
MarshalItem will marshal a value into an Item using dynamodbattribute.MarshalMap, unless this can be avoided because the value is already an Item or is Itemable.
type ItemMap ¶
type ItemMap interface { // DeleteItem deletes any existing item with the same key(s) as the given item. DeleteItem(keys Itemable) error // LoadItem returns the existing item, if present, with the same key(s) as the given item. // The ok result returns true if the value was found. LoadItem(keys Itemable) (item Item, ok bool, err error) // StoreItem stores the given item, clobbering any existing item with the same key(s). StoreItem(item Itemable) error // LoadOrStoreItem returns the existing item, if present, with the same key(s) as the given item. // Otherwise, it stores and returns the given item. // The loaded result is true if the value was loaded, false if stored. LoadOrStoreItem(item Itemable) (actual Item, loaded bool, err error) // StoreIfAbsent stores the given value if there is no existing value with the same key(s), // returning true if stored. StoreIfAbsent(val interface{}) (stored bool, err error) // StoreItemIfAbsent stores the given item if there is no existing item with the same key(s), // returning true if stored. StoreItemIfAbsent(item Itemable) (stored bool, err error) // RangeItems calls the given consumer for each stored item. // If the consumer returns false, range eventually stops the iteration. RangeItems(consumer func(Item) (resume bool)) error // StoreIfVersion stores the given item if there is an existing item with the same key(s) and the given version. // Returns true if the item was stored. StoreIfVersion(val interface{}, version int64) (ok bool) // StoreItemIfVersion stores the given item if there is an existing item with the same key(s) and the given version. // Returns true if the item was stored. StoreItemIfVersion(item Itemable, version int64) (ok bool, err error) }
ItemMap is like Map except that it supports Itemable types and more conditional operations.
type ItemUnmarshaller ¶
ItemUnmarshaller is a function that can convert an Item into some other type
func UnmarshallerForType ¶
func UnmarshallerForType(template interface{}) ItemUnmarshaller
UnmarshallerForType creates a new ItemUnmashaller function from a template. The template may be any value of the struct type you want items to be unmarshalled into, such as the zero value.
type Itemable ¶
type Itemable interface {
AsItem() Item
}
Itemable is implemented by types that can directly build representations of their data in the DynamoDB type system. This allows users to take direct control of how their data is presented to DynamoDB. Item also implements Itemable, by returning itself, so any method that take Itemable can accept an Item directly.
type KeyFromValue ¶ added in v0.0.8
type KeyFromValue func(interface{}) (interface{}, error)
KeyFromValue is a function that can generate a hashable key from a value.
type Map ¶
type Map interface { // Delete delete the value stored under the given key, if any. Delete(toDelete interface{}) error // Load returns the value stored under the given key, if any. // The ok result indicates if there a value was found for the key. Load(toLoad interface{}) (result interface{}, ok bool, err error) // LoadOrStore returns the value stored under the same key as the given value, if any, // else stores and returns the given value. // The loaded result is true if the value was loaded, false if stored. LoadOrStore(value interface{}) (actual interface{}, loaded bool, err error) // Range iterates over the map and applies the given function to every value. // Range stops iteration if the given function returns false. Range(consumer func(value interface{}) (resume bool)) error // Store stores the given value. Store(toStore interface{}) error // Store stores the given value is no value with the same key is stored. // The stored result is true if the value was stored. StoreIfAbsent(toStore interface{}) (stored bool, err error) }
Map implements a key-value store where keys can always be determined from values.
func NewSyncMap ¶ added in v0.0.8
func NewSyncMap(keyFromValue KeyFromValue) Map
NewSyncMap creates a new Map that uses sync.Map as storage. This is intended for use in tests.
type TableConfig ¶
type TableConfig struct { // The name of the table. TableName string // The name of the hash key attribute. HashKeyName string // The name of the range key attribute, if any. RangeKeyName string // The name of the numeric version field, if any. // Used only for those conditional methods that use versions. VersionName string // The name of the ttl field, if any. // If empty and TimeToLiveDuration is not zero, DefaultTimeToLiveName ("TTL") will be used. // A ttl field should be either an int type or dynamodbattribute.UnixTime. TimeToLiveName string // The Time To Live Duration, if any. TimeToLiveDuration time.Duration // The concurrency used in table scans (Range calls). // If less than 2, scan is done serially. ScanConcurrency int // If the client should use strongly consistent reads. // This costs twice as much as eventually consistent reads. ReadWithStrongConsistency bool // If true, debug logging in this library is enabled. Debug bool // Logger is the logger used by this library for debug and error logging. Logger aws.Logger // ValueUnmarshaller can be used to change what is returned by Load, LoadOrStore, and Range. // These methods return an Item if ValueUnmarshaller is nil. // If ValueUnmarshaller is not nil, the result of passing the value item to the unmarshaller // is returned as the value instead of the item. ValueUnmarshaller ItemUnmarshaller // Options for creating the table CreateTableOptions }
TableConfig holds details about a specific DynamoDB table and some options for using it.
func (TableConfig) NewMap ¶
func (tc TableConfig) NewMap(cfg aws.Config) (*DynamoMap, error)
NewMap creates a map view of a DynamoDB table from a TableConfig. If the table does not exist or is being deleted or there is an error, the pointer result will be nil. If ScanTableIfNotExists is true and the table does not exist, it will be created. If ScanTableIfNotExists is false and the key names are not set, they will be looked up. If the logger has not been configured, either the AWS config's logger (if present) or stdout will be used.
func (TableConfig) Ranged ¶
func (tc TableConfig) Ranged() bool
Ranged returns true if RangeKeyName is not empty
func (TableConfig) ToKeyItem ¶
func (tc TableConfig) ToKeyItem(item Item) Item
ToKeyItem returns an item with only the configured key(s) copied from the given item.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package ddbconv can be used to convert between dynamodb.AttributeValue and the Go type system Some of these functions provide little more than improved readability.
|
Package ddbconv can be used to convert between dynamodb.AttributeValue and the Go type system Some of these functions provide little more than improved readability. |