12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package services
- import (
- "fmt"
- ywtlog "hello/models/ywtlog"
- "github.com/astaxie/beego/orm"
- )
- // list 查询
- func QuerySinopharmList() {
- var j, i int64
- orm.Debug = true
- o := orm.NewOrm()
- _ = o.Using("ywt_log_db") // 默认使用 ywt_log_db,你可以指定为其他数据库
- var users []ywtlog.SinopharmApi
- num, err := o.Raw("SELECT * FROM sinopharm_api WHERE http_status = ? limit 10", 200).QueryRows(&users)
- // fmt.Println(users)
- if err == nil {
- fmt.Println("user nums: ", num)
- }
- i = num
- for j = 0; j < i; j++ {
- fmt.Printf("Element[%d] = %d, %s, %s\n", j, users[j].Id, users[j].Path, users[j].CreateTime)
- }
- }
- // 根据ID查找一个记录
- func FindSinopharmById(id int) ywtlog.SinopharmApi {
- orm.Debug = true
- o := orm.NewOrm()
- _ = o.Using("ywt_log_db") // 默认使用 ywt_log_db,你可以指定为其他数据库
- SinopharmApi := ywtlog.SinopharmApi{Id: int16(id)}
- err := o.Read(&SinopharmApi)
- if err == orm.ErrNoRows {
- fmt.Println("查询不到")
- } else if err == orm.ErrMissPK {
- fmt.Println("找不到主键")
- } else {
- fmt.Println(SinopharmApi.Id, SinopharmApi.Path)
- }
- return SinopharmApi
- }
|