SinopharmService.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package services
  2. import (
  3. "fmt"
  4. ywtlog "hello/models/ywtlog"
  5. "github.com/astaxie/beego/orm"
  6. )
  7. // list 查询
  8. func QuerySinopharmList() {
  9. var j, i int64
  10. orm.Debug = true
  11. o := orm.NewOrm()
  12. _ = o.Using("ywt_log_db") // 默认使用 ywt_log_db,你可以指定为其他数据库
  13. var users []ywtlog.SinopharmApi
  14. num, err := o.Raw("SELECT * FROM sinopharm_api WHERE http_status = ? limit 10", 200).QueryRows(&users)
  15. // fmt.Println(users)
  16. if err == nil {
  17. fmt.Println("user nums: ", num)
  18. }
  19. i = num
  20. for j = 0; j < i; j++ {
  21. fmt.Printf("Element[%d] = %d, %s, %s\n", j, users[j].Id, users[j].Path, users[j].CreateTime)
  22. }
  23. }
  24. // 根据ID查找一个记录
  25. func FindSinopharmById(id int) ywtlog.SinopharmApi {
  26. orm.Debug = true
  27. o := orm.NewOrm()
  28. _ = o.Using("ywt_log_db") // 默认使用 ywt_log_db,你可以指定为其他数据库
  29. SinopharmApi := ywtlog.SinopharmApi{Id: int16(id)}
  30. err := o.Read(&SinopharmApi)
  31. if err == orm.ErrNoRows {
  32. fmt.Println("查询不到")
  33. } else if err == orm.ErrMissPK {
  34. fmt.Println("找不到主键")
  35. } else {
  36. fmt.Println(SinopharmApi.Id, SinopharmApi.Path)
  37. }
  38. return SinopharmApi
  39. }