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


Golang MysqlDB.GetStructs方法代码示例

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


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

示例1: Comment_ByUser

// 获取由用户发布的评论
// @page: 从1开始
func Comment_ByUser(userId int64, page, pagesize int) []Comment {
	if page < 1 {
		page = 1
	}
	page = page - 1
	if pagesize == 0 {
		pagesize = 20
	}
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	qi := goku.SqlQueryInfo{}
	qi.Limit = pagesize
	qi.Offset = page * pagesize
	qi.Where = "`user_id`=?"
	qi.Params = []interface{}{userId}
	qi.Order = "id desc"
	var comments []Comment
	err := db.GetStructs(&comments, qi)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return nil
	}
	return comments
}
开发者ID:polaris1119,项目名称:ohlala,代码行数:27,代码来源:comment.go

示例2: 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

示例3: 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

示例4: GetTodoLists

func GetTodoLists() (*[]Todo, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()
	qi := goku.SqlQueryInfo{}
	qi.Order = "finished asc, id desc"
	var todos []Todo
	err := db.GetStructs(&todos, qi)
	return &todos, err
}
开发者ID:jango2015,项目名称:goku,代码行数:9,代码来源:todo.go

示例5: Topic_GetTops

func Topic_GetTops(page, pagesize int) ([]Topic, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	qi := goku.SqlQueryInfo{}
	qi.Order = "link_count desc"
	var topics []Topic
	err := db.GetStructs(&topics, qi)
	if err != nil {
		goku.Logger().Errorln(err.Error())
	}
	return topics, err
}
开发者ID:polaris1119,项目名称:ohlala,代码行数:13,代码来源:topic.go

示例6: Comment_ForLink

// 获取link的评论
func Comment_ForLink(linkId int64) []Comment {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	qi := goku.SqlQueryInfo{}
	qi.Where = "`link_id`=?"
	qi.Params = []interface{}{linkId}
	qi.Order = "id asc"
	var comments []Comment
	err := db.GetStructs(&comments, qi)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return nil
	}
	return comments
}
开发者ID:polaris1119,项目名称:ohlala,代码行数:17,代码来源:comment.go

示例7: User_GetByIds

func User_GetByIds(ids []int64) ([]User, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	users := []User{}
	qi := goku.SqlQueryInfo{}
	sids := ""
	for _, id := range ids {
		sids += "," + strconv.FormatInt(id, 10)
	}
	qi.Where = "id in (" + sids[1:] + ")"
	// qi.Params = []interface{}{ids}
	err := db.GetStructs(&users, qi)
	if err != nil {
		goku.Logger().Errorln("User_GetByIds error:", err.Error())
		return nil, err
	}
	return users, nil
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:19,代码来源:user.go

示例8: Link_ByUser

// 获取由用户发布的link
// @page: 从1开始
func Link_ByUser(userId int64, page, pagesize int) []Link {
	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 = "`user_id`=? and `status`=0"
	qi.Params = []interface{}{userId}
	qi.Order = "id desc"
	var links []Link
	err := db.GetStructs(&links, qi)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return nil
	}
	return links
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:22,代码来源:link.go

示例9: Link_ToVLink

// 转换为用于view显示用的实例
func Link_ToVLink(links []Link, ctx *goku.HttpContext) []VLink {
	if links == nil || len(links) < 1 {
		return nil
	}
	var userId int64
	if user, ok := ctx.Data["user"].(*User); ok && user != nil {
		userId = user.Id
	}
	l := len(links)

	vlinks := make([]VLink, l, l)
	uids := make([]string, l, l)
	lids := make([]string, l, l)
	lindex := make(map[int64]*VLink)
	for i, link := range links {
		uids[i] = strconv.FormatInt(link.UserId, 10)
		lids[i] = strconv.FormatInt(link.Id, 10)
		vlinks[i] = VLink{Link: link}
		lindex[link.Id] = &(vlinks[i])
	}

	var db *goku.MysqlDB = GetDB()
	defer db.Close()
	// 添加用户信息
	userIndex := make(map[int64]*User)
	qi := goku.SqlQueryInfo{}
	qi.Where = fmt.Sprintf("`id` in (%v)", strings.Join(uids, ","))
	var users []User
	err := db.GetStructs(&users, qi)
	if err != nil {
		goku.Logger().Errorln(err.Error())
	} else if users != nil {
		for i, _ := range users {
			user := &users[i]
			userIndex[user.Id] = user
		}
	}
	for i, _ := range vlinks {
		link := &vlinks[i]
		if user, ok := userIndex[link.UserId]; ok {
			link.user = user
			if user.Id == userId {
				link.SharedByMe = true
			}
		}
	}
	// 添加投票信息
	if userId > 0 {
		qi = goku.SqlQueryInfo{}
		qi.Where = fmt.Sprintf("`user_id`=%v AND `link_id` in (%v)", userId, strings.Join(lids, ","))
		var srs []LinkSupportRecord
		err = db.GetStructs(&srs, qi)
		if err != nil {
			goku.Logger().Errorln(err.Error())
		} else if srs != nil {
			for _, sr := range srs {
				if sr.Score == 1 {
					lindex[sr.LinkId].VoteUped = true
				} else if sr.Score == -1 {
					lindex[sr.LinkId].VoteDowned = true
				}
			}
		}

		// 添加收藏信息
		qi.Fields = "link_id"
		rows, err := db.Select("user_favorite_link", qi)
		if err != nil {
			goku.Logger().Errorln(err.Error())
		} else {
			var linkId int64
			for rows.Next() {
				err = rows.Scan(&linkId)
				if err != nil {
					goku.Logger().Errorln(err.Error())
					continue
				}
				lindex[linkId].Favorited = true
			}
		}
	}

	return vlinks
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:85,代码来源:link.go


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