dao.go 933 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package card
  2. import (
  3. "context"
  4. "go-common/app/interface/main/app-card/model/card/operate"
  5. "go-common/app/interface/main/app-intl/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. // Dao is dao
  12. type Dao struct {
  13. db *sql.DB
  14. followGet *sql.Stmt
  15. }
  16. // New new dao
  17. func New(c *conf.Config) (d *Dao) {
  18. d = &Dao{
  19. db: sql.NewMySQL(c.MySQL.Show),
  20. }
  21. // prepare
  22. d.followGet = d.db.Prepared(_followSQL)
  23. return
  24. }
  25. // Follow is.
  26. func (d *Dao) Follow(c context.Context) (cm map[int64]*operate.Follow, err error) {
  27. var rows *sql.Rows
  28. if rows, err = d.followGet.Query(c); err != nil {
  29. return
  30. }
  31. defer rows.Close()
  32. cm = make(map[int64]*operate.Follow)
  33. for rows.Next() {
  34. c := &operate.Follow{}
  35. if err = rows.Scan(&c.ID, &c.Type, &c.Title, &c.Content); err != nil {
  36. return
  37. }
  38. c.Change()
  39. cm[c.ID] = c
  40. }
  41. return
  42. }