com.snow.auto_monitor/app/models/bannermodel/banner.go

58 lines
1.1 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package bannermodel
import (
"sync"
"time"
"github.com/qit-team/snow-core/db"
)
var (
once sync.Once
m *bannerModel
)
/**
* Banner实体
*/
type Banner struct {
Id int64 `xorm:"pk autoincr"` //注使用getOne 或者ID() 需要设置主键
Pid int
Title string
ImageUrl string `xorm:"'img_url'"`
Url string
Status string
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt time.Time `xorm:"deleted"` //此特性会激发软删除
}
/**
* 表名规则
* @wiki http://gobook.io/read/github.com/go-xorm/manual-zh-CN/chapter-02/3.tags.html
*/
func (m *Banner) TableName() string {
return "banner"
}
/**
* 私有化防止被外部new
*/
type bannerModel struct {
db.Model //组合基础Model集成基础Model的属性和方法
}
//单例模式
func GetInstance() *bannerModel {
once.Do(func() {
m = new(bannerModel)
//m.DiName = "" //设置数据库实例连接默认db.SingletonMain
})
return m
}
func (m *bannerModel) GetListByPid(pid int, limits ...int) (banners []*Banner, err error) {
banners = make([]*Banner, 0)
err = m.GetList(&banners, "pid = ?", []interface{}{pid}, limits)
return
}