當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。