main.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package main
  2. import "confrontation-training/initialize"
  3. //func main() {
  4. // fmt.Println("===>hello world!")
  5. // db, err := gorm.Open(sqlite.Open("confrontation-training.db"), &gorm.Config{})
  6. // if err != nil {
  7. // fmt.Printf("初始化数据库异常:%s", err)
  8. // panic("failed to open database")
  9. // }
  10. // error := db.AutoMigrate(&Product{})
  11. // if error != nil {
  12. // fmt.Printf("AutoMigrate Product 数据库异常:%s", error)
  13. // panic("failed to open database")
  14. // }
  15. // create := db.Create(&Product{Title: "手机", Code: "001", Price: 10000})
  16. // if create.RowsAffected < 0 {
  17. // fmt.Println("插入有误--23 line")
  18. // }
  19. // db.Create(&Product{Title: "平板", Code: "002", Price: 110000})
  20. // // 读取内容
  21. // var product Product
  22. // db.First(&product, 1) // find product with integer primary key
  23. // fmt.Println(product)
  24. // db.First(&product, "code = ?", "001") // find product with code D42
  25. // fmt.Println(product)
  26. // // 更新操作:更新单个字段
  27. // db.Model(&product).Update("Price", 2000)
  28. // fmt.Println(product)
  29. // // 更新操作:更新多个字段
  30. // db.Model(&product).Updates(Product{Price: 2000, Code: "001"}) // non-zero fields
  31. // fmt.Println(product)
  32. // db.Model(&product).Updates(map[string]interface{}{"Price": 2000, "Code": "001"})
  33. // fmt.Println(product)
  34. //}
  35. //
  36. //type Product struct {
  37. // gorm.Model
  38. // Title string
  39. // Code string
  40. // Price uint
  41. //}
  42. func main() {
  43. initialize.Run()
  44. }