// GetTemplates returns the templates owned by the given user.
funcGetTemplates(uidint64)([]Template,error){
ts:=[]Template{}
_,err:=Conn.Select(&ts,"SELECT t.id, t.name, t.modified_date, t.text, t.html FROM templates t, user_templates ut, users u WHERE ut.uid=u.id AND ut.tid=t.id AND u.id=?",uid)
returnts,err
}
// GetTemplate returns the template, if it exists, specified by the given id and user_id.
err:=Conn.SelectOne(&t,"SELECT t.id, t.name, t.modified_date, t.text, t.html FROM templates t, user_templates ut, users u WHERE ut.uid=u.id AND ut.tid=t.id AND t.id=? AND u.id=?",id,uid)
iferr!=nil{
returnt,err
}
returnt,err
}
// PostTemplate creates a new template in the database.
funcPostTemplate(t*Template,uidint64)error{
// Insert into the DB
err=Conn.Insert(t)
iferr!=nil{
Logger.Println(err)
returnerr
}
// Now, let's add the user->user_templates->template mapping
_,err=Conn.Exec("INSERT OR IGNORE INTO user_templates VALUES (?,?)",uid,t.Id)
iferr!=nil{
Logger.Printf("Error adding many-many mapping for template %s\n",t.Name)