c2_item.go 673 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package model
  2. import (
  3. "git.getensh.com/common/gopkgsv2/database"
  4. "gorm.io/gorm"
  5. )
  6. type C2ItemModel interface {
  7. List(db *gorm.DB) ([]C2Item, error)
  8. }
  9. type C2Item struct {
  10. ID int64 `gorm:"column:id" json:"id"`
  11. Name string `gorm:"column:name" json:"name"`
  12. }
  13. type defaultC2ItemModel struct {
  14. tabname string
  15. fields string
  16. }
  17. func NewC2ItemModel() C2ItemModel {
  18. return &defaultC2ItemModel{
  19. tabname: "db_adm_dws.t_adm_ads6",
  20. fields: "id, name",
  21. }
  22. }
  23. func (d *defaultC2ItemModel) List(db *gorm.DB) ([]C2Item, error) {
  24. var res []C2Item
  25. err := database.List(db, &res, database.Option{
  26. TableName: d.tabname,
  27. Fields: d.fields,
  28. })
  29. return res, err
  30. }