Full-featured ORM library for Golang with associations, hooks, transactions, migrations, and developer-friendly chainable API
Overall
score
81%
Build a flexible data reporting system that can query database records and generate custom reports in multiple output formats (JSON, CSV-style maps, and aggregated summaries).
The system should provide three reporting functions:
Each function should properly handle database row iteration, type conversion, and error handling.
Your implementation should work with the following models:
type User struct {
ID uint
Name string
Email string
Age int
Salary float64
}
type Stats struct {
TotalUsers int64
TotalSalary float64
AverageSalary float64
}@generates
package reporter
import "gorm.io/gorm"
// GetUserRecords retrieves all user records from the database and returns them as a slice of User structs.
// It should use database row scanning to populate the struct fields with proper type conversion.
func GetUserRecords(db *gorm.DB) ([]User, error)
// GetUserMap retrieves user records and returns them as a slice of maps.
// Each map contains column names as keys and their corresponding values.
// This is useful when you need dynamic access to fields.
func GetUserMap(db *gorm.DB) ([]map[string]interface{}, error)
// GetAggregatedStats queries aggregated statistics and returns them in a Stats struct.
// The query should calculate total user count, total salary sum, and average salary.
func GetAggregatedStats(db *gorm.DB) (*Stats, error)
type User struct {
ID uint
Name string
Email string
Age int
Salary float64
}
type Stats struct {
TotalUsers int64
TotalSalary float64
AverageSalary float64
}Provides ORM functionality including database querying and row scanning capabilities.
@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