tconfigmodel.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package model
  2. import (
  3. "context"
  4. "time"
  5. "github.com/zeromicro/go-zero/core/stores/sqlx"
  6. )
  7. // TConfig is one dynamic configuration row. Hot-reloadable audit settings
  8. // (MinIO endpoint/keys, log level, archive threshold, HMAC secret) are
  9. // stored here and read back on every request by the audit middleware.
  10. type TConfig struct {
  11. Id int64 `db:"id"` // 主键
  12. ConfigItem string `db:"config_item"` // 配置项
  13. ConfigValue string `db:"config_value"` // 配置值
  14. EditFlag int64 `db:"edit_flag"` // 是否允许编辑,1是不可编辑configItem,2是所有均可编辑
  15. Description string `db:"description"` // 描述
  16. UpdatedBy string `db:"updated_by"` // 最后更新人
  17. UpdatedAt time.Time `db:"updated_at"` // 配置更新时间
  18. }
  19. type TConfigModel interface {
  20. // FindAll returns every configuration row ordered by id.
  21. FindAll(ctx context.Context) ([]TConfig, error)
  22. }
  23. type customTConfigModel struct {
  24. conn sqlx.SqlConn
  25. table string
  26. }
  27. var _ TConfigModel = (*customTConfigModel)(nil)
  28. // NewTConfigModel returns the model for the t_config table.
  29. func NewTConfigModel(conn sqlx.SqlConn) TConfigModel {
  30. return &customTConfigModel{
  31. conn: conn,
  32. table: "`t_config`",
  33. }
  34. }
  35. func (m *customTConfigModel) FindAll(ctx context.Context) ([]TConfig, error) {
  36. var resp []TConfig
  37. query := "select `id`, `config_item`, `config_value`, `edit_flag`, `description`, `updated_by`, `updated_at` from t_config order by `id` asc"
  38. if err := m.conn.QueryRowsCtx(ctx, &resp, query); err != nil {
  39. return nil, err
  40. }
  41. return resp, nil
  42. }