area_code.go 607 B

1234567891011121314151617181920212223242526272829
  1. package model
  2. import "github.com/jinzhu/gorm"
  3. type AreaCode struct {
  4. ID int64 `gorm:"column:ID"`
  5. Code string `gorm:"column:Code"`
  6. Addr string `gorm:"column:Addr"`
  7. }
  8. func (AreaCode) TableName() string {
  9. return "AreaCode"
  10. }
  11. func (p *AreaCode) List(db *gorm.DB, where map[string]interface{}) (list []AreaCode, err error) {
  12. if len(where) > 0 {
  13. cond, val, err := whereBuild(where)
  14. if err != nil {
  15. return list, err
  16. }
  17. result := db.Table(p.TableName()).Where(cond, val...).Find(&list)
  18. return list, result.Error
  19. }
  20. result := db.Table(p.TableName()).Find(&list)
  21. return list, result.Error
  22. }