-
Notifications
You must be signed in to change notification settings - Fork 0
/
cellphone.go
49 lines (40 loc) · 1.05 KB
/
cellphone.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package dao
import (
"gorm.io/gorm"
)
type Cellphone struct {
CommonTimeModel
Id uint64 `json:"id" gorm"primaryKey"`
Cellphone uint64 `json:"cellphone"`
IsDeleted uint64 `json:"is_deleted" gorm:"default:0" `
}
type CellphoneDao struct {
DB *gorm.DB
}
func NewCellphoneDao() *CellphoneDao {
return &CellphoneDao{
DB: DB,
}
}
func (dao *CellphoneDao) Create(data Cellphone) (err error) {
err = DB.Create(&data).Error
return
}
func (dao *CellphoneDao) FindByFields(fields map[string]interface{}) ([]Cellphone, error) {
var ages []Cellphone
err := DB.Where(fields).Find(&ages).Error
if err != nil && err != gorm.ErrRecordNotFound {
return nil, err
}
return ages, nil
}
func (dao *CellphoneDao) DeleteByIds(ids []uint64) (err error) {
if err := DB.Where(&map[string]interface{}{"id": ids}).Update("is_deleted", 1).Error; err != nil {
return err
}
return nil
}
func (dao *CellphoneDao) UpdateFields(where map[string]interface{}, updateFileds map[string]interface{}) (err error) {
// err = DB.Where(&where).Update(updateFileds).Error
return
}