Full-featured ORM library for Golang with associations, hooks, transactions, migrations, and developer-friendly chainable API
Overall
score
81%
Build a database audit logging system that tracks changes to user records. The system should log all create and update operations with timestamps, operation types, and the affected data.
AuditLog model with fields: ID, EntityType, EntityID, Operation (create/update), ChangedData (JSON), and Timestamp@generates
package main
import (
"time"
"gorm.io/gorm"
)
// User represents a user in the system
type User struct {
ID uint `gorm:"primarykey"`
Name string
Email string
UpdatedAt time.Time
CreatedAt time.Time
}
// AuditLog stores audit trail information
type AuditLog struct {
ID uint `gorm:"primarykey"`
EntityType string
EntityID uint
Operation string
ChangedData string // JSON string
Timestamp time.Time
}
// SetupAuditCallbacks configures the database to automatically create audit logs
func SetupAuditCallbacks(db *gorm.DB) error
// GetAuditLogs retrieves all audit logs for a specific user
func GetAuditLogs(db *gorm.DB, userID uint) ([]AuditLog, error)Provides ORM functionality for database operations and callback management.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/golang-gorm-io--gormdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10