12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package models
- import (
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- func (i *ImageSource) TableName() string {
- return "image_sources"
- }
- type ImageSource struct {
- Id int ` description:"Id"`
- ImgName string `description:"图片名称"`
- SrcUrl string `description:"图片资源"`
- PermissionId int `description:"品种"`
- Deleted int `description:"是否删除"`
- CreatedTime time.Time `description:"创建时间"`
- UpdatedTime time.Time `description:"更新时间"`
- }
- func (i *ImageSource) Insert() (insertId int64, err error) {
- o := orm.NewOrm()
- insertId, err = o.Insert(i)
- return
- }
- func (i *ImageSource) Update() (err error) {
- o := orm.NewOrm()
- _, err = o.Update(i, "img_name", "src_url", "permission_id")
- return
- }
- func (i *ImageSource) Delete() (err error) {
- o := orm.NewOrm()
- _, err = o.Update(i, "deleted")
- return
- }
- func GetImageIdByPermissionId(permissionId int) (items []int, err error) {
- o := orm.NewOrm()
- sql := "select id from image_sources where permission_id = ?"
- _, err = o.Raw(sql, permissionId).QueryRows(&items)
- return
- }
- func GetImageById(Id int) (item *ImageSource, err error) {
- o := orm.NewOrm()
- sql := "select id from image_sources where id = ?"
- err = o.Raw(sql, Id).QueryRow(&item)
- return
- }
|