15 Star 61 Fork 10

e9ab98e991ab/GoBooks

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
document_store.go 1.36 KB
一键复制 编辑 原始数据 按行查看 历史
高鑫 提交于 2018-11-20 21:09 +08:00 . commit
package models
import "github.com/astaxie/beego/orm"
var TableDocumentStore = "md_document_store"
// Document Store,文档存储,将大内容分发到专门的数据表里面
type DocumentStore struct {
DocumentId int `orm:"pk;auto;column(document_id)"` //文档id,对应Document中的document_id
Markdown string `orm:"type(text);"` //markdown内容
Content string `orm:"type(text);"` //文本内容
}
//插入或者更新
func (this *DocumentStore) InsertOrUpdate(ds DocumentStore, fields ...string) (err error) {
o := orm.NewOrm()
var one DocumentStore
o.QueryTable(TableDocumentStore).Filter("document_id", ds.DocumentId).One(&one, "document_id")
if one.DocumentId > 0 {
_, err = o.Update(&ds, fields...)
} else {
_, err = o.Insert(&ds)
}
return
}
//查询markdown内容或者content内容
func (this *DocumentStore) GetFiledById(docId interface{}, field string) string {
var ds = DocumentStore{}
if field != "markdown" {
field = "content"
}
orm.NewOrm().QueryTable(TableDocumentStore).Filter("document_id", docId).One(&ds, field)
if field == "content" {
return ds.Content
}
return ds.Markdown
}
//查询markdown内容或者content内容
func (this *DocumentStore) DeleteById(docId ...interface{}) {
if len(docId) > 0 {
orm.NewOrm().QueryTable(TableDocumentStore).Filter("document_id__in", docId...).Delete()
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/Godfeer/GoBooks.git
git@gitee.com:Godfeer/GoBooks.git
Godfeer
GoBooks
GoBooks
cbd8ecaa8838

搜索帮助