dao.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/interface/main/feedback/conf"
  5. "go-common/library/database/sql"
  6. "net/http"
  7. )
  8. // Dao is feedback dao.
  9. type Dao struct {
  10. // conf
  11. c *conf.Config
  12. // db
  13. dbMs *sql.DB
  14. //db stmt
  15. // session
  16. selSsn *sql.Stmt
  17. selSsnByMid *sql.Stmt
  18. selTagID *sql.Stmt
  19. inSsn *sql.Stmt
  20. inSsnTag *sql.Stmt
  21. upSsn *sql.Stmt
  22. upSsnMtime *sql.Stmt
  23. upSsnSta *sql.Stmt
  24. selSSnID *sql.Stmt
  25. selSSnCntByMid *sql.Stmt
  26. // reply
  27. selReply *sql.Stmt
  28. selReplyByMid *sql.Stmt
  29. selReplyBySid *sql.Stmt
  30. inReply *sql.Stmt
  31. // tag
  32. selTagBySsnID *sql.Stmt
  33. // bfs
  34. bfsClient *http.Client
  35. }
  36. // New dao.
  37. func New(c *conf.Config) (d *Dao) {
  38. d = &Dao{
  39. c: c,
  40. dbMs: sql.NewMySQL(c.MySQL.Master),
  41. }
  42. // session
  43. d.selSsn = d.dbMs.Prepared(_selSsn)
  44. d.selSsnByMid = d.dbMs.Prepared(_selSsnByMid)
  45. d.inSsn = d.dbMs.Prepared(_inSsn)
  46. d.inSsnTag = d.dbMs.Prepared(_inSsnTag)
  47. d.upSsn = d.dbMs.Prepared(_upSsn)
  48. d.upSsnMtime = d.dbMs.Prepared(_upSsnMtime)
  49. d.upSsnSta = d.dbMs.Prepared(_upSsnState)
  50. d.selSSnID = d.dbMs.Prepared(_selSSnID)
  51. d.selSSnCntByMid = d.dbMs.Prepared(_selSSnCntByMid)
  52. // reply
  53. d.selReply = d.dbMs.Prepared(_selReply)
  54. d.selReplyByMid = d.dbMs.Prepared(_selReplyByMid)
  55. d.inReply = d.dbMs.Prepared(_inReply)
  56. d.selTagID = d.dbMs.Prepared(_selTagID)
  57. d.selReplyBySid = d.dbMs.Prepared(_selReplyBySid)
  58. d.selTagBySsnID = d.dbMs.Prepared(_selTagBySsnID)
  59. // init bfs http client
  60. d.bfsClient = http.DefaultClient
  61. return
  62. }
  63. // BeginTran begin tran.
  64. func (d *Dao) BeginTran(c context.Context) (tx *sql.Tx, err error) {
  65. tx, err = d.dbMs.Begin(c)
  66. return
  67. }