Documentation
¶
Index ¶
- type AttributeDefinition
- type AttributeValue
- type Backup
- type ConditionExpr
- type DynamoDBService
- func (s *DynamoDBService) Actions() []service.Action
- func (s *DynamoDBService) Close()
- func (s *DynamoDBService) ExportState() (json.RawMessage, error)
- func (s *DynamoDBService) GetTableNames() []string
- func (s *DynamoDBService) HandleRequest(ctx *service.RequestContext) (*service.Response, error)
- func (s *DynamoDBService) HealthCheck() error
- func (s *DynamoDBService) ImportState(data json.RawMessage) error
- func (s *DynamoDBService) Name() string
- func (s *DynamoDBService) ResourceSchemas() []schema.ResourceSchema
- func (s *DynamoDBService) TableKeySchema(name string) (hashKey, rangeKey string, gsis map[string][2]string, ok bool)
- type Export
- type ExprCache
- type GSI
- type GlobalTable
- type IndexStore
- type Item
- type KeySchemaElement
- type LSI
- type Partition
- type ProvisionedThroughput
- type Shard
- type Stream
- type StreamDescription
- type StreamRecord
- type StreamSpecification
- type TTLSpecification
- type Table
- type TableStore
- func (s *TableStore) CreateTable(name string, keySchema []KeySchemaElement, attrDefs []AttributeDefinition, ...) (*Table, *service.AWSError)
- func (s *TableStore) DeleteItem(tableName string, key Item, condExpr ...string) *service.AWSError
- func (s *TableStore) DeleteResourcePolicy(resourceARN string) *service.AWSError
- func (s *TableStore) DeleteTable(name string) (*Table, *service.AWSError)
- func (s *TableStore) DescribeTable(name string) (*Table, *service.AWSError)
- func (s *TableStore) DescribeTimeToLive(tableName string) (*TTLSpecification, *service.AWSError)
- func (s *TableStore) GetItem(tableName string, key Item, projExpr string, exprNames map[string]string) (Item, *service.AWSError)
- func (s *TableStore) GetItemRaw(tableName string, key Item) ([]byte, *service.AWSError)
- func (s *TableStore) GetResourcePolicy(resourceARN string) (*Table, *service.AWSError)
- func (s *TableStore) GetStream(tableName string) (*Stream, *service.AWSError)
- func (s *TableStore) GetStreamByARN(arn string) *Stream
- func (s *TableStore) ListTables() []string
- func (s *TableStore) PutItem(tableName string, item Item, condExpr ...string) *service.AWSError
- func (s *TableStore) PutResourcePolicy(resourceARN, policy string) (*Table, *service.AWSError)
- func (s *TableStore) Query(tableName string, indexName string, keyCondExpr string, filterExpr string, ...) ([]Item, int, int, *service.AWSError)
- func (s *TableStore) Scan(tableName string, filterExpr string, projExpr string, ...) ([]Item, int, int, *service.AWSError)
- func (s *TableStore) TableKeySchema(name string) (hashKey, rangeKey string, gsis map[string][2]string, ok bool)
- func (s *TableStore) TransactGetItems(items []transactGetItem) ([]transactGetResponse, *service.AWSError)
- func (s *TableStore) TransactWriteItems(items []transactWriteItem) *service.AWSError
- func (s *TableStore) UpdateItem(tableName string, key Item, updateExpr string, exprNames map[string]string, ...) (Item, *service.AWSError)
- func (s *TableStore) UpdateTable(name, billingMode string, pt *ProvisionedThroughput, ...) (*Table, *service.AWSError)
- func (s *TableStore) UpdateTimeToLive(tableName string, spec *TTLSpecification) *service.AWSError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AttributeDefinition ¶
type AttributeDefinition struct {
AttributeName string `json:"AttributeName"`
AttributeType string `json:"AttributeType"` // S, N, or B
}
AttributeDefinition describes the type of a key attribute.
type AttributeValue ¶
AttributeValue is the DynamoDB typed value format. We store it as map[string]any matching the JSON wire format. e.g., {"S": "hello"}, {"N": "42"}, {"BOOL": true}
type ConditionExpr ¶
ConditionExpr is a compiled condition expression that can be evaluated against a DynamoDB item with zero string parsing in the hot path.
func CompileCondition ¶
func CompileCondition(expr string, names map[string]string, values map[string]AttributeValue) ConditionExpr
CompileCondition parses a condition expression string once, resolving #name placeholders from names and binding :value placeholders from values, returning a ConditionExpr whose Evaluate method does no string parsing.
type DynamoDBService ¶
type DynamoDBService struct {
// contains filtered or unexported fields
}
DynamoDBService is the cloudmock implementation of the AWS DynamoDB API.
func New ¶
func New(accountID, region string) *DynamoDBService
New returns a new DynamoDBService for the given AWS account ID and region.
func (*DynamoDBService) Actions ¶
func (s *DynamoDBService) Actions() []service.Action
Actions returns the list of DynamoDB API actions supported by this service.
func (*DynamoDBService) Close ¶
func (s *DynamoDBService) Close()
Close stops the background TTL reaper goroutine started in New. It is safe to call multiple times. Long-lived servers never need this, but in-process embeddings (e.g. the SDK) call it on teardown to avoid leaking the goroutine.
func (*DynamoDBService) ExportState ¶
func (s *DynamoDBService) ExportState() (json.RawMessage, error)
ExportState returns a JSON snapshot of all DynamoDB tables and items.
func (*DynamoDBService) GetTableNames ¶
func (s *DynamoDBService) GetTableNames() []string
GetTableNames returns all table names for topology queries.
func (*DynamoDBService) HandleRequest ¶
func (s *DynamoDBService) HandleRequest(ctx *service.RequestContext) (*service.Response, error)
HandleRequest routes an incoming DynamoDB request to the appropriate handler.
func (*DynamoDBService) HealthCheck ¶
func (s *DynamoDBService) HealthCheck() error
HealthCheck always returns nil (no external dependencies).
func (*DynamoDBService) ImportState ¶
func (s *DynamoDBService) ImportState(data json.RawMessage) error
ImportState restores DynamoDB state from a JSON snapshot.
func (*DynamoDBService) Name ¶
func (s *DynamoDBService) Name() string
Name returns the AWS service name used for routing.
func (*DynamoDBService) ResourceSchemas ¶
func (s *DynamoDBService) ResourceSchemas() []schema.ResourceSchema
ResourceSchemas returns the schema for DynamoDB table resources.
func (*DynamoDBService) TableKeySchema ¶
func (s *DynamoDBService) TableKeySchema(name string) (hashKey, rangeKey string, gsis map[string][2]string, ok bool)
TableKeySchema reports a running table's key schema and GSIs for IaC drift detection. See (*TableStore).TableKeySchema.
type ExprCache ¶
type ExprCache struct {
// contains filtered or unexported fields
}
ExprCache caches compiled condition expressions keyed by the raw expression string. It is safe for concurrent use.
func (*ExprCache) GetOrCompile ¶
func (c *ExprCache) GetOrCompile(expr string, names map[string]string, values map[string]AttributeValue) ConditionExpr
GetOrCompile returns a cached ConditionExpr or compiles and caches a new one. NOTE: The cache key is the raw expression string. Because literal values are bound at compile time, different values maps with the same expression string will return the first-compiled version. This is correct when the same expression+values pair is always used together (the common DynamoDB pattern).
type GSI ¶
type GSI struct {
IndexName string `json:"IndexName"`
KeySchema []KeySchemaElement `json:"KeySchema"`
Projection map[string]any `json:"Projection"`
ProvisionedThroughput *ProvisionedThroughput `json:"ProvisionedThroughput,omitempty"`
}
GSI represents a Global Secondary Index definition.
type GlobalTable ¶
type IndexStore ¶
type IndexStore struct {
// contains filtered or unexported fields
}
IndexStore mirrors the main table's partition structure for a secondary index.
type Item ¶
type Item = map[string]AttributeValue
Item is a DynamoDB item: a map of attribute names to typed values.
func ApplyProjection ¶
ApplyProjection applies a projection expression to an item.
func ApplyUpdate ¶
func ApplyUpdate(item Item, expr string, names map[string]string, values map[string]AttributeValue) Item
ApplyUpdate applies an update expression to an item, resolving names upfront. It delegates to the existing applySet/applyRemove logic.
type KeySchemaElement ¶
type KeySchemaElement struct {
AttributeName string `json:"AttributeName"`
KeyType string `json:"KeyType"` // HASH or RANGE
}
KeySchemaElement describes a single element of the table's key schema.
type LSI ¶
type LSI struct {
IndexName string `json:"IndexName"`
KeySchema []KeySchemaElement `json:"KeySchema"`
Projection map[string]any `json:"Projection"`
}
LSI represents a Local Secondary Index definition.
type Partition ¶
type Partition struct {
// contains filtered or unexported fields
}
Partition holds items sharing the same partition key value. For tables without a sort key, it holds at most one item. For tables with a sort key, items are stored in a B-tree sorted by sort key.
Frozen JSON cache: each item's GetItem JSON response is pre-serialized at write time and stored in frozenJSON. GetItemRaw returns the cached bytes with zero marshaling, eliminating the #1 CPU bottleneck (28% of CPU was spent in gojson.Marshal on reads).
type ProvisionedThroughput ¶
type ProvisionedThroughput struct {
ReadCapacityUnits int64 `json:"ReadCapacityUnits"`
WriteCapacityUnits int64 `json:"WriteCapacityUnits"`
}
ProvisionedThroughput holds the read/write capacity for a table.
type Shard ¶
type Shard struct {
ShardId string `json:"ShardId"`
}
Shard represents a shard in a DynamoDB Stream.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream holds the in-memory state for a table's DynamoDB Stream.
type StreamDescription ¶
type StreamDescription struct {
StreamARN string `json:"StreamArn"`
StreamLabel string `json:"StreamLabel"`
StreamStatus string `json:"StreamStatus"` // ENABLED, DISABLED
StreamViewType string `json:"StreamViewType"`
TableName string `json:"TableName"`
Shards []Shard `json:"Shards"`
}
StreamDescription holds metadata about a table's stream.
type StreamRecord ¶
type StreamRecord struct {
EventID string `json:"eventID"`
EventName string `json:"eventName"` // INSERT, MODIFY, REMOVE
NewImage Item `json:"NewImage,omitempty"`
OldImage Item `json:"OldImage,omitempty"`
SequenceNumber string `json:"SequenceNumber"`
StreamViewType string `json:"StreamViewType"`
}
StreamRecord represents a single change event in a DynamoDB Stream.
type StreamSpecification ¶
type StreamSpecification struct {
StreamEnabled bool `json:"StreamEnabled"`
StreamViewType string `json:"StreamViewType,omitempty"` // KEYS_ONLY, NEW_IMAGE, OLD_IMAGE, NEW_AND_OLD_IMAGES
}
StreamSpecification describes whether streams are enabled and the view type.
type TTLSpecification ¶
type TTLSpecification struct {
AttributeName string `json:"AttributeName"`
Enabled bool `json:"Enabled"`
}
TTLSpecification describes the TTL configuration for a table.
type Table ¶
type Table struct {
Name string
KeySchema []KeySchemaElement
AttributeDefinitions []AttributeDefinition
Status string // ACTIVE, CREATING, DELETING
CreationDateTime float64 // Unix timestamp
BillingMode string
ProvisionedThroughput *ProvisionedThroughput
GSIs []GSI
LSIs []LSI
Stream *Stream // nil if streams not enabled
TTL *TTLSpecification // nil if TTL not configured
// ResourcePolicy holds the table's resource-based policy JSON (set via PutResourcePolicy).
ResourcePolicy string
ResourcePolicyRevisionID string
// Tags holds the table's resource tags (key/value pairs).
Tags map[string]string
// contains filtered or unexported fields
}
Table is the in-memory representation of a DynamoDB table.
type TableStore ¶
type TableStore struct {
// contains filtered or unexported fields
}
TableStore manages all DynamoDB tables in memory.
func NewTableStore ¶
func NewTableStore(accountID, region string) *TableStore
NewTableStore creates an empty TableStore.
func (*TableStore) CreateTable ¶
func (s *TableStore) CreateTable(name string, keySchema []KeySchemaElement, attrDefs []AttributeDefinition, billingMode string, pt *ProvisionedThroughput, gsis []GSI, lsis []LSI, streamSpec *StreamSpecification) (*Table, *service.AWSError)
CreateTable creates a new table. Returns ResourceInUseException if it already exists.
func (*TableStore) DeleteItem ¶
DeleteItem removes an item by key from the specified table.
func (*TableStore) DeleteResourcePolicy ¶
func (s *TableStore) DeleteResourcePolicy(resourceARN string) *service.AWSError
DeleteResourcePolicy removes the resource policy from a table.
func (*TableStore) DeleteTable ¶
func (s *TableStore) DeleteTable(name string) (*Table, *service.AWSError)
DeleteTable removes a table. Returns ResourceNotFoundException if not found.
func (*TableStore) DescribeTable ¶
func (s *TableStore) DescribeTable(name string) (*Table, *service.AWSError)
DescribeTable returns table metadata. Returns ResourceNotFoundException if not found.
func (*TableStore) DescribeTimeToLive ¶
func (s *TableStore) DescribeTimeToLive(tableName string) (*TTLSpecification, *service.AWSError)
DescribeTimeToLive returns the TTL configuration for a table.
func (*TableStore) GetItem ¶
func (s *TableStore) GetItem(tableName string, key Item, projExpr string, exprNames map[string]string) (Item, *service.AWSError)
GetItem retrieves an item by key from the specified table.
func (*TableStore) GetItemRaw ¶
GetItemRaw retrieves an item and marshals it to JSON while holding the partition lock, eliminating the need for copyItem. Returns nil for not found.
func (*TableStore) GetResourcePolicy ¶
func (s *TableStore) GetResourcePolicy(resourceARN string) (*Table, *service.AWSError)
GetResourcePolicy returns the resource policy for a table.
func (*TableStore) GetStream ¶
func (s *TableStore) GetStream(tableName string) (*Stream, *service.AWSError)
GetStream returns the stream for a table, or nil if streams are not enabled.
func (*TableStore) GetStreamByARN ¶
func (s *TableStore) GetStreamByARN(arn string) *Stream
GetStreamByARN returns the stream matching the given ARN, or nil.
func (*TableStore) ListTables ¶
func (s *TableStore) ListTables() []string
ListTables returns the names of all tables.
func (*TableStore) PutResourcePolicy ¶
func (s *TableStore) PutResourcePolicy(resourceARN, policy string) (*Table, *service.AWSError)
PutResourcePolicy sets a resource-based policy on a table.
func (*TableStore) Query ¶
func (s *TableStore) Query(tableName string, indexName string, keyCondExpr string, filterExpr string, projExpr string, exprNames map[string]string, exprValues map[string]AttributeValue, scanForward *bool, limit int) ([]Item, int, int, *service.AWSError)
Query finds items matching a key condition expression, applies filter and projection.
func (*TableStore) Scan ¶
func (s *TableStore) Scan(tableName string, filterExpr string, projExpr string, exprNames map[string]string, exprValues map[string]AttributeValue, limit int) ([]Item, int, int, *service.AWSError)
Scan iterates all items, applies filter and projection.
func (*TableStore) TableKeySchema ¶
func (s *TableStore) TableKeySchema(name string) (hashKey, rangeKey string, gsis map[string][2]string, ok bool)
TableKeySchema reports a running table's hash key, optional range key ("" when the table has no sort key), and a map of GSI name → [hashKey, rangeKey], for IaC drift detection. ok is false if no table with the given name exists.
func (*TableStore) TransactGetItems ¶
func (s *TableStore) TransactGetItems(items []transactGetItem) ([]transactGetResponse, *service.AWSError)
TransactGetItems retrieves items transactionally.
func (*TableStore) TransactWriteItems ¶
func (s *TableStore) TransactWriteItems(items []transactWriteItem) *service.AWSError
TransactWriteItems executes a transactional write across multiple tables.
func (*TableStore) UpdateItem ¶
func (s *TableStore) UpdateItem(tableName string, key Item, updateExpr string, exprNames map[string]string, exprValues map[string]AttributeValue, returnValues string) (Item, *service.AWSError)
UpdateItem updates an item using an UpdateExpression. Creates the item if it doesn't exist.
func (*TableStore) UpdateTable ¶
func (s *TableStore) UpdateTable(name, billingMode string, pt *ProvisionedThroughput, attrDefs []AttributeDefinition) (*Table, *service.AWSError)
UpdateTable updates mutable table properties: BillingMode, ProvisionedThroughput, AttributeDefinitions (for new GSIs), and GlobalSecondaryIndexUpdates. All fields are optional; only non-zero values are applied. The table stays ACTIVE throughout (no async state transition in CloudMock).
func (*TableStore) UpdateTimeToLive ¶
func (s *TableStore) UpdateTimeToLive(tableName string, spec *TTLSpecification) *service.AWSError
UpdateTimeToLive sets or disables TTL for a table.