附近小店
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.

dbs_sys_cfg.go 1.2 KiB

3 months ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package db
  2. import (
  3. "xorm.io/xorm"
  4. "applet/app/db/model"
  5. "applet/app/utils/logx"
  6. )
  7. // 系统配置get
  8. func DbsSysCfgGetAll(eg *xorm.Engine) (*[]model.SysCfg, error) {
  9. var cfgList []model.SysCfg
  10. if err := eg.Cols("`key`,`val`").Find(&cfgList); cfgList == nil || err != nil {
  11. return nil, logx.Error(err)
  12. }
  13. return &cfgList, nil
  14. }
  15. // 获取一条记录
  16. func DbsSysCfgGet(eg *xorm.Engine, key string) (*model.SysCfg, error) {
  17. var cfgList model.SysCfg
  18. if has, err := eg.Where("`key`=?", key).Get(&cfgList); err != nil || has == false {
  19. return nil, logx.Error(err)
  20. }
  21. return &cfgList, nil
  22. }
  23. func DbsSysCfgInsert(eg *xorm.Engine, key, val string) bool {
  24. cfg := model.SysCfg{Key: key, Val: val}
  25. _, err := eg.Where("`key`=?", key).Cols("val,memo").Update(&cfg)
  26. if err != nil {
  27. logx.Error(err)
  28. return false
  29. }
  30. return true
  31. }
  32. func DbsSysCfgInserts(eg *xorm.Engine, key, val string) bool {
  33. cfg := model.SysCfg{Key: key, Val: val}
  34. _, err := eg.InsertOne(&cfg)
  35. if err != nil {
  36. logx.Error(err)
  37. return false
  38. }
  39. return true
  40. }
  41. func DbsSysCfgUpdate(eg *xorm.Engine, key, val string) bool {
  42. cfg := model.SysCfg{Key: key, Val: val}
  43. _, err := eg.Where("`key`=?", key).Cols("val").Update(&cfg)
  44. if err != nil {
  45. logx.Error(err)
  46. return false
  47. }
  48. return true
  49. }