蛋蛋星球 后台端
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.

db_sys_cfg.go 1.0 KiB

3 weeks ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils/logx"
  5. "xorm.io/xorm"
  6. )
  7. // 系统配置get
  8. func SysCfgGetAll(Db *xorm.Engine) (*[]model.SysCfg, error) {
  9. var cfgList []model.SysCfg
  10. if err := Db.Cols("key,val,memo").Find(&cfgList); err != nil {
  11. return nil, logx.Error(err)
  12. }
  13. return &cfgList, nil
  14. }
  15. // 获取一条记录
  16. func SysCfgGetOne(Db *xorm.Engine, key string) (*model.SysCfg, error) {
  17. var cfgList model.SysCfg
  18. if has, err := Db.Where("`key`=?", key).Get(&cfgList); err != nil || has == false {
  19. return nil, logx.Error(err)
  20. }
  21. return &cfgList, nil
  22. }
  23. // 返回最后插入id
  24. func SysCfgInsert(Db *xorm.Engine, key, val, memo string) bool {
  25. cfg := model.SysCfg{Key: key, Val: val, Memo: memo}
  26. _, err := Db.InsertOne(&cfg)
  27. if err != nil {
  28. logx.Error(err)
  29. return false
  30. }
  31. return true
  32. }
  33. func SysCfgUpdate(Db *xorm.Engine, key, val, memo string) bool {
  34. cfg := model.SysCfg{Key: key, Val: val, Memo: memo}
  35. _, err := Db.Where("`key`=?", key).Cols("val,memo").Update(&cfg)
  36. if err != nil {
  37. logx.Error(err)
  38. return false
  39. }
  40. return true
  41. }