func SaveOrUpdate(articleLike entities.ArticleLike, db db.DB) error { sql := bytes.NewBufferString("insert into article_like (user_id , article_id,valid,created_at) ") sql.WriteString("values(?,?,?,now()) ") sql.WriteString("on duplicate key update valid =?,updated_at=now() ") _, err := db.Execute(sql.String(), []interface{}{articleLike.UserId, articleLike.ArticleId, articleLike.Valid, articleLike.Valid}) return err }
func BatchSaveOrUpdateCategory(db db.DB, categories []entities.Category) { sql := bytes.NewBufferString("insert into category(user_id,name,`order`,article_count,created_at) ") sql.WriteString("values(?,?,0,1,now()) ") sql.WriteString("on duplicate key update article_count =article_count+1,updated_at=now()") for _, category := range categories { db.Execute(sql.String(), []interface{}{category.UserId, category.Name}) } }