package model import "github.com/jinzhu/gorm" type DustExcessiveImg struct { Ecode string `gorm:"column:Ecode"` ImageText string `gorm:"column:ImageText"` ID int64 `gorm:"column:ID"` ProjectId int64 `gorm:"column:ProjectId"` SN string `gorm:"column:SN"` DeviceID string `gorm:"column:DeviceID"` } func (DustExcessiveImg) TableName() string { return "DustExcessiveImg" } func (p *DustExcessiveImg) Insert(db *gorm.DB) error { return db.Table(p.TableName()).Create(p).Error } func (p *DustExcessiveImg) Find(db *gorm.DB, where map[string]interface{}, or map[string]interface{}) error { cond, val, err := whereBuildAndOr(where, or) if err != nil { return err } return db.Table(p.TableName()).Where(cond, val...).First(p).Error } func (p *DustExcessiveImg) All(db *gorm.DB, where map[string]interface{}) (list []DustExcessiveImg, err error) { if len(where) > 0 { cond, val, err := whereBuild(where) if err != nil { return nil, err } result := db.Table(p.TableName()).Where(cond, val).Find(&list) return list, result.Error } result := db.Table(p.TableName()).Find(&list) return list, result.Error } func (p *DustExcessiveImg) Count(db *gorm.DB, where map[string]interface{}) (int64, error) { if len(where) > 0 { cond, val, err := whereBuild(where) if err != nil { return 0, err } ret := int64(0) err = db.Table(p.TableName()).Where(cond, val...).Count(&ret).Error return ret, err } ret := int64(0) err := db.Table(p.TableName()).Count(&ret).Error return ret, err } func (p *DustExcessiveImg) Del(db *gorm.DB, where map[string]interface{}) error { cond, val, err := whereBuild(where) if err != nil { return err } return db.Table(p.TableName()).Where(cond, val...).Delete(p).Error }