Full-featured ORM library for Golang with associations, hooks, transactions, migrations, and developer-friendly chainable API
Overall
score
81%
Build an order processing function that uses transaction savepoints to handle failures gracefully.
Process an order containing multiple items within a single transaction. For each item, create a savepoint before attempting to add it. If adding an item fails (e.g., insufficient inventory), roll back to that savepoint and skip the item. Successfully added items should be preserved.
The function should:
Use the following models:
type Order struct {
ID uint
CustomerID uint
TotalAmount float64
Status string
CreatedAt time.Time
}
type LineItem struct {
ID uint
OrderID uint
ProductID uint
Quantity int
Price float64
}
type Inventory struct {
ID uint
ProductID uint
Quantity int
}@generates
Implement a function with the following signature:
package main
import (
"gorm.io/gorm"
)
// ProcessOrder processes an order with savepoint-based error recovery.
// Returns the created order ID and any error encountered.
// If no items can be added, returns an error and rolls back everything.
func ProcessOrder(db *gorm.DB, customerID uint, items []OrderItem) (uint, error)
// OrderItem represents a requested order item
type OrderItem struct {
ProductID uint
Quantity int
Price float64
}Provides ORM functionality and transaction management with savepoint support.
@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