dao.go 889 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package tab
  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. _followSQL = "SELECT `id`,`type`,`long_title`,`content` FROM `card_follow` WHERE `deleted`=0"
  10. )
  11. type Dao struct {
  12. db *sql.DB
  13. followGet *sql.Stmt
  14. }
  15. func New(c *conf.Config) (d *Dao) {
  16. d = &Dao{
  17. db: sql.NewMySQL(c.MySQL.Show),
  18. }
  19. // prepare
  20. d.followGet = d.db.Prepared(_followSQL)
  21. return
  22. }
  23. func (d *Dao) Follow(c context.Context) (cm map[int64]*operate.Follow, err error) {
  24. var rows *sql.Rows
  25. if rows, err = d.followGet.Query(c); err != nil {
  26. return
  27. }
  28. defer rows.Close()
  29. cm = make(map[int64]*operate.Follow)
  30. for rows.Next() {
  31. c := &operate.Follow{}
  32. if err = rows.Scan(&c.ID, &c.Type, &c.Title, &c.Content); err != nil {
  33. return
  34. }
  35. c.Change()
  36. cm[c.ID] = c
  37. }
  38. return
  39. }