1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package main
- import "confrontation-training/initialize"
- //func main() {
- // fmt.Println("===>hello world!")
- // db, err := gorm.Open(sqlite.Open("confrontation-training.db"), &gorm.Config{})
- // if err != nil {
- // fmt.Printf("初始化数据库异常:%s", err)
- // panic("failed to open database")
- // }
- // error := db.AutoMigrate(&Product{})
- // if error != nil {
- // fmt.Printf("AutoMigrate Product 数据库异常:%s", error)
- // panic("failed to open database")
- // }
- // create := db.Create(&Product{Title: "手机", Code: "001", Price: 10000})
- // if create.RowsAffected < 0 {
- // fmt.Println("插入有误--23 line")
- // }
- // db.Create(&Product{Title: "平板", Code: "002", Price: 110000})
- // // 读取内容
- // var product Product
- // db.First(&product, 1) // find product with integer primary key
- // fmt.Println(product)
- // db.First(&product, "code = ?", "001") // find product with code D42
- // fmt.Println(product)
- // // 更新操作:更新单个字段
- // db.Model(&product).Update("Price", 2000)
- // fmt.Println(product)
- // // 更新操作:更新多个字段
- // db.Model(&product).Updates(Product{Price: 2000, Code: "001"}) // non-zero fields
- // fmt.Println(product)
- // db.Model(&product).Updates(map[string]interface{}{"Price": 2000, "Code": "001"})
- // fmt.Println(product)
- //}
- //
- //type Product struct {
- // gorm.Model
- // Title string
- // Code string
- // Price uint
- //}
- func main() {
- initialize.Run()
- }
|