special.go 999 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package special
  2. import (
  3. "context"
  4. "go-common/app/interface/main/app-view/conf"
  5. "go-common/app/interface/main/app-view/model/special"
  6. "go-common/library/database/sql"
  7. )
  8. const (
  9. _getSQL = "SELECT `id`,`title`,`desc`,`cover`,`re_type`,`re_value`,`corner` FROM special_card"
  10. )
  11. type Dao struct {
  12. db *sql.DB
  13. specialGet *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.specialGet = d.db.Prepared(_getSQL)
  21. return
  22. }
  23. func (d *Dao) Card(c context.Context) (scm map[int64]*special.Card, err error) {
  24. rows, err := d.specialGet.Query(c)
  25. if err != nil {
  26. return
  27. }
  28. defer rows.Close()
  29. scm = map[int64]*special.Card{}
  30. for rows.Next() {
  31. sc := &special.Card{}
  32. if err = rows.Scan(&sc.ID, &sc.Title, &sc.Desc, &sc.Cover, &sc.ReType, &sc.ReValue, &sc.Badge); err != nil {
  33. return
  34. }
  35. scm[sc.ID] = sc
  36. }
  37. return scm, err
  38. }
  39. // Close close memcache resource.
  40. func (d *Dao) Close() {
  41. if d.db != nil {
  42. d.db.Close()
  43. }
  44. }