dynamodb

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 32 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]any) (
	*string,
	map[string]string,
	map[string]types.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]any, primaryKey string) (
	*string,
	map[string]string,
	map[string]types.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 any) (map[string]types.AttributeValue, error)

MarshalItem marshals a Go value to a DynamoDB item.

func MarshalKey

func MarshalKey(keyName string, keyValue any) (map[string]types.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]types.AttributeValue, v any) error

UnmarshalItem unmarshals a DynamoDB item to a Go value.

func UnmarshalItems

func UnmarshalItems(items []map[string]types.AttributeValue, v any) 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.
	//
	// structonly: skips validating *into* the client's fields (only checks
	// non-nilness) - same reasoning as Config below applies to any live SDK
	// state reachable from it.
	Client *awsdynamodb.Client `json:"-" validate:"required,structonly"`

	// Config is the DynamoDB configuration.
	//
	// Skipped by the validator: it dives into untagged nested structs, and an
	// aws.Config holds live SDK state (credentials guarded by a mutex, which
	// background SDK goroutines write) that must not be read reflectively.
	Config Config `json:"-" validate:"-"`

	// 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"`
	// contains filtered or unexported fields
}

DynamoDB storage definition.

func New

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

New creates a new DynamoDB storage.

func NewWithDynamicTable

func NewWithDynamicTable(
	ctx context.Context,
	region string,
	dynamicTableFunc DynamicTableFunc,
	cfg *Config,
	options ...func(*DynamoDB),
) (*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,
	options ...func(*DynamoDB),
) (*DynamoDB, error)

NewWithTable creates a new DynamoDB storage with a static table name.

func (*DynamoDB) BulkCreate

func (d *DynamoDB) BulkCreate(
	ctx context.Context,
	target string,
	items []storage.BulkItem,
	prm *create.Create,
	optionFuncs ...storage.Func[*create.Create],
) (storage.BulkResult, error)

BulkCreate writes at most 25 items per BatchWriteItem request and retries UnprocessedItems with bounded exponential backoff.

func (*DynamoDB) Close

func (d *DynamoDB) Close() error

Close releases the resources held by the storage.

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.

Any accepts a map[string]any for DynamoDB filter expressions. Limit, Offset, and Fields are applied; Sort is not currently used.

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]types.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 = types.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
⌂ 换网址