Documentation
¶
Overview ¶
Package dynamorm provides a type-safe ORM for Amazon DynamoDB in Go
lambda.go
multiaccount.go
Index ¶
- Variables
- func EnableXRayTracing() bool
- func GetLambdaMemoryMB() int
- func GetPartnerFromContext(ctx context.Context) string
- func GetRemainingTimeMillis(ctx context.Context) int64
- func IsLambdaEnvironment() bool
- func New(config session.Config) (core.ExtendedDB, error)
- func NewBasic(config session.Config) (core.DB, error)
- func PartnerContext(ctx context.Context, partnerID string) context.Context
- type AccountConfig
- type AutoMigrateOption
- type ColdStartMetrics
- type Config
- type DB
- func (db *DB) AutoMigrate(models ...any) error
- func (db *DB) AutoMigrateWithOptions(model any, opts ...any) error
- func (db *DB) Close() error
- func (db *DB) CreateTable(model any, opts ...any) error
- func (db *DB) DeleteTable(model any) error
- func (db *DB) DescribeTable(model any) (any, error)
- func (db *DB) EnsureTable(model any) error
- func (db *DB) Migrate() error
- func (db *DB) Model(model any) core.Query
- func (db *DB) Transaction(fn func(tx *core.Tx) error) error
- func (db *DB) TransactionFunc(fn func(tx any) error) error
- func (db *DB) WithContext(ctx context.Context) core.DB
- func (db *DB) WithLambdaTimeout(ctx context.Context) core.DB
- func (db *DB) WithLambdaTimeoutBuffer(buffer time.Duration) core.DB
- type LambdaDB
- func (ldb *LambdaDB) GetMemoryStats() LambdaMemoryStats
- func (ldb *LambdaDB) IsModelRegistered(model any) bool
- func (ldb *LambdaDB) OptimizeForColdStart()
- func (ldb *LambdaDB) OptimizeForMemory()
- func (ldb *LambdaDB) PreRegisterModels(models ...any) error
- func (ldb *LambdaDB) WithLambdaTimeout(ctx context.Context) *LambdaDB
- type LambdaMemoryStats
- type MultiAccountDB
- func (mdb *MultiAccountDB) AddPartner(partnerID string, config AccountConfig)
- func (mdb *MultiAccountDB) Close() error
- func (mdb *MultiAccountDB) Partner(partnerID string) (*LambdaDB, error)
- func (mdb *MultiAccountDB) RemovePartner(partnerID string)
- func (mdb *MultiAccountDB) WithContext(ctx context.Context) *MultiAccountDB
Constants ¶
This section is empty.
Variables ¶
var ( WithBackupTable = schema.WithBackupTable WithDataCopy = schema.WithDataCopy WithTargetModel = schema.WithTargetModel WithTransform = schema.WithTransform WithBatchSize = schema.WithBatchSize )
Re-export AutoMigrate options for convenience
Functions ¶
func EnableXRayTracing ¶
func EnableXRayTracing() bool
EnableXRayTracing enables AWS X-Ray tracing for DynamoDB calls
func GetLambdaMemoryMB ¶
func GetLambdaMemoryMB() int
GetLambdaMemoryMB returns the allocated memory in MB
func GetPartnerFromContext ¶
GetPartnerFromContext retrieves partner ID from context
func GetRemainingTimeMillis ¶
GetRemainingTimeMillis returns milliseconds until Lambda timeout
func IsLambdaEnvironment ¶
func IsLambdaEnvironment() bool
IsLambdaEnvironment detects if running in AWS Lambda
func New ¶
func New(config session.Config) (core.ExtendedDB, error)
New creates a new DynamORM instance with the given configuration
Types ¶
type AccountConfig ¶
type AccountConfig struct {
RoleARN string
ExternalID string
Region string
// Optional: Custom session duration (default is 1 hour)
SessionDuration time.Duration
}
AccountConfig holds configuration for a partner account
type AutoMigrateOption ¶
type AutoMigrateOption = schema.AutoMigrateOption
Re-export types for convenience
type ColdStartMetrics ¶
type ColdStartMetrics struct {
TotalDuration time.Duration
Phases map[string]time.Duration
MemoryMB int
IsLambda bool
}
ColdStartMetrics contains cold start performance data
func BenchmarkColdStart ¶
func BenchmarkColdStart(models ...any) ColdStartMetrics
BenchmarkColdStart measures cold start performance
func (ColdStartMetrics) String ¶
func (m ColdStartMetrics) String() string
String returns a formatted string of the metrics
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is the main DynamORM database instance
func (*DB) AutoMigrate ¶
AutoMigrate creates or updates tables based on the given models
func (*DB) AutoMigrateWithOptions ¶
AutoMigrateWithOptions performs enhanced auto-migration with data copy support
func (*DB) CreateTable ¶
CreateTable creates a DynamoDB table for the given model
func (*DB) DeleteTable ¶
DeleteTable deletes the DynamoDB table for the given model
func (*DB) DescribeTable ¶
DescribeTable returns the table description for the given model
func (*DB) EnsureTable ¶
EnsureTable checks if a table exists for the model and creates it if not
func (*DB) Transaction ¶
Transaction executes a function within a database transaction
func (*DB) TransactionFunc ¶
TransactionFunc executes a function within a database transaction This is the actual implementation that uses our sophisticated transaction support
func (*DB) WithContext ¶
WithContext returns a new DB instance with the given context
func (*DB) WithLambdaTimeout ¶
WithLambdaTimeout sets a deadline based on Lambda context
type LambdaDB ¶
type LambdaDB struct {
core.ExtendedDB
// contains filtered or unexported fields
}
LambdaDB wraps DB with Lambda-specific optimizations
func LambdaInit ¶
LambdaInit should be called in the init() function of your Lambda handler It performs one-time initialization to reduce cold start latency
func NewLambdaOptimized ¶
NewLambdaOptimized creates a Lambda-optimized DB instance
func (*LambdaDB) GetMemoryStats ¶
func (ldb *LambdaDB) GetMemoryStats() LambdaMemoryStats
GetMemoryStats returns current memory usage statistics
func (*LambdaDB) IsModelRegistered ¶
IsModelRegistered checks if a model is already registered
func (*LambdaDB) OptimizeForColdStart ¶
func (ldb *LambdaDB) OptimizeForColdStart()
OptimizeForColdStart reduces Lambda cold start time
func (*LambdaDB) OptimizeForMemory ¶
func (ldb *LambdaDB) OptimizeForMemory()
OptimizeForMemory adjusts internal buffers based on available Lambda memory
func (*LambdaDB) PreRegisterModels ¶
PreRegisterModels registers models at init time to reduce cold starts
type LambdaMemoryStats ¶
type LambdaMemoryStats struct {
Alloc uint64 // Bytes allocated and still in use
TotalAlloc uint64 // Bytes allocated (even if freed)
Sys uint64 // Bytes obtained from system
NumGC uint32 // Number of GC cycles
AllocatedMB float64 // MB currently allocated
SystemMB float64 // MB obtained from system
LambdaMemoryMB int // Total Lambda memory allocation
MemoryPercent float64 // Percentage of Lambda memory used
}
LambdaMemoryStats contains memory usage information
type MultiAccountDB ¶
type MultiAccountDB struct {
// contains filtered or unexported fields
}
MultiAccountDB manages DynamoDB connections across multiple AWS accounts
func NewMultiAccount ¶
func NewMultiAccount(accounts map[string]AccountConfig) (*MultiAccountDB, error)
NewMultiAccount creates a multi-account aware DB
func (*MultiAccountDB) AddPartner ¶
func (mdb *MultiAccountDB) AddPartner(partnerID string, config AccountConfig)
AddPartner dynamically adds a new partner configuration
func (*MultiAccountDB) Close ¶
func (mdb *MultiAccountDB) Close() error
Close stops the refresh routine and cleans up
func (*MultiAccountDB) Partner ¶
func (mdb *MultiAccountDB) Partner(partnerID string) (*LambdaDB, error)
Partner returns a DB instance for the specified partner account
func (*MultiAccountDB) RemovePartner ¶
func (mdb *MultiAccountDB) RemovePartner(partnerID string)
RemovePartner removes a partner and clears its cached connection
func (*MultiAccountDB) WithContext ¶
func (mdb *MultiAccountDB) WithContext(ctx context.Context) *MultiAccountDB
WithContext returns a new MultiAccountDB with the given context
Directories
¶
| Path | Synopsis |
|---|---|
|
Package examples demonstrates DynamORM's embedded struct support
|
Package examples demonstrates DynamORM's embedded struct support |
|
initialization
command
Package main demonstrates proper DynamORM initialization patterns to avoid nil pointer dereference errors
|
Package main demonstrates proper DynamORM initialization patterns to avoid nil pointer dereference errors |
|
lambda
command
|
|
|
optimization
command
|
|
|
payment/lambda/process
command
|
|
|
payment/lambda/query
command
|
|
|
payment/lambda/reconcile
command
|
|
|
internal
|
|
|
pkg
|
|
|
core
Package core defines the core interfaces and types for DynamORM
|
Package core defines the core interfaces and types for DynamORM |
|
errors
Package errors defines error types and utilities for DynamORM
|
Package errors defines error types and utilities for DynamORM |
|
interfaces
Package interfaces provides abstractions for AWS SDK operations to enable mocking
|
Package interfaces provides abstractions for AWS SDK operations to enable mocking |
|
marshal
Package marshal provides optimized marshaling for DynamoDB
|
Package marshal provides optimized marshaling for DynamoDB |
|
mocks
Package mocks provides mock implementations for DynamORM interfaces and AWS SDK operations
|
Package mocks provides mock implementations for DynamORM interfaces and AWS SDK operations |
|
model
Package model provides model registration and metadata management for DynamORM
|
Package model provides model registration and metadata management for DynamORM |
|
query
Package query provides aggregate functionality for DynamoDB queries
|
Package query provides aggregate functionality for DynamoDB queries |
|
session
Package session provides AWS session management and DynamoDB client configuration
|
Package session provides AWS session management and DynamoDB client configuration |
|
testing
Package testing provides utilities for testing applications that use DynamORM.
|
Package testing provides utilities for testing applications that use DynamORM. |
|
transaction
Package transaction provides atomic transaction support for DynamORM
|
Package transaction provides atomic transaction support for DynamORM |
|
types
Package types provides type conversion between Go types and DynamoDB AttributeValues
|
Package types provides type conversion between Go types and DynamoDB AttributeValues |