446 Star 3.2K Fork 1.2K

GVP进击的皇虫/BookStack

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
friendlink.go 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
TruthHun 提交于 7年前 . 一大波修改...
package models
import (
"fmt"
"github.com/astaxie/beego/orm"
)
//友链数据表
type FriendLink struct {
Id int //自增主键
Sort int //排序
Link string `orm:"unique;size(128)"` //链接地址
Title string //链接名称
Status bool `orm:"default(1)"` //状态
}
//添加友情链接
func (this *FriendLink) Add(title, link string) (err error) {
var fl = FriendLink{
Title: title,
Link: link,
Sort: 0,
Status: true,
}
_, err = orm.NewOrm().Insert(&fl)
return
}
//根据字段更新友链
func (this *FriendLink) Update(id int, field string, value interface{}) (err error) {
sql := fmt.Sprintf("update md_friend_link set %v=? where id=?", field)
_, err = orm.NewOrm().Raw(sql, value, id).Exec()
return
}
//删除友情链接
func (this *FriendLink) Del(id int) (err error) {
var link = FriendLink{Id: id}
_, err = orm.NewOrm().Delete(&link)
return
}
//查询友链列表
//all表示是否查询全部,当为false时,只查询启用状态的友链,否则查询全部
func (this *FriendLink) GetList(all bool) (links []FriendLink) {
qs := orm.NewOrm().QueryTable("md_friend_link")
if !all {
qs = qs.Filter("status", 1)
}
qs.OrderBy("-status").OrderBy("sort").All(&links)
return
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/truthhun/BookStack.git
git@gitee.com:truthhun/BookStack.git
truthhun
BookStack
BookStack
v1.3.1

搜索帮助