广告平台(总站长使用)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

medium_implement.go 1.2 KiB

4 months ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package implement
  2. import (
  3. "applet/app/db/dao"
  4. "applet/app/db/model"
  5. "applet/app/utils/logx"
  6. "reflect"
  7. "xorm.io/xorm"
  8. )
  9. func NewMediumDb(engine *xorm.Engine) dao.MediumDao {
  10. return &MediumDb{Db: engine}
  11. }
  12. type MediumDb struct {
  13. Db *xorm.Engine
  14. }
  15. func (m MediumDb) UpdateMedium(medium *model.Medium, columns ...string) (int64, error) {
  16. affected, err := m.Db.Where("id =?", medium.Id).Cols(columns...).Update(m)
  17. if err != nil {
  18. return 0, err
  19. }
  20. return affected, nil
  21. }
  22. func (m MediumDb) GetMediumByUsername(username string) (medium *model.Medium, err error) {
  23. medium = new(model.Medium)
  24. has, err := m.Db.Where("username =?", username).Get(medium)
  25. if err != nil {
  26. return nil, logx.Error(err)
  27. }
  28. if has == false {
  29. return nil, nil
  30. }
  31. return medium, nil
  32. }
  33. func (m MediumDb) MediumInsert(medium *model.Medium) (int64, error) {
  34. insertAffected, err := m.Db.InsertOne(medium)
  35. if err != nil {
  36. return 0, err
  37. }
  38. return insertAffected, nil
  39. }
  40. func (m MediumDb) MediumDeleteBySession(session *xorm.Session, id interface{}) (int64, error) {
  41. if reflect.TypeOf(id).Kind() == reflect.Slice {
  42. return session.In("id", id).Delete(model.Admin{})
  43. } else {
  44. return session.Where("id = ?", id).Delete(model.Admin{})
  45. }
  46. }