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
}
Ejemplo n.º 2
0
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})
	}

}
func SaveArticleView(articleView entities.ArticleView, db db.DB) error {
	_, err := db.Insert(&articleView)
	return err

}
func HasViewArticle(articleId int64, userId int64, ip string, db db.DB) (bool, error) {

	count, err := db.QueryTable("article_view").Filter("article_id", articleId).Filter("ip", ip).Count()

	return count > 0, err
}
func HasLikeArticle(articleId int64, userId int64, db db.DB) (bool, error) {
	count, err := db.QueryTable("article_like").Filter("user_id", userId).Filter("article_id", articleId).Filter("valid", 1).Count()

	return count > 0, err
}