Documentation
¶
Overview ¶
Package dynamostore provides a generic single-table DynamoDB store with tenant isolation via partition key prefix.
Table design:
PK: TENANT#{org_id}
SK: {FEATURE}#{id}
GSI1PK: {FEATURE} (feature-time-index)
GSI1SK: {created_at}
All features share one table; tenant isolation is enforced by scoping every read and write to the tenant's partition key.
Index ¶
- Variables
- type Item
- type QueryOpts
- type Store
- func (s *Store) Delete(ctx context.Context, feature, id string) error
- func (s *Store) Get(ctx context.Context, feature, id string, out any) error
- func (s *Store) List(ctx context.Context, feature string, out any) error
- func (s *Store) Put(ctx context.Context, feature, id string, item any) error
- func (s *Store) PutWithTTL(ctx context.Context, feature, id string, item any, ttl *int64) error
- func (s *Store) Query(ctx context.Context, feature string, opts QueryOpts) ([]Item, error)
- func (s *Store) TenantID() string
- func (s *Store) UpdateData(ctx context.Context, feature, id string, item any) error
- func (s *Store) WithTenant(tenantID string) *Store
Constants ¶
This section is empty.
Variables ¶
var ErrNoTenant = errors.New("dynamostore: tenant ID not set")
ErrNoTenant is returned when a tenant context has not been set.
var ErrNotFound = errors.New("dynamostore: not found")
ErrNotFound is returned when a requested item does not exist.
Functions ¶
This section is empty.
Types ¶
type Item ¶
type Item struct {
PK string `dynamodbav:"pk"`
SK string `dynamodbav:"sk"`
Feature string `dynamodbav:"feature"`
Data string `dynamodbav:"data"` // JSON-encoded payload
CreatedAt string `dynamodbav:"created_at"`
UpdatedAt string `dynamodbav:"updated_at"`
TTL *int64 `dynamodbav:"ttl,omitempty"`
}
Item is the raw DynamoDB item shape stored in the table.
type QueryOpts ¶
type QueryOpts struct {
Limit int32
StartTime *time.Time // inclusive lower bound on created_at
EndTime *time.Time // exclusive upper bound on created_at
UseGSI bool // if true, queries the feature-time-index GSI
}
QueryOpts controls the behaviour of Query.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a generic DynamoDB store scoped to a single table. Create one Store per application and use WithTenant to produce per-request copies bound to a specific tenant.
func (*Store) List ¶
List retrieves all items for a given feature within the current tenant and unmarshals them into out (which must be a pointer to a slice).
func (*Store) PutWithTTL ¶
PutWithTTL stores an item with an optional TTL (epoch seconds).
func (*Store) Query ¶
Query retrieves items for a feature, optionally using the GSI and time filters.
func (*Store) UpdateData ¶
UpdateData performs a Put that preserves the original created_at timestamp.
func (*Store) WithTenant ¶
WithTenant returns a shallow copy of the Store bound to the given tenant. This must be called per-request from auth middleware.