converge.go 950 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package converge
  2. import (
  3. "context"
  4. "go-common/app/interface/main/app-card/model/card/operate"
  5. "go-common/app/interface/main/app-channel/conf"
  6. "go-common/library/database/sql"
  7. )
  8. const (
  9. _getSQL = "SELECT id,re_type,re_value,title,cover,content FROM content_card"
  10. )
  11. type Dao struct {
  12. db *sql.DB
  13. }
  14. func New(c *conf.Config) (d *Dao) {
  15. d = &Dao{
  16. db: sql.NewMySQL(c.MySQL.Manager),
  17. }
  18. return
  19. }
  20. func (d *Dao) Cards(c context.Context) (cm map[int64]*operate.Converge, err error) {
  21. rows, err := d.db.Query(c, _getSQL)
  22. if err != nil {
  23. return
  24. }
  25. defer rows.Close()
  26. cm = map[int64]*operate.Converge{}
  27. for rows.Next() {
  28. c := &operate.Converge{}
  29. if err = rows.Scan(&c.ID, &c.ReType, &c.ReValue, &c.Title, &c.Cover, &c.Content); err != nil {
  30. return
  31. }
  32. if c.Title == "" {
  33. continue
  34. }
  35. c.Change()
  36. cm[c.ID] = c
  37. }
  38. return
  39. }
  40. // Close close memcache resource.
  41. func (dao *Dao) Close() {
  42. if dao.db != nil {
  43. dao.db.Close()
  44. }
  45. }