ddb

package
v0.29.2 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetadataKeyTables = "cloud.aws.dynamodb.tables"

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

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 interface{}, upper interface{}) expression.ConditionBuilder

func Eq

func Eq(attribute string, value interface{}) expression.ConditionBuilder

func GetTableNameWithSettings

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

func Gt

func Gt(attribute string, value interface{}) expression.ConditionBuilder

func Gte

func Gte(attribute string, value interface{}) expression.ConditionBuilder

func IsTableNotFoundError

func IsTableNotFoundError(err error) bool

func Lt

func Lt(attribute string, value interface{}) expression.ConditionBuilder

func Lte

func Lte(attribute string, value interface{}) expression.ConditionBuilder

func MarshalMap

func MarshalMap(in interface{}) (map[string]types.AttributeValue, error)

func MetadataReadFields

func MetadataReadFields(model interface{}) ([]string, error)

func NewDecoder

func NewDecoder() *attributevalue.Decoder

func NewEncoder

func NewEncoder() *attributevalue.Encoder

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 interface{}) expression.ConditionBuilder

func TableName

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

func UnmarshalList

func UnmarshalList(l []types.AttributeValue, out interface{}) error

func UnmarshalListOfMaps

func UnmarshalListOfMaps(l []map[string]types.AttributeValue, out interface{}) error

func UnmarshalMap

func UnmarshalMap(m map[string]types.AttributeValue, out interface{}) 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 interface{}) (Attributes, error)

func (Attributes) GetByTag

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

type BatchGetItemsBuilder

type BatchGetItemsBuilder interface {
	WithKeys(values ...interface{}) BatchGetItemsBuilder
	WithKeyPairs(pairs [][]interface{}) BatchGetItemsBuilder
	WithHashKeys(hashKeys interface{}) BatchGetItemsBuilder
	DisableTtlFilter() BatchGetItemsBuilder
	WithProjection(projection interface{}) BatchGetItemsBuilder
	WithConsistentRead(consistentRead bool) BatchGetItemsBuilder
	Build(result interface{}) (*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 interface{}) (*types.ConditionCheck, error)
	ReturnNone() ConditionCheckBuilder
	ReturnAllOld() ConditionCheckBuilder
	WithHash(hashValue interface{}) ConditionCheckBuilder
	WithRange(rangeValue interface{}) ConditionCheckBuilder
	WithKeys(keys ...interface{}) 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 DeleteItemBuilder

type DeleteItemBuilder interface {
	WithHash(hashValue interface{}) DeleteItemBuilder
	WithRange(rangeValue interface{}) DeleteItemBuilder
	WithCondition(cond expression.ConditionBuilder) DeleteItemBuilder
	ReturnNone() DeleteItemBuilder
	ReturnAllOld() DeleteItemBuilder
	Build(item interface{}) (*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() interface{}
	ContainsField(field string) bool
	GetFields() []string
}

type GetItemBuilder

type GetItemBuilder interface {
	WithHash(hashValue interface{}) GetItemBuilder
	WithRange(rangeValue interface{}) GetItemBuilder
	WithKeys(keys ...interface{}) GetItemBuilder
	DisableTtlFilter() GetItemBuilder
	WithProjection(rangeValue interface{}) GetItemBuilder
	WithConsistentRead(consistentRead bool) GetItemBuilder
	Build(result interface{}) (*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              interface{}
	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 LocalSettings

type LocalSettings struct {
	Name  string
	Model interface{}
}

type MainSettings

type MainSettings struct {
	Model              interface{}
	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

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 interface{}) (*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 interface{}) QueryBuilder
	WithRangeBetween(lower interface{}, upper interface{}) QueryBuilder
	WithRangeBeginsWith(prefix string) QueryBuilder
	WithRangeEq(value interface{}) QueryBuilder
	WithRangeGt(value interface{}) QueryBuilder
	WithRangeGte(value interface{}) QueryBuilder
	WithRangeLt(value interface{}) QueryBuilder
	WithRangeLte(value interface{}) QueryBuilder
	WithFilter(filter expression.ConditionBuilder) QueryBuilder
	DisableTtlFilter() QueryBuilder
	WithProjection(projection interface{}) QueryBuilder
	WithLimit(limit int) QueryBuilder
	WithPageSize(size int) QueryBuilder
	WithDescendingOrder() QueryBuilder
	WithConsistentRead(consistentRead bool) QueryBuilder
	Build(result interface{}) (*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 interface{}) (*OperationResult, error)
	BatchGetItems(ctx context.Context, qb BatchGetItemsBuilder, result interface{}) (*OperationResult, error)
	BatchPutItems(ctx context.Context, items interface{}) (*OperationResult, error)
	DeleteItem(ctx context.Context, db DeleteItemBuilder, item interface{}) (*DeleteItemResult, error)
	GetItem(ctx context.Context, qb GetItemBuilder, result interface{}) (*GetItemResult, error)
	PutItem(ctx context.Context, qb PutItemBuilder, item interface{}) (*PutItemResult, error)
	Query(ctx context.Context, qb QueryBuilder, result interface{}) (*QueryResult, error)
	Scan(ctx context.Context, sb ScanBuilder, result interface{}) (*ScanResult, error)
	UpdateItem(ctx context.Context, ub UpdateItemBuilder, item interface{}) (*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 interface{}, progress Progress) (bool, error)

type ScanBuilder

type ScanBuilder interface {
	WithIndex(name string) ScanBuilder
	WithFilter(filter expression.ConditionBuilder) ScanBuilder
	DisableTtlFilter() ScanBuilder
	WithProjection(projection interface{}) ScanBuilder
	WithLimit(limit int) ScanBuilder
	WithPageSize(size int) ScanBuilder
	WithSegment(segment int, total int) ScanBuilder
	WithConsistentRead(consistentRead bool) ScanBuilder
	Build(result interface{}) (*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, 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)

type Settings

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

type SimpleSettings

type SimpleSettings struct {
	ModelId            mdl.ModelId
	AutoCreate         bool
	Model              interface{}
	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

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    interface{}
}

func (*TransactConditionCheck) Build

func (*TransactConditionCheck) GetItem

func (b *TransactConditionCheck) GetItem() interface{}

type TransactDeleteItem

type TransactDeleteItem struct {
	Builder DeleteItemBuilder
	Item    interface{}
}

func (*TransactDeleteItem) Build

func (*TransactDeleteItem) GetItem

func (b *TransactDeleteItem) GetItem() interface{}

type TransactGetItem

type TransactGetItem struct {
	Builder GetItemBuilder
	Item    interface{}
}

func (*TransactGetItem) Build

func (*TransactGetItem) GetItem

func (b *TransactGetItem) GetItem() interface{}

type TransactGetItemBuilder

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

type TransactPutItem

type TransactPutItem struct {
	Builder PutItemBuilder
	Item    interface{}
}

func NewTransactionPutItemBuilder

func NewTransactionPutItemBuilder() *TransactPutItem

func (*TransactPutItem) Build

func (*TransactPutItem) GetItem

func (b *TransactPutItem) GetItem() interface{}

type TransactUpdateItem

type TransactUpdateItem struct {
	Builder UpdateItemBuilder
	Item    interface{}
}

func (*TransactUpdateItem) Build

func (*TransactUpdateItem) GetItem

func (b *TransactUpdateItem) GetItem() interface{}

type TransactWriteItemBuilder

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

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 interface{}) (*Unmarshaller, error)

func NewUnmarshallerFromStruct

func NewUnmarshallerFromStruct(model interface{}) (*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) (interface{}, error)

type UpdateItemBuilder

type UpdateItemBuilder interface {
	WithHash(hashValue interface{}) UpdateItemBuilder
	WithRange(rangeValue interface{}) UpdateItemBuilder
	WithCondition(cond expression.ConditionBuilder) UpdateItemBuilder
	Add(path string, value interface{}) UpdateItemBuilder
	Delete(path string, value interface{}) UpdateItemBuilder
	Set(path string, value interface{}) UpdateItemBuilder
	SetMap(values map[string]interface{}) UpdateItemBuilder
	SetIfNotExist(path string, value interface{}) UpdateItemBuilder
	Remove(path string) UpdateItemBuilder
	RemoveMultiple(paths ...string) UpdateItemBuilder
	ReturnNone() UpdateItemBuilder
	ReturnAllOld() UpdateItemBuilder
	ReturnUpdatedOld() UpdateItemBuilder
	ReturnAllNew() UpdateItemBuilder
	ReturnUpdatedNew() UpdateItemBuilder
	Build(item interface{}) (*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