tessl install tessl/golang-gorm-io--gorm@1.31.0Full-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%
Build a book management system that tracks books and their authors using a relational database structure.
Implement a system with two models: Book and Author. Each book belongs to an author, and an author can have multiple books.
Create two models with the following specifications:
Author Model:
Book Model:
Implement the following operations in a main.go file:
Database Setup: Initialize an in-memory SQLite database and run auto-migration for both models.
Create Data: Insert sample data into the database:
Query with Preloading: Retrieve a book by its title and preload its associated author information. Print the book title and the author's name.
Query Books by Author: Find all books written by a specific author. Print each book's title.
Update Author: Change the country of an author and verify the update was successful.
@generates
package main
import (
"gorm.io/gorm"
)
// Author represents an author in the system
type Author struct {
ID uint
Name string
Country string
CreatedAt time.Time
UpdatedAt time.Time
}
// Book represents a book in the system
type Book struct {
ID uint
Title string
ISBN string
AuthorID uint
Author Author
CreatedAt time.Time
UpdatedAt time.Time
}
func main() {
// Implementation here
}Provides ORM functionality for database operations.
Provides SQLite database driver for GORM.