当前位置: 首页>>代码示例>>Golang>>正文


Golang MysqlDB.Count方法代码示例

本文整理汇总了Golang中github.com/QLeelulu/goku.MysqlDB.Count方法的典型用法代码示例。如果您正苦于以下问题:Golang MysqlDB.Count方法的具体用法?Golang MysqlDB.Count怎么用?Golang MysqlDB.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/QLeelulu/goku.MysqlDB的用法示例。


在下文中一共展示了MysqlDB.Count方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: User_GetList

// 获取用户列表.
// @page: 从1开始的页数
// @return: users, total-count, err
func User_GetList(page, pagesize int, order string) ([]User, int64, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	page, pagesize = utils.PageCheck(page, pagesize)

	qi := goku.SqlQueryInfo{}
	qi.Limit = pagesize
	qi.Offset = pagesize * page
	if order == "" {
		qi.Order = "id desc"
	} else {
		qi.Order = order
	}

	var users []User
	err := db.GetStructs(&users, qi)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return nil, 0, err
	}

	total, err := db.Count("user", "")
	if err != nil {
		goku.Logger().Errorln(err.Error())
	}
	return users, total, nil
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:31,代码来源:user.go

示例2: Comment_GetByPage

// @page: 从1开始
// @return: comments, total-count, err
func Comment_GetByPage(page, pagesize int, order string) ([]Comment, int64, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	page, pagesize = utils.PageCheck(page, pagesize)

	qi := goku.SqlQueryInfo{}
	qi.Limit = pagesize
	qi.Offset = page * pagesize
	if order == "" {
		qi.Order = "id desc"
	} else {
		qi.Order = order
	}
	var comments []Comment
	err := db.GetStructs(&comments, qi)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return nil, 0, err
	}

	total, err := db.Count("comment", "")
	if err != nil {
		goku.Logger().Errorln(err.Error())
	}

	return comments, total, nil
}
开发者ID:polaris1119,项目名称:ohlala,代码行数:30,代码来源:comment.go

示例3: admin_index

func admin_index(ctx *goku.HttpContext) goku.ActionResulter {
	var db *goku.MysqlDB = models.GetDB()
	defer db.Close()

	linkCount, err := db.Count("link", "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["linkCount"] = linkCount

	userCount, err := db.Count("user", "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["userCount"] = userCount

	topicCount, err := db.Count("topic", "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["topicCount"] = topicCount

	commentCount, err := db.Count("comment", "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["commentCount"] = commentCount

	return ctx.View(nil)
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:34,代码来源:index.go

示例4: CommentForUser_GetByPage

// 获取收到的评论列表
// @page: 从1开始
// @return: comments, total-count, err
func CommentForUser_GetByPage(userId int64, page, pagesize int, order string) ([]Comment, int64, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	page, pagesize = utils.PageCheck(page, pagesize)

	qi := goku.SqlQueryInfo{}
	qi.Limit = pagesize
	qi.Offset = page * pagesize
	qi.Where = "cfu.user_id=?"
	qi.Join = " cfu INNER JOIN `comment` c ON cfu.comment_id=c.id"
	qi.Fields = `c.id, c.user_id, c.link_id, c.parent_path, c.children_count, c.top_parent_id,
                c.parent_id, c.deep, c.status, c.content, c.create_time, c.vote_up, c.vote_down, c.reddit_score`

	if order == "" {
		qi.Order = "create_time desc"
	} else {
		qi.Order = order
	}

	qi.Params = []interface{}{userId}
	rows, err := db.Select("comment_for_user", qi)

	if err != nil {
		goku.Logger().Errorln(err.Error())
		return nil, 0, err
	}
	defer rows.Close()
	comments := make([]Comment, 0)
	for rows.Next() {
		c := Comment{}
		err = rows.Scan(&c.Id, &c.UserId, &c.LinkId, &c.ParentPath, &c.ChildrenCount,
			&c.TopParentId, &c.ParentId, &c.Deep, &c.Status, &c.Content,
			&c.CreateTime, &c.VoteUp, &c.VoteDown, &c.RedditScore)
		if err != nil {
			goku.Logger().Errorln(err.Error())
			return nil, 0, err
		}
		comments = append(comments, c)
	}

	total, err := db.Count("comment_for_user", "user_id=?", userId)
	if err != nil {
		goku.Logger().Errorln(err.Error())
	}

	return comments, total, nil
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:51,代码来源:comment_for_user.go


注:本文中的github.com/QLeelulu/goku.MysqlDB.Count方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。