Dynorm¶
Type-safe DynamoDB abstraction layer for Go
Laravel Eloquent-inspired fluent API for AWS Lambda and Go applications
Dynorm is a powerful, type-safe DynamoDB abstraction layer for Go that brings the elegance of Laravel's Eloquent ORM to the AWS ecosystem. Built specifically for AWS Lambda and serverless applications, it provides automatic ID generation, timestamps, snake_case marshalling, and a fluent query API.
Features¶
-
Zero Configuration
Automatic table name resolution, lazy client initialization, and context capture. Just define your entities and start coding.
-
Type Safety
Full generic support with
Repository[T]andCollection[T]. Compile-time type checking for all operations. -
ULID-Based IDs
Lexicographically sortable, time-ordered unique identifiers. No need to manage ID generation.
-
Relationships
HasOne, HasMany, BelongsTo, BelongsToMany, and polymorphic morphing relationships.
-
Fluent Queries
Chainable query builder with automatic GSI selection, filtering, sorting, and pagination.
-
Soft Deletes
Built-in soft delete support with automatic query filtering and restore capabilities.
-
Optimistic Locking
Version-based concurrency control prevents lost updates in concurrent environments.
-
Query Caching
Pluggable cache interface with in-memory default reduces DynamoDB costs and latency.
-
Schema Export
Generate CloudFormation and Terraform from your entity definitions for IaC workflows.
Quick Example¶
package main
import "github.com/go-gamma/dynorm"
// Define your entity
type User struct {
dynorm.Entity // Provides: ID, CreatedAt, UpdatedAt, DeletedAt
Email string `dynorm:"gsi:ByEmail"`
Username string
FirstName string
LastName string
}
// Define your repository
type UserRepository struct {
dynorm.Repository[User]
}
var UserRepo = &UserRepository{}
func main() {
// Create a new user
user := &User{
Email: "john@example.com",
Username: "johndoe",
FirstName: "John",
LastName: "Doe",
}
// Save - ID and timestamps are set automatically
UserRepo.Save(user)
// Query with fluent API
activeUsers, _ := UserRepo.
Where("Status", "=", "active").
OrderBy("CreatedAt", "desc").
Limit(10).
GetAll()
}
Installation¶
Requirements¶
- Go 1.24 or later
- AWS SDK for Go v2
- DynamoDB table(s) with appropriate schema
Next Steps¶
-
Getting Started
Learn the basics and get up and running in minutes.
-
Core Concepts
Understand entities, repositories, and collections.
-
Querying
Master the fluent query builder and pagination.
-
Advanced
Explore relationships, transactions, and batch operations.