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


Golang goku.SqlQueryInfo类代码示例

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


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

示例1: NewestLinkUnread_Friends

// 关注好友的最新链接的未读数
func NewestLinkUnread_Friends(userId, lastReadLinkId int64) (int64, error) {
	if userId < 1 {
		return 0, nil
	}

	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	qi := goku.SqlQueryInfo{}
	qi.Where = "`user_id`=? and `link_id`>?"
	qi.Params = []interface{}{userId, lastReadLinkId}
	qi.Fields = "count(*)"
	tableName := LinkForUser_TableName(userId)
	rows, err := db.Select(tableName, qi)
	var unreadCount int64
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return 0, err
	}
	if rows.Next() {
		err = rows.Scan(&unreadCount)
		if err != nil {
			goku.Logger().Errorln(err.Error())
			return 0, err
		}
	}
	return unreadCount, nil
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:29,代码来源:link_unread.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: 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

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

// 获取由用户收藏的link
// @page: 从1开始
func FavoriteLink_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.Fields = "l.id, l.user_id, l.title, l.context, l.topics, l.vote_up, l.vote_down, l.view_count, l.comment_count, l.create_time"
	qi.Join = " ufl INNER JOIN `link` l ON ufl.link_id=l.id"
	qi.Where = "ufl.user_id=?"
	qi.Params = []interface{}{userId}
	qi.Limit = pagesize
	qi.Offset = pagesize * page
	qi.Order = "ufl.create_time desc"

	rows, err := db.Select("user_favorite_link", qi)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return nil
	}
	links := make([]Link, 0)
	for rows.Next() {
		link := Link{}
		err = rows.Scan(&link.Id, &link.UserId, &link.Title, &link.Context, &link.Topics,
			&link.VoteUp, &link.VoteDown, &link.ViewCount, &link.CommentCount, &link.CreateTime)
		if err != nil {
			goku.Logger().Errorln(err.Error())
			return nil
		}
		links = append(links, link)
	}

	return links
}
开发者ID:cloudcache,项目名称:ohlala,代码行数:36,代码来源:favorite_link.go

示例7: Topic_GetFollowers

// 获取关注topicId的用户列表
func Topic_GetFollowers(topicId int64, page, pagesize int) ([]User, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

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

	qi := goku.SqlQueryInfo{}
	qi.Fields = "u.id, u.name, u.email, u.user_pic"
	qi.Join = " tf INNER JOIN `user` u ON tf.user_id=u.id"
	qi.Where = "tf.topic_id=?"
	qi.Params = []interface{}{topicId}
	qi.Limit = pagesize
	qi.Offset = pagesize * page
	qi.Order = "u.id desc"

	rows, err := db.Select("topic_follow", qi)

	if err != nil {
		goku.Logger().Errorln(err.Error())
		return nil, err
	}
	defer rows.Close()

	users := make([]User, 0)
	for rows.Next() {
		user := User{}
		err = rows.Scan(&user.Id, &user.Name, &user.Email, &user.UserPic)
		if err != nil {
			goku.Logger().Errorln(err.Error())
			return nil, err
		}
		users = append(users, user)
	}
	return users, nil
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:36,代码来源:topic.go

示例8: User_GetFollowTopics

// 获取用户关注的话题列表
func User_GetFollowTopics(userId int64, page, pagesize int) ([]Topic, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

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

	qi := goku.SqlQueryInfo{}
	qi.Fields = "t.id, t.name, t.description, t.pic"
	qi.Join = " tf INNER JOIN `topic` t ON tf.topic_id=t.id"
	qi.Where = "tf.user_id=?"
	qi.Params = []interface{}{userId}
	qi.Limit = pagesize
	qi.Offset = pagesize * page
	qi.Order = "t.id desc"

	rows, err := db.Select("topic_follow", qi)

	if err != nil {
		goku.Logger().Errorln(err.Error())
		return nil, err
	}
	defer rows.Close()

	topics := make([]Topic, 0)
	for rows.Next() {
		topic := Topic{}
		err = rows.Scan(&topic.Id, &topic.Name, &topic.Description, &topic.Pic)
		if err != nil {
			goku.Logger().Errorln(err.Error())
			return nil, err
		}
		topics = append(topics, topic)
	}
	return topics, nil
}
开发者ID:t7er,项目名称:ohlala,代码行数:36,代码来源:user.go

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

示例10: User_SearchByName

//模糊搜索用户
func User_SearchByName(name string, ctx *goku.HttpContext) ([]*VUser, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	qi := goku.SqlQueryInfo{}
	qi.Fields = "`id`,`name`,`email`,`description`,`user_pic`,`friend_count`,`topic_count`,`ftopic_count`,`status`,`follower_count`,`link_count`,`create_time`"
	qi.Where = "name_lower LIKE ?"
	qi.Params = []interface{}{strings.ToLower(name) + "%"}
	qi.Limit = 10
	qi.Offset = 0
	qi.Order = "link_count DESC"

	rows, err := db.Select("user", qi)

	if err != nil {
		goku.Logger().Errorln(err.Error())
		return nil, err
	}

	users := make([]User, 0)
	for rows.Next() {
		user := User{}
		err = rows.Scan(&user.Id, &user.Name, &user.Email, &user.Description, &user.UserPic, &user.FriendCount, &user.TopicCount, &user.FtopicCount, &user.Status, &user.FollowerCount, &user.LinkCount, &user.CreateTime)
		if err != nil {
			goku.Logger().Errorln(err.Error())
			return nil, err
		}
		users = append(users, user)
	}

	return User_ToVUsers(users, ctx), nil

}
开发者ID:yonglehou,项目名称:ohlala,代码行数:34,代码来源:user.go

示例11: Topic_SearchByName

func Topic_SearchByName(name string) ([]Topic, error) {
	var db *goku.MysqlDB = GetDB()
	// db.Debug = true
	defer db.Close()

	qi := goku.SqlQueryInfo{}
	qi.Fields = "`id`,`name`,`name_lower`,`description`,`pic`,`click_count`,`follower_count`,`link_count`"
	qi.Where = "name_lower LIKE ?"                         //"name_lower LIKE '%" + strings.ToLower(name) + "%'"
	qi.Params = []interface{}{strings.ToLower(name) + "%"} //"%" +
	qi.Limit = 10
	qi.Offset = 0
	qi.Order = "link_count DESC"

	rows, err := db.Select("topic", qi)

	topics := make([]Topic, 0)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return topics, err
	}

	for rows.Next() {
		topic := Topic{}
		err = rows.Scan(&topic.Id, &topic.Name, &topic.NameLower, &topic.Description, &topic.Pic, &topic.ClickCount, &topic.FollowerCount, &topic.LinkCount)
		if err != nil {
			goku.Logger().Errorln(err.Error())
			return topics, err
		}
		topics = append(topics, topic)
	}

	return topics, nil

}
开发者ID:yonglehou,项目名称:ohlala,代码行数:34,代码来源:topic.go

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

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

示例14: Link_GetByIdList

// 根据id列表获取link
func Link_GetByIdList(searchItems []utils.SearchHitItem) ([]Link, error) {
	hashTable := map[int64]*Link{}
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	var strLinkIdList string
	for _, item := range searchItems {
		strLinkIdList += item.Id + ","
	}
	strLinkIdList += "0"

	qi := goku.SqlQueryInfo{}
	qi.Fields = "id, user_id, title, context, topics, vote_up, vote_down, view_count, comment_count, create_time, status"
	qi.Where = "id IN(" + strLinkIdList + ")"
	rows, err := db.Select("link", qi)

	if err != nil {
		goku.Logger().Errorln(err.Error())
		return nil, err
	}
	defer rows.Close()

	links := make([]Link, 0)
	for rows.Next() {
		link := &Link{}
		err = rows.Scan(&link.Id, &link.UserId, &link.Title, &link.Context, &link.Topics,
			&link.VoteUp, &link.VoteDown, &link.ViewCount, &link.CommentCount, &link.CreateTime, &link.Status)
		if err != nil {
			goku.Logger().Errorln(err.Error())
			return nil, err
		}
		hashTable[link.Id] = link
	}
	for _, item := range searchItems {
		linkId, err := strconv.ParseInt(item.Id, 10, 64)
		link := hashTable[linkId]
		if err == nil && link != nil {
			links = append(links, *link)
		}
	}

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

示例15: NewestLinkUnread_All

// 全部链接的最新链接的未读数
func NewestLinkUnread_All(userId, lastReadLinkId int64) (int64, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	qi := goku.SqlQueryInfo{}
	qi.Fields = "max(id)"
	rows, err := db.Select(Table_Link, qi)
	var maxLinkId int64
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return 0, err
	}
	if rows.Next() {
		err = rows.Scan(&maxLinkId)
		if err != nil {
			goku.Logger().Errorln(err.Error())
			return 0, err
		}
	}
	return maxLinkId - lastReadLinkId - 1, nil
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:22,代码来源:link_unread.go


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