Documentation
¶
Overview ¶
Package dynamodb provides a DynamoDB implementation of the storage interface.
Package dynamodb provides a DynamoDB implementation of the storage interface.
Package dynamodb provides a DynamoDB implementation of the storage interface.
Index ¶
- Constants
- func BuildFilterExpression(conditions map[string]interface{}) (*string, map[string]*string, map[string]*dynamodb.AttributeValue, error)
- func BuildProjectionExpression(fields []string) (*string, map[string]*string)
- func BuildUpdateExpression(updates map[string]interface{}, primaryKey string) (*string, map[string]*string, map[string]*dynamodb.AttributeValue, error)
- func Get() storage.IStorage
- func IsConditionalCheckFailedError(err error) bool
- func IsNotFoundError(err error) bool
- func IsProvisionedThroughputExceededError(err error) bool
- func MarshalItem(v interface{}) (map[string]*dynamodb.AttributeValue, error)
- func MarshalKey(keyName string, keyValue interface{}) (map[string]*dynamodb.AttributeValue, error)
- func Set(s storage.IStorage)
- func ToDynamoDBSort(s customsort.Sort) (bool, error)
- func UnmarshalItem(item map[string]*dynamodb.AttributeValue, v interface{}) error
- func UnmarshalItems(items []map[string]*dynamodb.AttributeValue, v interface{}) error
- func WithDynamicTarget(targetFunc DynamicTableFunc) func(*DynamoDB)
- func WithPrimaryKey(primaryKey string) func(*DynamoDB)
- func WithTarget(target string) func(*DynamoDB)
- type Config
- type CreateTableInput
- type DeleteItemInput
- type DynamicTableFunc
- type DynamoDB
- func (d *DynamoDB) Count(ctx context.Context, target string, prm *count.Count, ...) (int64, error)
- func (d *DynamoDB) Create(ctx context.Context, id, target string, v any, prm *create.Create, ...) (string, error)
- func (d *DynamoDB) Delete(ctx context.Context, id, target string, prm *delete.Delete, ...) error
- func (d *DynamoDB) GetClient() any
- func (d *DynamoDB) List(ctx context.Context, target string, v any, prm *list.List, ...) error
- func (d *DynamoDB) Retrieve(ctx context.Context, id, target string, v any, prm *retrieve.Retrieve, ...) error
- func (d *DynamoDB) Update(ctx context.Context, id, target string, v any, prm *update.Update, ...) error
- type GetItemInput
- type Item
- type Items
- type PutItemInput
- type QueryInput
- type ScanInput
- type TableDescription
- type UpdateItemInput
Constants ¶
const Name = "dynamodb"
Name of the storage.
Variables ¶
This section is empty.
Functions ¶
func BuildFilterExpression ¶
func BuildFilterExpression(conditions map[string]interface{}) ( *string, map[string]*string, map[string]*dynamodb.AttributeValue, error, )
BuildFilterExpression builds a DynamoDB filter expression from a map of conditions.
func BuildProjectionExpression ¶
BuildProjectionExpression builds a DynamoDB projection expression from a slice of field names.
func BuildUpdateExpression ¶
func BuildUpdateExpression(updates map[string]interface{}, primaryKey string) ( *string, map[string]*string, map[string]*dynamodb.AttributeValue, error, )
BuildUpdateExpression builds a DynamoDB update expression from a map of fields to update.
func IsConditionalCheckFailedError ¶
IsConditionalCheckFailedError checks if the error is a conditional check failed error.
func IsNotFoundError ¶
IsNotFoundError checks if the error is a DynamoDB item not found error.
func IsProvisionedThroughputExceededError ¶
IsProvisionedThroughputExceededError checks if the error is a throughput exceeded error.
func MarshalItem ¶
func MarshalItem(v interface{}) (map[string]*dynamodb.AttributeValue, error)
MarshalItem marshals a Go value to a DynamoDB item.
func MarshalKey ¶
func MarshalKey(keyName string, keyValue interface{}) (map[string]*dynamodb.AttributeValue, error)
MarshalKey marshals a key value for DynamoDB operations.
func ToDynamoDBSort ¶
func ToDynamoDBSort(s customsort.Sort) (bool, error)
ToDynamoDBSort converts the `Sort` to DynamoDB sort format.
func UnmarshalItem ¶
func UnmarshalItem(item map[string]*dynamodb.AttributeValue, v interface{}) error
UnmarshalItem unmarshals a DynamoDB item to a Go value.
func UnmarshalItems ¶
func UnmarshalItems(items []map[string]*dynamodb.AttributeValue, v interface{}) error
UnmarshalItems unmarshals a slice of DynamoDB items to a slice of Go values.
func WithDynamicTarget ¶
func WithDynamicTarget(targetFunc DynamicTableFunc) func(*DynamoDB)
WithDynamicTarget sets a dynamic target function for the DynamoDB storage.
func WithPrimaryKey ¶
WithPrimaryKey sets a custom primary key for the DynamoDB storage. Default is "id" if not specified.
func WithTarget ¶
WithTarget sets a static target (table name) for the DynamoDB storage.
Types ¶
type CreateTableInput ¶
type CreateTableInput = dynamodb.CreateTableInput
CreateTableInput represents DynamoDB create table input.
type DeleteItemInput ¶
type DeleteItemInput = dynamodb.DeleteItemInput
DeleteItemInput represents DynamoDB delete item input.
type DynamicTableFunc ¶
type DynamicTableFunc func() string
DynamicTableFunc is a function which defines the name of the table, and evaluated at the operation time.
type DynamoDB ¶
type DynamoDB struct {
*storage.Storage
// Client is the DynamoDB client.
Client *dynamodb.DynamoDB `json:"-" validate:"required"`
// Config is the DynamoDB configuration.
Config Config `json:"-"`
// Region is the AWS region.
Region string `json:"region" validate:"required"`
// Target allows to set a static target. If it is empty, the target will be
// dynamic - the one set at the operation (count, create, delete, etc) time.
// Depending on the storage, target is a collection, a table, a bucket, etc.
// For DynamoDB, the target is the table name. This function allows for
// dynamic table naming, useful for time-based partitioning or other patterns.
Target DynamicTableFunc `json:"-"`
// PrimaryKey is the primary key field name for DynamoDB.
// Default is "id" if not specified.
PrimaryKey string `json:"primaryKey" validate:"required"`
}
DynamoDB storage definition.
func NewWithDynamicTable ¶
func NewWithDynamicTable(ctx context.Context, region string, dynamicTableFunc DynamicTableFunc, cfg *Config) (*DynamoDB, error)
NewWithDynamicTable creates a new DynamoDB storage with a dynamic table function. This allows for table names to be computed at runtime, useful for time-based partitioning.
func NewWithTable ¶
NewWithTable creates a new DynamoDB storage with a static table name.
func (*DynamoDB) Count ¶
func (d *DynamoDB) Count(ctx context.Context, target string, prm *count.Count, options ...storage.Func[*count.Count]) (int64, error)
Count returns the number of items in the storage.
func (*DynamoDB) Create ¶
func (d *DynamoDB) Create(ctx context.Context, id, target string, v any, prm *create.Create, options ...storage.Func[*create.Create]) (string, error)
Create data.
NOTE: DynamoDB requires the primary key to be set in the model (`v`).
func (*DynamoDB) Delete ¶
func (d *DynamoDB) Delete(ctx context.Context, id, target string, prm *delete.Delete, options ...storage.Func[*delete.Delete]) error
Delete removes data.
func (*DynamoDB) List ¶
func (d *DynamoDB) List(ctx context.Context, target string, v any, prm *list.List, opts ...storage.Func[*list.List]) error
List data.
NOTE: It uses param.List.Any for DynamoDB filter expressions.
type GetItemInput ¶
type GetItemInput = dynamodb.GetItemInput
GetItemInput represents DynamoDB get item input.
type PutItemInput ¶
type PutItemInput = dynamodb.PutItemInput
PutItemInput represents DynamoDB put item input.
type TableDescription ¶
type TableDescription = dynamodb.TableDescription
TableDescription represents DynamoDB table description.
type UpdateItemInput ¶
type UpdateItemInput = dynamodb.UpdateItemInput
UpdateItemInput represents DynamoDB update item input.