2019-05-16 10:05:20 +00:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"background/db"
|
|
|
|
"background/logs"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Doc struct {
|
|
|
|
ID int64 `sql:"id" json:"id"`
|
|
|
|
Title string `sql:"title" json:"title"`
|
|
|
|
Type int64 `sql:"type" json:"type"`
|
|
|
|
Content string `sql:"content" json:"content"`
|
|
|
|
Author string `sql:"author" json:"author"`
|
2019-05-17 09:45:50 +00:00
|
|
|
}
|
2019-05-16 10:05:20 +00:00
|
|
|
|
2019-05-17 09:45:50 +00:00
|
|
|
type ArticleType struct {
|
|
|
|
Id int64 `sql:"id" json:"id"`
|
|
|
|
Name string `sql:"name" json:"name"`
|
|
|
|
Author string `sql:"author" json:"author"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetArticlesType() []ArticleType{
|
|
|
|
ret := []ArticleType{}
|
|
|
|
sql := fmt.Sprintf("select * from article_type");
|
|
|
|
e := db.GetBlogMysql().Query2(sql,&ret)
|
|
|
|
if nil != e{
|
|
|
|
logs.Error(e.Error())
|
|
|
|
return nil
|
2019-05-16 10:05:20 +00:00
|
|
|
}
|
2019-05-17 09:45:50 +00:00
|
|
|
return ret
|
|
|
|
}
|
|
|
|
func CreateDoc(doc Doc) error {
|
2019-06-23 11:33:45 +00:00
|
|
|
sql := fmt.Sprintf(`insert into doc(title,type,content,author) values ('%s','%d','%s','%s')
|
|
|
|
on duplicate key update title = '%s',type = '%d',content = '%s',author = '%s';`,doc.Title,doc.Type,doc.Content,doc.Author,doc.Title,doc.Type,doc.Content,doc.Author)
|
|
|
|
_,e := db.GetMysqlClient().Query(sql)
|
2019-05-16 10:05:20 +00:00
|
|
|
if nil != e{
|
|
|
|
logs.Error(e.Error())
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|