dao.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package game
  2. import (
  3. "context"
  4. "go-common/app/interface/main/app-card/model/card/operate"
  5. "go-common/app/interface/main/app-feed/conf"
  6. "go-common/library/database/sql"
  7. )
  8. const (
  9. _getSQL = "SELECT `id`,`title`,`desc`,`icon`,`cover`,`url_type`,`url_value`,`btn_txt`,`re_type`,`re_value`,`number`,`double_cover` FROM download_card"
  10. )
  11. type Dao struct {
  12. db *sql.DB
  13. downloadGet *sql.Stmt
  14. }
  15. func New(c *conf.Config) (d *Dao) {
  16. d = &Dao{
  17. db: sql.NewMySQL(c.MySQL.Manager),
  18. }
  19. // prepare
  20. d.downloadGet = d.db.Prepared(_getSQL)
  21. return
  22. }
  23. func (d *Dao) DownLoad(c context.Context) (dm map[int64]*operate.Download, err error) {
  24. rows, err := d.downloadGet.Query(c)
  25. if err != nil {
  26. return
  27. }
  28. defer rows.Close()
  29. dm = map[int64]*operate.Download{}
  30. for rows.Next() {
  31. d := &operate.Download{}
  32. if err = rows.Scan(&d.ID, &d.Title, &d.Desc, &d.Icon, &d.Cover, &d.URLType, &d.URLValue, &d.BtnTxt, &d.ReType, &d.ReValue, &d.Number, &d.DoubleCover); err != nil {
  33. return
  34. }
  35. d.Change()
  36. dm[d.ID] = d
  37. }
  38. return
  39. }
  40. // Close close memcache resource.
  41. func (d *Dao) Close() {
  42. if d.db != nil {
  43. d.db.Close()
  44. }
  45. }