ddb

package
v0.46.2 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2025 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetricNameAccessSuccess = "DdbAccessSuccess"
	MetricNameAccessFailure = "DdbAccessFailure"
	MetricNameAccessLatency = "DdbAccessLatency"

	OpSave = "save"

	StreamViewTypeNewImage        = types.StreamViewTypeNewImage
	StreamViewTypeOldImage        = types.StreamViewTypeOldImage
	StreamViewTypeNewAndOldImages = types.StreamViewTypeNewAndOldImages
	StreamViewTypeKeysOnly        = types.StreamViewTypeKeysOnly

	Create = "create"
	Update = "update"
	Delete = "delete"
)
View Source
const MetadataKeyTables = "cloud.aws.dynamodb.tables"

Variables

This section is empty.

Functions

func AttributeExists

func AttributeExists(attribute string) expression.ConditionBuilder

func AttributeNotExists

func AttributeNotExists(attribute string) expression.ConditionBuilder

func Between

func Between(attribute string, lower any, upper any) expression.ConditionBuilder

func DynamoDbFixtureSetFactory added in v0.37.0

func DynamoDbFixtureSetFactory[T any](settings *Settings, data fixtures.NamedFixtures[T], options ...fixtures.FixtureSetOption) fixtures.FixtureSetFactory

func Eq

func Eq(attribute string, value any) expression.ConditionBuilder

func GetTableNameWithSettings

func GetTableNameWithSettings(tableSettings *Settings, namingSettings *TableNamingSettings) string

func Gt

func Gt(attribute string, value any) expression.ConditionBuilder

func Gte

func Gte(attribute string, value any) expression.ConditionBuilder

func IsTableNotFoundError

func IsTableNotFoundError(err error) bool

func Lt

func Lt(attribute string, value any) expression.ConditionBuilder

func Lte

func Lte(attribute string, value any) expression.ConditionBuilder

func MarshalMap

func MarshalMap(in any) (map[string]types.AttributeValue, error)

func MetadataReadFields

func MetadataReadFields(model any) ([]string, error)

func NewDecoder

func NewDecoder() *attributevalue.Decoder

func NewDynamoDbFixtureWriter added in v0.37.0

func NewDynamoDbFixtureWriter(ctx context.Context, config cfg.Config, logger log.Logger, settings *Settings, options ...DdbWriterOption) (fixtures.FixtureWriter, error)

func NewDynamoDbFixtureWriterWithInterfaces added in v0.37.0

func NewDynamoDbFixtureWriterWithInterfaces(logger log.Logger, repo Repository) fixtures.FixtureWriter

func NewEncoder

func NewEncoder() *attributevalue.Encoder

func NewLifecycleManager added in v0.37.0

func NewLifecycleManager(settings *Settings, optFns ...gosoDynamodb.ClientOption) reslife.LifeCycleerFactory

func NewMetricRepository

func NewMetricRepository(_ cfg.Config, _ log.Logger, repo Repository) *metricRepository

func NewTransactionRepository

func NewTransactionRepository(ctx context.Context, config cfg.Config, logger log.Logger, name string) (*transactionRepository, error)

func NewTransactionRepositoryWithInterfaces

func NewTransactionRepositoryWithInterfaces(logger log.Logger, client gosoDynamodb.Client, tracer tracing.Tracer) *transactionRepository

func NotEq

func NotEq(attribute string, value any) expression.ConditionBuilder

func TableName

func TableName(config cfg.Config, settings *Settings) (string, error)

func UnmarshalList

func UnmarshalList(l []types.AttributeValue, out any) error

func UnmarshalListOfMaps

func UnmarshalListOfMaps(l []map[string]types.AttributeValue, out any) error

func UnmarshalMap

func UnmarshalMap(m map[string]types.AttributeValue, out any) error

Types

type Attribute

type Attribute struct {
	FieldName     string
	AttributeName string
	Tags          map[string]string
	Type          types.ScalarAttributeType
}

func (*Attribute) HasTag

func (d *Attribute) HasTag(key string, value string) bool

type Attributes

type Attributes map[string]*Attribute

func ReadAttributes

func ReadAttributes(model any) (Attributes, error)

func (Attributes) GetByTag

func (a Attributes) GetByTag(key string, value string) (*Attribute, error)

type BatchGetItemsBuilder

type BatchGetItemsBuilder interface {
	WithKeys(values ...any) BatchGetItemsBuilder
	WithKeyPairs(pairs [][]any) BatchGetItemsBuilder
	WithHashKeys(hashKeys any) BatchGetItemsBuilder
	DisableTtlFilter() BatchGetItemsBuilder
	WithProjection(projection any) BatchGetItemsBuilder
	WithConsistentRead(consistentRead bool) BatchGetItemsBuilder
	Build(result any) (*dynamodb.BatchGetItemInput, error)
}

func NewBatchGetItemsBuilder

func NewBatchGetItemsBuilder(metadata *Metadata, clock clock.Clock) BatchGetItemsBuilder

type Capacity

type Capacity struct {
	// contains filtered or unexported fields
}

func (*Capacity) Read

func (c *Capacity) Read() float64

func (*Capacity) Total

func (c *Capacity) Total() float64

func (*Capacity) Write

func (c *Capacity) Write() float64

type ConditionCheckBuilder

type ConditionCheckBuilder interface {
	Build(result any) (*types.ConditionCheck, error)
	ReturnNone() ConditionCheckBuilder
	ReturnAllOld() ConditionCheckBuilder
	WithHash(hashValue any) ConditionCheckBuilder
	WithRange(rangeValue any) ConditionCheckBuilder
	WithKeys(keys ...any) ConditionCheckBuilder
	WithCondition(cond expression.ConditionBuilder) ConditionCheckBuilder
}

func NewConditionCheckBuilder

func NewConditionCheckBuilder(metadata *Metadata) ConditionCheckBuilder

type ConsumedCapacity

type ConsumedCapacity struct {
	Capacity
	Table Capacity
	LSI   map[string]*Capacity
	GSI   map[string]*Capacity
}

type DdbWriterOption added in v0.37.0

type DdbWriterOption func(settings *Settings)

func WithApplication added in v0.37.0

func WithApplication(application string) DdbWriterOption

type DeleteItemBuilder

type DeleteItemBuilder interface {
	WithHash(hashValue any) DeleteItemBuilder
	WithRange(rangeValue any) DeleteItemBuilder
	WithCondition(cond expression.ConditionBuilder) DeleteItemBuilder
	ReturnNone() DeleteItemBuilder
	ReturnAllOld() DeleteItemBuilder
	Build(item any) (*dynamodb.DeleteItemInput, error)
}

func NewDeleteItemBuilder

func NewDeleteItemBuilder(metadata *Metadata) DeleteItemBuilder

type DeleteItemResult

type DeleteItemResult struct {
	ConditionalCheckFailed bool
	ConsumedCapacity       *ConsumedCapacity
}

type FieldAware

type FieldAware interface {
	KeyAware
	GetModel() any
	ContainsField(field string) bool
	GetFields() []string
}

type GetItemBuilder

type GetItemBuilder interface {
	WithHash(hashValue any) GetItemBuilder
	WithRange(rangeValue any) GetItemBuilder
	WithKeys(keys ...any) GetItemBuilder
	DisableTtlFilter() GetItemBuilder
	WithProjection(rangeValue any) GetItemBuilder
	WithConsistentRead(consistentRead bool) GetItemBuilder
	Build(result any) (*dynamodb.GetItemInput, error)
}

func NewGetItemBuilder

func NewGetItemBuilder(metadata *Metadata, clock clock.Clock) GetItemBuilder

type GetItemResult

type GetItemResult struct {
	IsFound          bool
	ConsumedCapacity *ConsumedCapacity
}

type GlobalSettings

type GlobalSettings struct {
	Name               string
	Model              any
	ReadCapacityUnits  int64
	WriteCapacityUnits int64
}

type KeyAware

type KeyAware interface {
	IsKeyField(field string) bool
	GetHashKey() *string
	GetRangeKey() *string
	GetKeyFields() []string
}

type KeyValues

type KeyValues map[string]types.AttributeValue

type LifeCyclePurger added in v0.38.3

type LifeCyclePurger struct {
	// contains filtered or unexported fields
}

func NewLifeCyclePurger added in v0.38.3

func NewLifeCyclePurger(ctx context.Context, config cfg.Config, logger log.Logger, clientName string, tableName string) (*LifeCyclePurger, error)

func (*LifeCyclePurger) Purge added in v0.38.3

func (s *LifeCyclePurger) Purge(ctx context.Context) error

type LifecycleManager added in v0.37.0

type LifecycleManager interface {
	reslife.LifeCycleer
	reslife.Creator
	reslife.Registerer
	reslife.Purger
}

type LocalSettings

type LocalSettings struct {
	Name  string
	Model any
}

type MainSettings

type MainSettings struct {
	Model              any
	StreamView         types.StreamViewType
	ReadCapacityUnits  int64
	WriteCapacityUnits int64
}

type Metadata

type Metadata struct {
	TableName  string
	Attributes Attributes
	TimeToLive metadataTtl
	Main       metadataMain
	Local      metaLocal
	Global     metaGlobal
}

func (*Metadata) Index

func (d *Metadata) Index(name string) FieldAware

type MetadataFactory

type MetadataFactory struct {
	// contains filtered or unexported fields
}

func NewMetadataFactory

func NewMetadataFactory(config cfg.Config, settings *Settings) (*MetadataFactory, error)

func NewMetadataFactoryWithInterfaces

func NewMetadataFactoryWithInterfaces(settings *Settings, tableName string) *MetadataFactory

func (*MetadataFactory) GetMetadata

func (f *MetadataFactory) GetMetadata() (*Metadata, error)

func (*MetadataFactory) GetSettings

func (f *MetadataFactory) GetSettings() *Settings

func (*MetadataFactory) GetTableName

func (f *MetadataFactory) GetTableName() string

type OperationResult

type OperationResult struct {
	ConsumedCapacity *ConsumedCapacity
}

type Progress

type Progress interface {
	GetRequestCount() int32
	GetItemCount() int32
	GetScannedCount() int32
	GetConsumedCapacity() *ConsumedCapacity
}

type PutItemBuilder

type PutItemBuilder interface {
	WithCondition(cond expression.ConditionBuilder) PutItemBuilder
	ReturnNone() PutItemBuilder
	ReturnAllOld() PutItemBuilder
	Build(item any) (*dynamodb.PutItemInput, error)
}

func NewPutItemBuilder

func NewPutItemBuilder(metadata *Metadata) PutItemBuilder

type PutItemResult

type PutItemResult struct {
	ConditionalCheckFailed bool
	ConsumedCapacity       *ConsumedCapacity
	IsReturnEmpty          bool
}

type QueryBuilder

type QueryBuilder interface {
	WithIndex(name string) QueryBuilder
	WithHash(value any) QueryBuilder
	WithRangeBetween(lower any, upper any) QueryBuilder
	WithRangeBeginsWith(prefix string) QueryBuilder
	WithRangeEq(value any) QueryBuilder
	WithRangeGt(value any) QueryBuilder
	WithRangeGte(value any) QueryBuilder
	WithRangeLt(value any) QueryBuilder
	WithRangeLte(value any) QueryBuilder
	WithFilter(filter expression.ConditionBuilder) QueryBuilder
	DisableTtlFilter() QueryBuilder
	WithProjection(projection any) QueryBuilder
	WithLimit(limit int) QueryBuilder
	WithPageSize(size int) QueryBuilder
	WithDescendingOrder() QueryBuilder
	WithConsistentRead(consistentRead bool) QueryBuilder
	Build(result any) (*QueryOperation, error)
}

func NewQueryBuilder

func NewQueryBuilder(metadata *Metadata, clock clock.Clock) QueryBuilder

type QueryOperation

type QueryOperation struct {
	// contains filtered or unexported fields
}

type QueryResult

type QueryResult struct {
	RequestCount     int32
	ItemCount        int32
	ScannedCount     int32
	ConsumedCapacity *ConsumedCapacity
}

func (QueryResult) GetConsumedCapacity

func (q QueryResult) GetConsumedCapacity() *ConsumedCapacity

func (QueryResult) GetItemCount

func (q QueryResult) GetItemCount() int32

func (QueryResult) GetRequestCount

func (q QueryResult) GetRequestCount() int32

func (QueryResult) GetScannedCount

func (q QueryResult) GetScannedCount() int32

type Repository

type Repository interface {
	GetModelId() mdl.ModelId

	BatchDeleteItems(ctx context.Context, value any) (*OperationResult, error)
	BatchGetItems(ctx context.Context, qb BatchGetItemsBuilder, result any) (*OperationResult, error)
	BatchPutItems(ctx context.Context, items any) (*OperationResult, error)
	DeleteItem(ctx context.Context, db DeleteItemBuilder, item any) (*DeleteItemResult, error)
	GetItem(ctx context.Context, qb GetItemBuilder, result any) (*GetItemResult, error)
	PutItem(ctx context.Context, qb PutItemBuilder, item any) (*PutItemResult, error)
	Query(ctx context.Context, qb QueryBuilder, result any) (*QueryResult, error)
	Scan(ctx context.Context, sb ScanBuilder, result any) (*ScanResult, error)
	UpdateItem(ctx context.Context, ub UpdateItemBuilder, item any) (*UpdateItemResult, error)

	BatchGetItemsBuilder() BatchGetItemsBuilder
	DeleteItemBuilder() DeleteItemBuilder
	GetItemBuilder() GetItemBuilder
	QueryBuilder() QueryBuilder
	PutItemBuilder() PutItemBuilder
	ScanBuilder() ScanBuilder
	UpdateItemBuilder() UpdateItemBuilder
}

func NewRepository

func NewRepository(ctx context.Context, config cfg.Config, logger log.Logger, settings *Settings, optFns ...gosoDynamodb.ClientOption) (Repository, error)

func NewWithInterfaces

func NewWithInterfaces(logger log.Logger, tracer tracing.Tracer, client gosoDynamodb.Client, metadataFactory *MetadataFactory) (Repository, error)

type ResultCallback

type ResultCallback func(ctx context.Context, items any, progress Progress) (bool, error)

type ScanBuilder

type ScanBuilder interface {
	WithIndex(name string) ScanBuilder
	WithFilter(filter expression.ConditionBuilder) ScanBuilder
	DisableTtlFilter() ScanBuilder
	WithProjection(projection any) ScanBuilder
	WithLimit(limit int) ScanBuilder
	WithPageSize(size int) ScanBuilder
	WithSegment(segment int, total int) ScanBuilder
	WithConsistentRead(consistentRead bool) ScanBuilder
	Build(result any) (*ScanOperation, error)
}

func NewScanBuilder

func NewScanBuilder(metadata *Metadata, clock clock.Clock) ScanBuilder

type ScanOperation

type ScanOperation struct {
	// contains filtered or unexported fields
}

type ScanResult

type ScanResult struct {
	RequestCount     int32
	ItemCount        int32
	ScannedCount     int32
	ConsumedCapacity *ConsumedCapacity
}

func (ScanResult) GetConsumedCapacity

func (s ScanResult) GetConsumedCapacity() *ConsumedCapacity

func (ScanResult) GetItemCount

func (s ScanResult) GetItemCount() int32

func (ScanResult) GetRequestCount

func (s ScanResult) GetRequestCount() int32

func (ScanResult) GetScannedCount

func (s ScanResult) GetScannedCount() int32

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(ctx context.Context, config cfg.Config, logger log.Logger, settings *Settings, optFns ...gosoDynamodb.ClientOption) (*Service, error)

func NewServiceWithInterfaces

func NewServiceWithInterfaces(logger log.Logger, client gosoDynamodb.Client, purger reslife.Purger, metadataFactory *MetadataFactory) *Service

func (*Service) CreateTable

func (s *Service) CreateTable(ctx context.Context) (*Metadata, error)

func (*Service) DescribeTable

func (s *Service) DescribeTable(ctx context.Context) (*TableDescription, error)

func (*Service) PurgeTable added in v0.37.0

func (s *Service) PurgeTable(ctx context.Context) error

type Settings

type Settings struct {
	ModelId             mdl.ModelId
	TableNamingSettings TableNamingSettings
	DisableTracing      bool
	ClientName          string
	Main                MainSettings
	Local               []LocalSettings
	Global              []GlobalSettings
}

type SimpleSettings

type SimpleSettings struct {
	ModelId            mdl.ModelId
	AutoCreate         bool
	Model              any
	StreamView         string
	ReadCapacityUnits  int64
	WriteCapacityUnits int64
}

type TableDescription

type TableDescription struct {
	Name      string
	ItemCount int64
}

type TableMetadata

type TableMetadata struct {
	AwsClientName string `json:"aws_client_name"`
	TableName     string `json:"table_name"`
}

type TableNamingSettings

type TableNamingSettings struct {
	Pattern string `cfg:"pattern,nodecode" default:"{project}-{env}-{family}-{group}-{modelId}"`
}

func GetTableNamingSettings

func GetTableNamingSettings(config cfg.Config, clientName string) (*TableNamingSettings, error)

type TableNotFoundError

type TableNotFoundError struct {
	TableName string
	// contains filtered or unexported fields
}

func NewTableNotFoundError

func NewTableNotFoundError(tableName string, err error) TableNotFoundError

func (TableNotFoundError) Error

func (t TableNotFoundError) Error() string

func (TableNotFoundError) Unwrap

func (t TableNotFoundError) Unwrap() error

type TransactConditionCheck

type TransactConditionCheck struct {
	Builder ConditionCheckBuilder
	Item    any
}

func (*TransactConditionCheck) Build

func (*TransactConditionCheck) GetItem

func (b *TransactConditionCheck) GetItem() any

type TransactDeleteItem

type TransactDeleteItem struct {
	Builder DeleteItemBuilder
	Item    any
}

func (*TransactDeleteItem) Build

func (*TransactDeleteItem) GetItem

func (b *TransactDeleteItem) GetItem() any

type TransactGetItem

type TransactGetItem struct {
	Builder GetItemBuilder
	Item    any
}

func (*TransactGetItem) Build

func (*TransactGetItem) GetItem

func (b *TransactGetItem) GetItem() any

type TransactGetItemBuilder

type TransactGetItemBuilder interface {
	Build() (types.TransactGetItem, error)
	GetItem() any
}

type TransactPutItem

type TransactPutItem struct {
	Builder PutItemBuilder
	Item    any
}

func NewTransactionPutItemBuilder

func NewTransactionPutItemBuilder() *TransactPutItem

func (*TransactPutItem) Build

func (*TransactPutItem) GetItem

func (b *TransactPutItem) GetItem() any

type TransactUpdateItem

type TransactUpdateItem struct {
	Builder UpdateItemBuilder
	Item    any
}

func (*TransactUpdateItem) Build

func (*TransactUpdateItem) GetItem

func (b *TransactUpdateItem) GetItem() any

type TransactWriteItemBuilder

type TransactWriteItemBuilder interface {
	Build() (*types.TransactWriteItem, error)
	GetItem() any
}

type TransactionRepository

type TransactionRepository interface {
	TransactWriteItems(ctx context.Context, items []TransactWriteItemBuilder) (*OperationResult, error)
	TransactGetItems(ctx context.Context, items []TransactGetItemBuilder) (*OperationResult, error)
}

type Unmarshaller

type Unmarshaller struct {
	// contains filtered or unexported fields
}

func NewUnmarshallerFromPtrSlice

func NewUnmarshallerFromPtrSlice(result any) (*Unmarshaller, error)

func NewUnmarshallerFromStruct

func NewUnmarshallerFromStruct(model any) (*Unmarshaller, error)

func (*Unmarshaller) Append

func (u *Unmarshaller) Append(items []map[string]types.AttributeValue) error

func (*Unmarshaller) Unmarshal

func (u *Unmarshaller) Unmarshal(items []map[string]types.AttributeValue) (any, error)

type UpdateItemBuilder

type UpdateItemBuilder interface {
	WithHash(hashValue any) UpdateItemBuilder
	WithRange(rangeValue any) UpdateItemBuilder
	WithCondition(cond expression.ConditionBuilder) UpdateItemBuilder
	Add(path string, value any) UpdateItemBuilder
	Delete(path string, value any) UpdateItemBuilder
	Set(path string, value any) UpdateItemBuilder
	SetMap(values map[string]any) UpdateItemBuilder
	SetIfNotExist(path string, value any) UpdateItemBuilder
	Remove(path string) UpdateItemBuilder
	RemoveMultiple(paths ...string) UpdateItemBuilder
	ReturnNone() UpdateItemBuilder
	ReturnAllOld() UpdateItemBuilder
	ReturnUpdatedOld() UpdateItemBuilder
	ReturnAllNew() UpdateItemBuilder
	ReturnUpdatedNew() UpdateItemBuilder
	Build(item any) (*dynamodb.UpdateItemInput, error)
}

func NewUpdateItemBuilder

func NewUpdateItemBuilder(metadata *Metadata) UpdateItemBuilder

type UpdateItemResult

type UpdateItemResult struct {
	ConditionalCheckFailed bool
	ConsumedCapacity       *ConsumedCapacity
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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