dynamorm

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

README

DynamORM Implementation for Streamer

This directory contains the DynamORM v1.0.9 implementation for the Streamer project's data storage layer.

Overview

DynamORM provides a cleaner, more maintainable interface for DynamoDB operations compared to direct AWS SDK usage. This implementation maintains backward compatibility while offering improved developer experience.

Files

  • models.go - DynamORM model definitions with PK/SK pattern
  • connection_store.go - ConnectionStore interface implementation using DynamORM
  • factory.go - Factory pattern for creating DynamORM stores
  • connection_store_test.go - Unit tests for the connection store

Key Features

1. PK/SK Pattern

DynamORM uses a composite key pattern for better query flexibility:

  • PK: CONN#<ConnectionID>
  • SK: METADATA

This allows for future extensibility and efficient queries.

2. Automatic Index Management

Indexes are defined using struct tags:

UserID   string `dynamorm:"user_id" dynamorm-index:"user-index,pk"`
TenantID string `dynamorm:"tenant_id" dynamorm-index:"tenant-index,pk"`
3. Simplified Operations

Compare the difference:

Before (AWS SDK):

input := &dynamodb.PutItemInput{
    TableName: aws.String(s.tableName),
    Item:      item,
}
_, err = s.client.PutItem(ctx, input)

After (DynamORM):

err := s.db.Model(dynamormConn).Create()

Usage

Enable DynamORM in Lambda Functions

Set the environment variable:

USE_DYNAMORM=true
Initialize in Code
// Create DynamORM factory
factory, err := dynamorm.NewStoreFactory(session.Config{
    Region: "us-east-1",
})

// Get connection store
connStore := factory.ConnectionStore()

Migration Status

  • ✅ Connection Store implemented
  • ⏳ Request Queue (TODO)
  • ⏳ Subscription Store (TODO)

Testing

Run tests with:

go test ./internal/store/dynamorm/...

Performance Considerations

  • DynamORM is optimized for Lambda cold starts
  • Connection pooling is handled automatically
  • Built-in retry logic with exponential backoff

Next Steps

  1. Implement RequestQueue and SubscriptionStore
  2. Add integration tests with DynamoDB Local
  3. Create migration scripts for production data
  4. Update deployment infrastructure

Documentation

Index

Constants

View Source
const (
	StatusPending    = models.StatusPending
	StatusProcessing = models.StatusProcessing
	StatusCompleted  = models.StatusCompleted
	StatusFailed     = models.StatusFailed
	StatusCancelled  = models.StatusCancelled
	StatusRetrying   = models.StatusRetrying
)

Status constants

Variables

This section is empty.

Functions

func NewConnectionStore

func NewConnectionStore(db core.DB) store.ConnectionStore

NewConnectionStore creates a new DynamORM-backed connection store

func NewRequestQueue

func NewRequestQueue(db core.DB) store.RequestQueue

NewRequestQueue creates a new DynamORM-backed request queue

Types

type AsyncRequest

type AsyncRequest = models.AsyncRequest

type Connection

type Connection = models.Connection

Type aliases for backward compatibility

type RequestStatus added in v1.0.4

type RequestStatus = models.RequestStatus

type StoreFactory

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

StoreFactory creates all the necessary stores using DynamORM

func NewStoreFactory

func NewStoreFactory(config session.Config) (*StoreFactory, error)

NewStoreFactory creates a new DynamORM store factory

func NewStoreFactoryFromClient

func NewStoreFactoryFromClient(client *dynamodb.Client, region string) (*StoreFactory, error)

NewStoreFactoryFromClient creates a new factory from an existing DynamoDB client This is useful for Lambda functions that already have a client configured

func (*StoreFactory) ConnectionStore

func (f *StoreFactory) ConnectionStore() store.ConnectionStore

ConnectionStore returns the connection store

func (*StoreFactory) DB

func (f *StoreFactory) DB() *dynamorm.DB

DB returns the underlying DynamORM database instance

func (*StoreFactory) EnsureTables

func (f *StoreFactory) EnsureTables(ctx context.Context) error

EnsureTables creates the required DynamoDB tables if they don't exist This should only be used in development/testing environments

func (*StoreFactory) RequestQueue

func (f *StoreFactory) RequestQueue() store.RequestQueue

RequestQueue returns the request queue

func (*StoreFactory) SubscriptionStore

func (f *StoreFactory) SubscriptionStore() store.SubscriptionStore

SubscriptionStore returns the subscription store

type Subscription

type Subscription = models.Subscription

Jump to

Keyboard shortcuts

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