Skip to content

get HaveCountList function return no all fields#543

Open
airplayx wants to merge 4 commits intogo-gorm:masterfrom
airplayx:master
Open

get HaveCountList function return no all fields#543
airplayx wants to merge 4 commits intogo-gorm:masterfrom
airplayx:master

Conversation

@airplayx
Copy link

HaveCountList func:

func (srv *commentService) HaveCountList(maps *Comment, where interface{}, limit, offset int) (info []*Comment, count int64, err error) {
	query := DB.Model(&Comment{}).
		Unscoped().
		Joins("User").
		Where(where).Where(maps).
		Group(srv.table + ".id").
		Count(&count).Offset(offset).Limit(limit).
		Order(srv.table + ".id desc").
		Find(&info)
	if err = query.Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
		panic(err)
	}
	return
}

return sql:

SELECT count(*) FROM `comment` LEFT JOIN `user` `User` ON `comment`.`author_id` = `User`.`id` WHERE `comment`.`id` = 10000 GROUP BY `comment`.`id`

SELECT `comment`.`id`,`comment`.`content_id`,`comment`.`author_id`,`comment`.`content`,`comment`.`parent_comment_id`,`comment`.`ip`,`comment`.`user_agent`,`comment`.`pushed_at`,
`comment`.`author_name`,`comment`.`author_avatar_url`,`comment`.`author_url`,`comment`.`blog_id`,`comment`.`status`,`comment`.`created_at`,`comment`.`updated_at`,`comment`.`deleted_at` FROM `comment` LEFT JOIN `user`
 `User` ON `comment`.`author_id` = `User`.`id` WHERE `comment`.`id` = 10000 GROUP BY `comment`.`id` ORDER BY comment.id desc 


NormalList func :


func (srv *commentService) NormalList(maps *Comment, where interface{}, limit, offset int) (info []*Comment, count int64, err error) {
	query := DB.Model(&Comment{}).
		Unscoped().
		Joins("User").
		Where(where).Where(maps).
		Group(srv.table + ".id").
		Offset(offset).Limit(limit).
		Order(srv.table + ".id desc").
		Find(&info)
	if err = query.Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
		panic(err)
	}
	return
}

return sql:

SELECT `comment`.`id`,`comment`.`content_id`,`comment`.`author_id`,`comment`.`content`,`comment`.`parent_comment_id`,`comment`.`ip`,`comment`.`user_agent`,`comment`.`pushed_at`,
`comment`.`author_name`,`comment`.`author_avatar_url`,`comment`.`author_url`,`comment`.`blog_id`,`comment`.`status`,`comment`.`created_at`,`comment`.`updated_at`,`comment`.`deleted_at`,
`User`.`id` AS `User__id`,`User`.`name` AS `User__name`,`User`.`channel_id` AS `User__channel_id`,`User`.`sign_time` AS `User__sign_time` FROM `comment` LEFT JOIN `user` 
`User` ON `comment`.`author_id` = `User`.`id` WHERE `comment`.`id` = 10000 GROUP BY `comment`.`id` ORDER BY comment.id desc 

Added input validation for Cloudflare API Token and domain names.
Added color control for error messages and warnings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant