29 lines
639 B
Go
29 lines
639 B
Go
package model
|
|
|
|
import (
|
|
"background/db"
|
|
"background/logs"
|
|
"errors"
|
|
"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"`
|
|
}
|
|
|
|
func CreateDoc(doc Doc) error {
|
|
if doc.ID == 0{
|
|
return errors.New("wrong primary key")
|
|
}
|
|
sql := fmt.Sprintf("insert into doc(title,type,content,author) values ('%s','%d','%s','%s')",doc.Title,doc.Type,doc.Content,doc.Author)
|
|
_,e := db.GetMysqlClient().Query(sql)
|
|
if nil != e{
|
|
logs.Error(e.Error())
|
|
return e
|
|
}
|
|
return nil
|
|
} |