package model import ( "background/db" "background/logs" "fmt" "log" ) type DocTemplate struct { Id int32 `sql:"id" json:"id"` Content string `sql:"content" json:"content"` Name string `sql:"content" json:"name"` } func CreateDocTemplate(templ DocTemplate) error{ sql := fmt.Sprintf(`insert into doc_template(content,name) select '%s','%s from dual where not exists (select * from doc_template where doc_template.name='%s') `, templ.Content,templ.Name,templ.Name) log.Print(sql) _, e := db.GetMysqlClient().Query(sql) if nil != e { log.Print(sql) return e } return nil } func UpdateDocTemplate(templ DocTemplate) error{ sql := fmt.Sprintf(`update doc_template set content = %s, name = %s, where memo.id = '%d'`,templ.Content,templ.Name,templ.Id) _, e := db.GetMysqlClient().Query(sql) if nil != e { log.Print(e.Error()) return e } return nil } func DeleteDocTemplate(id int32) error{ sql := fmt.Sprintf(`delete from doc_template doc_template memo.id = '%d'`,id) _, e := db.GetMysqlClient().Query(sql) if nil != e { logs.Error(e.Error()) return e } return nil } func ReadDocTemplate(id int32) ([]DocTemplate,error){ memo := []DocTemplate{} sql := fmt.Sprintf(`select * from doc_template where doc_template.id = '%d'`,id) e := db.GetMysqlClient().Query2(sql,&memo) if nil != e { logs.Error(e.Error()) return nil,e } return memo,nil } func GetDocTemplate(title string,limit int,offset int) ([]DocTemplate,error) { memo := []DocTemplate{} sql := fmt.Sprintf(`select * from doc_template where doc_template.name like '%s%%' limit %d offset %d`, title,limit,offset) log.Print(sql) e := db.GetMysqlClient().Query2(sql,&memo) if nil != e { logs.Error(e.Error()) return nil,e } return memo,nil }