dynamodb

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: MIT Imports: 31 Imported by: 0

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

View Source
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

func BuildProjectionExpression(fields []string) (*string, map[string]*string)

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 Get

func Get() storage.IStorage

Get returns a setup storage, or set it up.

func IsConditionalCheckFailedError

func IsConditionalCheckFailedError(err error) bool

IsConditionalCheckFailedError checks if the error is a conditional check failed error.

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError checks if the error is a DynamoDB item not found error.

func IsProvisionedThroughputExceededError

func IsProvisionedThroughputExceededError(err error) bool

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 Set

func Set(s storage.IStorage)

Set sets the storage, primarily used for testing.

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

func WithPrimaryKey(primaryKey string) func(*DynamoDB)

WithPrimaryKey sets a custom primary key for the DynamoDB storage. Default is "id" if not specified.

func WithTarget

func WithTarget(target string) func(*DynamoDB)

WithTarget sets a static target (table name) for the DynamoDB storage.

Types

type Config

type Config = aws.Config

Config is the DynamoDB configuration.

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 New

func New(ctx context.Context, region string, cfg *Config) (*DynamoDB, error)

New creates a new DynamoDB storage.

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

func NewWithTable(ctx context.Context, region, tableName string, cfg *Config) (*DynamoDB, error)

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) GetClient

func (d *DynamoDB) GetClient() any

GetClient returns the client.

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.

func (*DynamoDB) Retrieve

func (d *DynamoDB) Retrieve(ctx context.Context, id, target string, v any, prm *retrieve.Retrieve, options ...storage.Func[*retrieve.Retrieve]) error

Retrieve data.

func (*DynamoDB) Update

func (d *DynamoDB) Update(ctx context.Context, id, target string, v any, prm *update.Update, opts ...storage.Func[*update.Update]) error

Update data.

type GetItemInput

type GetItemInput = dynamodb.GetItemInput

GetItemInput represents DynamoDB get item input.

type Item

type Item map[string]*dynamodb.AttributeValue

Item represents a DynamoDB item.

type Items

type Items []Item

Items represents a slice of DynamoDB items.

type PutItemInput

type PutItemInput = dynamodb.PutItemInput

PutItemInput represents DynamoDB put item input.

type QueryInput

type QueryInput = dynamodb.QueryInput

QueryInput represents DynamoDB query input.

type ScanInput

type ScanInput = dynamodb.ScanInput

ScanInput represents DynamoDB scan input.

type TableDescription

type TableDescription = dynamodb.TableDescription

TableDescription represents DynamoDB table description.

type UpdateItemInput

type UpdateItemInput = dynamodb.UpdateItemInput

UpdateItemInput represents DynamoDB update item input.

Jump to

Keyboard shortcuts

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