當前位置: 首頁>>代碼示例>>Golang>>正文


Golang SqlQueryInfo.Params方法代碼示例

本文整理匯總了Golang中github.com/QLeelulu/goku.SqlQueryInfo.Params方法的典型用法代碼示例。如果您正苦於以下問題:Golang SqlQueryInfo.Params方法的具體用法?Golang SqlQueryInfo.Params怎麽用?Golang SqlQueryInfo.Params使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/QLeelulu/goku.SqlQueryInfo的用法示例。


在下文中一共展示了SqlQueryInfo.Params方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

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

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

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

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

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

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

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

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

// 獲取屬於某用戶的link
// @page: 從1開始
// @orderType: 排序類型, hot:熱門, hotc:熱議, time:最新, vote:投票得分, ctvl:爭議
func Link_ForUser(userId int64, orderType string, page, pagesize int) ([]Link, error) {
    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.click_count, l.comment_count, l.create_time"
    qi.Join = " ul INNER JOIN `link` l ON ul.link_id=l.id"
    qi.Where = "ul.user_id=?"
    qi.Params = []interface{}{userId}
    qi.Limit = pagesize
    qi.Offset = pagesize * page
    switch orderType {
    case golink.ORDER_TYPE_TIME: // 最新
        qi.Order = "l.id desc"
    case golink.ORDER_TYPE_HOTC: // 熱議
        qi.Order = "l.comment_count desc, id desc"
    case golink.ORDER_TYPE_CTVL: // 爭議
        qi.Order = "l.dispute_score desc, id desc"
    case golink.ORDER_TYPE_VOTE: // 得分
        qi.Order = "l.vote_up desc, id desc"
    default:
        qi.Order = "l.reddit_score desc, id desc"
    }

    rows, err := db.Select(LinkForUser_TableName(userId), 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.ClickCount, &link.CommentCount, &link.CreateTime)
        if err != nil {
            goku.Logger().Errorln(err.Error())
            return nil, err
        }
        links = append(links, link)
    }
    return links, nil
}
開發者ID:yonglehou,項目名稱:ohlala,代碼行數:50,代碼來源:link.go

示例11: UserFollow_Followers

// 獲取用戶關注的粉絲列表
func UserFollow_Followers(userId int64, page, pagesize int) ([]User, error) {
    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.Fields = "u.id, u.name, u.email, u.user_pic, u.follower_count, u.link_count, u.topic_count, u.friend_count, u.ftopic_count"
    qi.Join = " uf INNER JOIN `user` u ON uf.user_id=u.id"
    qi.Where = "uf.follow_id=?"
    qi.Params = []interface{}{userId}
    qi.Limit = pagesize
    qi.Offset = pagesize * page
    // qi.Order = "u.id desc"
    qi.Order = "uf.create_time desc"

    rows, err := db.Select("user_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,
            &user.FollowerCount, &user.LinkCount, &user.TopicCount, &user.FriendCount, &user.FtopicCount)
        if err != nil {
            goku.Logger().Errorln(err.Error())
            return nil, err
        }
        users = append(users, user)
    }
    return users, nil
}
開發者ID:yonglehou,項目名稱:ohlala,代碼行數:43,代碼來源:user_follow.go

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

示例13: LinkForUser_ToUserFollowers

// 將linkid推送給userid的所有粉絲
func LinkForUser_ToUserFollowers(userId, linkId int64) error {
    db := GetDB()
    defer db.Close()

    qi := goku.SqlQueryInfo{}
    qi.Fields = "`user_id`"
    qi.Where = "`follow_id`=?"
    qi.Params = []interface{}{userId}
    rows, err := db.Select("user_follow", qi)
    if err != nil {
        goku.Logger().Errorln(err.Error())
        return err
    }

    var uid int64
    for rows.Next() {
        err = rows.Scan(&uid)
        if err == nil && uid > 0 {
            linkForUser_AddWithDb(db, uid, linkId, LinkForUser_ByUser)
        }
    }
    return nil
}
開發者ID:Leon1108,項目名稱:ohlala,代碼行數:24,代碼來源:link_for_user.go

示例14: Link_ForTopic

// 獲取屬於某話題的link
// @page: 從1開始
func Link_ForTopic(topicId int64, page, pagesize int, sortType string, t string) ([]Link, error) {
    var db *goku.MysqlDB = GetDB()
    db.Debug = true
    defer db.Close()

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

    sortField := "tl.reddit_score DESC,tl.link_id DESC"
    tableName := "tui_link_for_topic_top"
    switch {
    case sortType == golink.ORDER_TYPE_HOTC: //熱議
        sortField = "l.comment_count DESC,tl.link_id DESC"
        tableName = "tui_link_for_topic_top"
    case sortType == golink.ORDER_TYPE_CTVL: //爭議
        sortField = "tl.vote_abs_score ASC,tl.vote_add_score DESC,tl.link_id DESC"
        tableName = "tui_link_for_topic_hot"
    case sortType == golink.ORDER_TYPE_TIME: //最新
        sortField = "tl.link_id desc"
        tableName = "tui_link_for_topic_later"
    case sortType == golink.ORDER_TYPE_VOTE: //得分
        sortField = "tl.vote DESC, tl.link_id DESC"
        tableName = "tui_link_for_topic_vote"
    default: //熱門
        sortField = "tl.reddit_score DESC,tl.link_id DESC"
        tableName = "tui_link_for_topic_top"
    }

    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.click_count, l.comment_count, l.create_time"
    qi.Join = " tl INNER JOIN `link` l ON tl.link_id=l.id"

    if sortType == golink.ORDER_TYPE_CTVL || sortType == golink.ORDER_TYPE_VOTE {
        qi.Where = "tl.topic_id=? AND tl.time_type=?"
        switch {
        case t == "all": //1:全部時間;2:這個小時;3:今天;4:這周;5:這個月;6:今年
            qi.Params = []interface{}{topicId, 1}
        case t == "hour":
            qi.Params = []interface{}{topicId, 2}
        case t == "day":
            qi.Params = []interface{}{topicId, 3}
        case t == "week":
            qi.Params = []interface{}{topicId, 4}
        case t == "month":
            qi.Params = []interface{}{topicId, 5}
        case t == "year":
            qi.Params = []interface{}{topicId, 6}
        default:
            qi.Params = []interface{}{topicId, 1}
        }
    } else {
        qi.Where = "tl.topic_id=?"
        qi.Params = []interface{}{topicId}
    }
    qi.Limit = pagesize
    qi.Offset = pagesize * page
    qi.Order = sortField

    rows, err := db.Select(tableName, 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.ClickCount, &link.CommentCount, &link.CreateTime)
        if err != nil {
            goku.Logger().Errorln(err.Error())
            return nil, err
        }
        links = append(links, link)
    }
    return links, nil
}
開發者ID:yonglehou,項目名稱:ohlala,代碼行數:80,代碼來源:link.go

示例15: LinkForHome_GetByPage

// @page: 從1開始
// @orderType: 排序類型, hot:熱門, hotc:熱議, time:最新, vote:投票得分, ctvl:爭議
// @dataType: 2:熱門;
//            3:爭議[3:全部時間;10:這個小時;11:今天;12:這周;13:這個月;14:今年];
//            [投票時間範圍: 4:全部時間;5:這個小時;6:今天;7:這周;8:這個月;9:今年]
func LinkForHome_GetByPage(orderType string, dataType, page, pagesize int) ([]Link, error) {
    if page < 1 {
        page = 1
    }
    page = page - 1
    if pagesize == 0 {
        pagesize = 20
    }

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

    var rows *sql.Rows
    var err error
    if orderType != golink.ORDER_TYPE_TIME {
        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, l.status"
        qi.Join = " lfh INNER JOIN `link` l ON lfh.link_id=l.id"
        qi.Where = "lfh.data_type=?"
        qi.Limit = pagesize
        qi.Offset = pagesize * page
        switch orderType {
        case golink.ORDER_TYPE_HOTC: // 熱議
            qi.Order = "l.comment_count desc, lfh.link_id desc"
            dataType = 2
        case golink.ORDER_TYPE_CTVL: // 爭議
            qi.Order = "lfh.score DESC,lfh.link_id desc"
            dataType = 3
        case golink.ORDER_TYPE_VOTE: // 得分
            qi.Order = "lfh.score desc, lfh.link_id desc"
            dataType = 4
        default:
            qi.Order = "lfh.score desc, lfh.link_id desc"
            dataType = 2
        }

        qi.Params = []interface{}{dataType}
        rows, err = db.Select("tui_link_for_home", qi)

        if err != nil {
            goku.Logger().Errorln(err.Error())
            return nil, err
        }
        defer rows.Close()
    } else {
        qi := goku.SqlQueryInfo{}
        qi.Fields = "id, user_id, title, context, topics, vote_up, vote_down, view_count, comment_count, create_time, status"
        qi.Where = "status=0"
        qi.Limit = pagesize
        qi.Offset = pagesize * page
        qi.Order = "id desc"

        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
        }
        links = append(links, link)
    }
    return links, nil
}
開發者ID:yonglehou,項目名稱:ohlala,代碼行數:79,代碼來源:link_for_home.go


注:本文中的github.com/QLeelulu/goku.SqlQueryInfo.Params方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。