Documentation
¶
Overview ¶
Package dynorm provides a type-safe DynamoDB abstraction layer for Go.
Basic usage:
import "github.com/go-gamma/dynorm"
type User struct {
dynorm.Entity
Email string `dynorm:"gsi:ByEmail"`
Name string
}
type UserRepository struct {
dynorm.Repository[User]
}
var UserRepo = &UserRepository{}
For local development with DynamoDB Local:
dynorm.SetEndpoint("http://localhost:8000")
For more examples, see the examples/ directory.
Index ¶
- Constants
- Variables
- func GetEndpoint() string
- func GetTablePrefix() string
- func Reset()
- func SetClient(client *dynamodb.Client)
- func SetContext(ctx context.Context)
- func SetEndpoint(endpoint string)
- func SetTablePrefix(prefix string)
- type BelongsTo
- type BelongsToMany
- type Collection
- type Created
- type Creating
- type Cursor
- type Deleted
- type Deleting
- type Entity
- type ForceDeleted
- type ForceDeleting
- type HasMany
- type HasManyThrough
- type HasOne
- type MorphMany
- type MorphOne
- type MorphToMany
- type MorphedByMany
- type PivotData
- type Query
- type RelationshipState
- type Replicated
- type Replicating
- type Repository
- type RepositoryInterface
- type RepositoryTransaction
- type Restored
- type Restoring
- type Retrieved
- type Retrieving
- type Saved
- type Saving
- type Trashed
- type Trashing
- type UpdateBuilder
- type Updated
- type Updating
- type Versioned
Constants ¶
const ( // MaxBatchGetItems is the maximum items per BatchGetItem request. MaxBatchGetItems = impl.MaxBatchGetItems // MaxBatchWriteItems is the maximum items per BatchWriteItem request. MaxBatchWriteItems = impl.MaxBatchWriteItems // MaxTransactionItems is the maximum items per transaction. MaxTransactionItems = impl.MaxTransactionItems )
Batch operation limits
Variables ¶
var ( // ErrRepositoryNotFound is returned when a relationship's repository cannot be found. ErrRepositoryNotFound = impl.ErrRepositoryNotFound // ErrPivotNotInitialized is returned when the pivot repository is not available. ErrPivotNotInitialized = impl.ErrPivotNotInitialized // ErrParentNotSaved is returned when trying to use a relationship before the parent is saved. ErrParentNotSaved = impl.ErrParentNotSaved // ErrEntityNil is returned when a nil entity is passed to a relationship method. ErrEntityNil = impl.ErrEntityNil // ErrEntityNotSaved is returned when trying to attach/relate an unsaved entity. ErrEntityNotSaved = impl.ErrEntityNotSaved // ErrForeignKeyNotSet is returned when a foreign key field cannot be set. ErrForeignKeyNotSet = impl.ErrForeignKeyNotSet // ErrMethodNotFound is returned when a required method doesn't exist on a repository. ErrMethodNotFound = impl.ErrMethodNotFound // ErrNoRepository is returned when a collection operation requires a repository // but the collection was created without one. ErrNoRepository = impl.ErrNoRepository )
Relationship errors provide consistent error messages across all relationship types.
Functions ¶
func GetEndpoint ¶
func GetEndpoint() string
GetEndpoint returns the current custom DynamoDB endpoint. Returns an empty string if using the default AWS endpoint.
func SetClient ¶
SetClient sets a custom DynamoDB client. This is primarily useful for testing with a mock client.
func SetContext ¶
SetContext sets the global context for all operations. This is typically called at the start of a Lambda handler.
func SetEndpoint ¶
func SetEndpoint(endpoint string)
SetEndpoint sets a custom DynamoDB endpoint URL. This is primarily used for DynamoDB Local or other local development setups. This must be called BEFORE any repository operations, or after Reset().
Example:
dynorm.SetEndpoint("http://localhost:8000")
func SetTablePrefix ¶
func SetTablePrefix(prefix string)
SetTablePrefix sets the table prefix for all tables. Normally, use the DYNORM_TABLE_PREFIX environment variable instead.
Types ¶
type BelongsTo ¶
type BelongsTo[R impl.RepositoryInterface] = impl.BelongsTo[R]
BelongsTo represents the inverse of a HasOne/HasMany relationship where the foreign key is on this entity (e.g., Post belongs to User via Post.UserID).
type BelongsToMany ¶
type BelongsToMany[R impl.RepositoryInterface] = impl.BelongsToMany[R]
BelongsToMany represents a many-to-many relationship via a pivot table (e.g., User belongs to many Roles, Role belongs to many Users).
type Collection ¶
type Collection[T any] = impl.Collection[T]
Collection wraps a slice of entities with utility methods for enumeration, filtering, sorting, and bulk operations.
type Entity ¶
Entity is the base struct that all entities should embed. It provides automatic ID generation (ULID), and timestamp management.
type ForceDeleted ¶
type ForceDeleted = impl.ForceDeleted
ForceDeleted is called after an entity is permanently deleted.
type ForceDeleting ¶
type ForceDeleting = impl.ForceDeleting
ForceDeleting is called before an entity is permanently deleted.
type HasMany ¶
type HasMany[R impl.RepositoryInterface] = impl.HasMany[R]
HasMany represents a one-to-many relationship where the foreign key is on the related entities (e.g., User has many Posts via Post.UserID).
type HasManyThrough ¶
type HasManyThrough[R impl.RepositoryInterface, Through impl.RepositoryInterface] = impl.HasManyThrough[R, Through]
HasManyThrough represents a has-many-through relationship (e.g., Country has many Posts through Users).
type HasOne ¶
type HasOne[R impl.RepositoryInterface] = impl.HasOne[R]
HasOne represents a one-to-one relationship where the foreign key is on the related entity (e.g., User has one Profile via Profile.UserID).
type MorphMany ¶
type MorphMany[R impl.RepositoryInterface] = impl.MorphMany[R]
MorphMany represents a polymorphic one-to-many relationship.
type MorphOne ¶
type MorphOne[R impl.RepositoryInterface] = impl.MorphOne[R]
MorphOne represents a polymorphic one-to-one relationship.
type MorphToMany ¶
type MorphToMany[R impl.RepositoryInterface] = impl.MorphToMany[R]
MorphToMany represents a polymorphic many-to-many relationship.
type MorphedByMany ¶
type MorphedByMany[R impl.RepositoryInterface] = impl.MorphedByMany[R]
MorphedByMany represents the inverse of a polymorphic many-to-many relationship.
type RelationshipState ¶
type RelationshipState = impl.RelationshipState
RelationshipState holds common state for all relationship types.
type Replicated ¶
type Replicated = impl.Replicated
Replicated is called after an entity is replicated.
type Replicating ¶
type Replicating = impl.Replicating
Replicating is called before an entity is replicated (copied).
type Repository ¶
type Repository[T any] = impl.Repository[T]
Repository is the base repository struct that should be embedded. It provides CRUD operations and query building for entities of type T.
type RepositoryInterface ¶
type RepositoryInterface = impl.RepositoryInterface
RepositoryInterface is the interface that all repositories must implement. This is needed for relationship type parameters.
type RepositoryTransaction ¶
type RepositoryTransaction[T any] = impl.RepositoryTransaction[T]
RepositoryTransaction provides type-safe transaction operations for a repository.
type Retrieving ¶
type Retrieving = impl.Retrieving
Retrieving is called before an entity is loaded from the database.
type UpdateBuilder ¶
type UpdateBuilder = impl.UpdateBuilder
UpdateBuilder provides a fluent interface for building update operations.
func Update ¶
func Update() *UpdateBuilder
Update creates a new UpdateBuilder for fluent update operations.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic
command
Example basic demonstrates basic dynorm usage with a simple User entity.
|
Example basic demonstrates basic dynorm usage with a simple User entity. |
|
caching
command
Example caching demonstrates dynorm's query caching feature.
|
Example caching demonstrates dynorm's query caching feature. |
|
lambda
command
Example lambda demonstrates dynorm usage in AWS Lambda functions.
|
Example lambda demonstrates dynorm usage in AWS Lambda functions. |
|
relationships
command
Example relationships demonstrates dynorm relationship patterns.
|
Example relationships demonstrates dynorm relationship patterns. |
|
internal
|
|
|
batch
Package batch provides internal batch operation utilities for dynorm.
|
Package batch provides internal batch operation utilities for dynorm. |
|
collection
Package collection provides internal collection utilities for dynorm.
|
Package collection provides internal collection utilities for dynorm. |
|
events
Package events provides internal event dispatching for dynorm.
|
Package events provides internal event dispatching for dynorm. |
|
marshal
Package marshal provides internal marshaling utilities for dynorm.
|
Package marshal provides internal marshaling utilities for dynorm. |
|
pagination
Package pagination provides internal pagination utilities for dynorm.
|
Package pagination provides internal pagination utilities for dynorm. |
|
pivot
Package pivot provides internal pivot table helpers for dynorm.
|
Package pivot provides internal pivot table helpers for dynorm. |
|
pluralize
Package pluralize provides internal pluralization utilities for dynorm.
|
Package pluralize provides internal pluralization utilities for dynorm. |
|
query
Package query provides internal query utilities for dynorm.
|
Package query provides internal query utilities for dynorm. |
|
reflect
Package reflect provides internal reflection utilities for dynorm.
|
Package reflect provides internal reflection utilities for dynorm. |
|
registry
Package registry provides internal repository registry for dynorm.
|
Package registry provides internal repository registry for dynorm. |
|
relationship
Package relationship provides internal relationship helpers for dynorm.
|
Package relationship provides internal relationship helpers for dynorm. |
|
transaction
Package transaction provides internal transaction utilities for dynorm.
|
Package transaction provides internal transaction utilities for dynorm. |
|
pkg
|
|
|
cache
Package cache provides a pluggable caching layer for dynorm queries.
|
Package cache provides a pluggable caching layer for dynorm queries. |
|
dynorm
Package dynorm provides a type-safe DynamoDB abstraction layer for Go.
|
Package dynorm provides a type-safe DynamoDB abstraction layer for Go. |
|
dynormtest
Package dynormtest provides mock implementations for unit testing.
|
Package dynormtest provides mock implementations for unit testing. |
|
dynormtest/local
Package local provides utilities for testing with DynamoDB Local.
|
Package local provides utilities for testing with DynamoDB Local. |
|
errors
Package errors provides custom error types for dynorm.
|
Package errors provides custom error types for dynorm. |
|
relationship
Package relationship provides patterns for modeling entity relationships in DynamoDB.
|
Package relationship provides patterns for modeling entity relationships in DynamoDB. |
|
schema
Package schema handles parsing of dynorm struct tags and schema extraction.
|
Package schema handles parsing of dynorm struct tags and schema extraction. |
|
validation
Package validation provides field validation for dynorm entities.
|
Package validation provides field validation for dynorm entities. |