47 lines
805 B
Go
47 lines
805 B
Go
package db
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/jinzhu/gorm"
|
|
)
|
|
|
|
// Race model describe race.
|
|
type Race struct {
|
|
gorm.Model
|
|
Season string
|
|
Round string
|
|
RaceName string
|
|
Circuit Circuit
|
|
Date time.Time
|
|
}
|
|
|
|
// Circuit model describe a circuit.
|
|
type Circuit struct {
|
|
gorm.Model
|
|
Name string
|
|
Location string
|
|
}
|
|
|
|
// Races contains the list of all races for a season.
|
|
type Races struct {
|
|
gorm.Model
|
|
Season string
|
|
Races []Race
|
|
}
|
|
|
|
// GORM DOC
|
|
|
|
// // Create
|
|
// db.Create(&Product{Code: "L1212", Price: 1000})
|
|
|
|
// // Read
|
|
// var product Product
|
|
// db.First(&product, 1) // find product with id 1
|
|
// db.First(&product, "code = ?", "L1212") // find product with code l1212
|
|
|
|
// // Update - update product's price to 2000
|
|
// db.Model(&product).Update("Price", 2000)
|
|
|
|
// Delete - delete p
|