forked from TruthHun/BookStack
/
document_store.go
49 lines (40 loc) · 1.32 KB
/
document_store.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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(document_id interface{},field string)string {
var ds=DocumentStore{}
if field!="markdown"{
field="content"
}
orm.NewOrm().QueryTable(TableDocumentStore).Filter("document_id",document_id).One(&ds,field)
if field=="content"{
return ds.Content
}else{
return ds.Markdown
}
}
//查询markdown内容或者content内容
func (this *DocumentStore)DeleteById(document_id ...interface{}) {
if len(document_id)>0{
orm.NewOrm().QueryTable(TableDocumentStore).Filter("document_id__in",document_id...).Delete()
}
}