CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/golang-gorm-io--gorm

tessl install tessl/golang-gorm-io--gorm@1.31.0

Full-featured ORM library for Golang with associations, hooks, transactions, migrations, and developer-friendly chainable API

Agent Success

Agent success rate when using this tile

81%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.13x

Baseline

Agent success rate without this tile

72%

task.mdevals/scenario-3/

Custom Report Generator

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).

Requirements

The system should provide three reporting functions:

  1. GetUserRecords: Query user records from the database and scan them into a slice of User structs
  2. GetUserMap: Query user records and scan them into a map where column names are keys (useful for dynamic field access)
  3. GetAggregatedStats: Query aggregated statistics (count, sum, average) and scan the results into a custom Stats struct

Each function should properly handle database row iteration, type conversion, and error handling.

Data Models

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
}

Test Cases

  • Querying multiple user records and scanning into a slice of structs returns correct data with proper type conversion @test
  • Querying user records and scanning into maps produces column-to-value mappings @test
  • Querying aggregated statistics and scanning into a custom struct correctly converts aggregate values @test
  • Handling empty result sets returns empty collections without errors @test

Implementation

@generates

API

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
}

Dependencies { .dependencies }

GORM { .dependency }

Provides ORM functionality including database querying and row scanning capabilities.

@satisfied-by

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
golangpkg:golang/gorm.io/gorm@v1.31.1
tile.json