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


Golang MysqlDB.Query方法代码示例

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


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

示例1: User_CheckRelationship

// 检查 mUserId 与 sUserId 的关系,
// return:
//      @isFollower: sUserId是否关注mUserId
//      @isFollowed: mUserId是否关注sUserId
//      @isFriend: 是否互相关注
func User_CheckRelationship(mUserId, sUserId int64) (isFollower, isFollowed, isFriend bool) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	rows, err := db.Query("select * from `user_follow` where `user_id`=? and `follow_id`=? limit 1",
		mUserId, sUserId)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return
	}
	defer rows.Close()
	if rows.Next() {
		isFollowed = true
	}

	rows1, err1 := db.Query("select * from `user_follow` where `user_id`=? and `follow_id`=? limit 1",
		sUserId, mUserId)
	if err1 != nil {
		goku.Logger().Errorln(err1.Error())
		return
	}
	defer rows1.Close()
	if rows1.Next() {
		isFollower = true
	}

	if isFollowed && isFollower {
		isFriend = true
	}

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

示例2: thirdPartyUser_SearchOneBy

func thirdPartyUser_SearchOneBy(criteria string, values ...interface{}) (u *ThirdPartyUser) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	sql := "SELECT `user_id`, `third_party`, `third_party_user_id`, `third_party_email`, `access_token`, `refresh_token`, `token_expire_time`, `create_time`, `last_active_time`, `avatar_url`, `link` FROM `third_party_user` WHERE " + criteria + " limit 1"
	thirdPartyUserRow, err := db.Query(sql, values...)
	if err != nil {
		return
	}
	if thirdPartyUserRow == nil {
		return
	}

	if thirdPartyUserRow.Next() {
		u = &ThirdPartyUser{}
		err = thirdPartyUserRow.Scan(
			&u.UserId, &u.ThirdParty, &u.ThirdPartyUserId, &u.ThirdPartyEmail,
			&u.AccessToken, &u.RefreshToken, &u.TokenExpireTime, &u.CreateTime, &u.LastActiveTime, &u.AvatarUrl, &u.Link)
	}

	if err != nil {
		u = nil
	}

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

示例3: delete_tui_link_for_handle

/**
 * 删除tui_link_for_handle已经处理的数据
 */
func delete_tui_link_for_handle(handleTime time.Time, db *goku.MysqlDB) error {

	sql := "DELETE FROM tui_link_for_handle WHERE `insert_time`<=? "
	_, err := db.Query(sql, handleTime)

	return err
}
开发者ID:cloudcache,项目名称:ohlala,代码行数:10,代码来源:push-to-topic-and-home.go

示例4: Del_link_for_topic_all

func Del_link_for_topic_all(db *goku.MysqlDB) error {

	err := del_link_for_topic_later_top("tui_link_for_topic_top", "reddit_score DESC,link_id DESC", db)
	if err == nil {
		err = del_link_for_topic_later_top("tui_link_for_topic_later", "link_id DESC", db)
	}
	if err == nil {
		_, err = db.Query(`DELETE FROM tui_link_for_topic_hot WHERE (time_type=2 AND create_time<?) OR (time_type=3 AND create_time<?) OR 
							(time_type=4 AND create_time<?) OR (time_type=5 AND create_time<?) OR 
			(time_type=6 AND create_time<?)`, utils.ThisHour(), utils.ThisDate(), utils.ThisWeek(), utils.ThisMonth(), utils.ThisYear())
		if err == nil {
			err = del_link_for_topic_hot_vote("tui_link_for_topic_hot", "dispute_score DESC,link_id DESC", db)
		}
	}
	if err == nil {
		_, err = db.Query(`DELETE FROM tui_link_for_topic_vote WHERE (time_type=2 AND create_time<?) OR (time_type=3 AND create_time<?) OR 
							(time_type=4 AND create_time<?) OR (time_type=5 AND create_time<?) OR 
			(time_type=6 AND create_time<?)`, utils.ThisHour(), utils.ThisDate(), utils.ThisWeek(), utils.ThisMonth(), utils.ThisYear())
		if err == nil {
			err = del_link_for_topic_hot_vote("tui_link_for_topic_vote", "vote DESC,link_id DESC", db)
		}
	}

	return err
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:25,代码来源:link_for_topic.go

示例5: link_for_topic_hop_time

/**
 * 链接推送给话题(热议) 2:这个小时;3:今天;4:这周;5:这个月;6:今年
 */
func link_for_topic_hop_time(timeType int, handleTime time.Time, db *goku.MysqlDB) error {

	var t time.Time
	switch {
	case timeType == 2:
		t = utils.ThisHour()
	case timeType == 3:
		t = utils.ThisDate()
	case timeType == 4:
		t = utils.ThisWeek()
	case timeType == 5:
		t = utils.ThisMonth()
	case timeType == 6:
		t = utils.ThisYear()
	}

	sql := `INSERT ignore INTO tui_link_for_topic_hot(topic_id,link_id,create_time,dispute_score,time_type) 
		( 
		SELECT TL.topic_id,H.link_id,H.create_time,L.dispute_score,? AS time_type FROM tui_link_for_handle H 
		INNER JOIN topic_link TL ON H.insert_time<=? AND H.create_time>=? AND H.link_id=TL.link_id
		INNER JOIN link L ON L.id=H.link_id
		);`
	_, err := db.Query(sql, timeType, handleTime, t)

	return err
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:29,代码来源:link_for_topic.go

示例6: UpdateIsRegister

//更新邀请码
func UpdateIsRegister(invite *RegisterInvite) {
	if !golink.Invite_Enabled {
		return
	}
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	db.Query("UPDATE `register_invite` SET `is_register`=1 WHERE `Guid`=?", invite.Guid)

}
开发者ID:cloudcache,项目名称:ohlala,代码行数:11,代码来源:invite.go

示例7: User_RecommendFromTopic

//根据用户关注的话题给它推荐相关的用户
func User_RecommendFromTopic(userId int64) ([]User, error) {
	iRecommendCount := 10
	var db *goku.MysqlDB = GetDB()
	db.Debug = true
	defer db.Close()

	sql := "SELECT `topic_id` FROM `topic_follow` WHERE `user_id`=? ORDER BY `create_time` DESC limit ?"
	topicRows, topicErr := db.Query(sql, userId, iRecommendCount)
	if topicErr != nil {
		return nil, topicErr
	}
	topicIds := make([]int64, 0)
	var topicId int64
	for topicRows.Next() {
		topicErr = topicRows.Scan(&topicId)
		if topicErr == nil {
			topicIds = append(topicIds, topicId)
		}
	}

	hashUsers := map[int64]int64{}
	users := make([]User, 0)
	tLen := len(topicIds)
	var uCount int
	uCount = iRecommendCount / tLen
	strUserIds := fmt.Sprintf("%d", userId)
	hashUsers[userId] = userId
	if tLen > 0 {
		sql = "SELECT u.`id`,u.`name`,u.`email`,u.`description`,u.`user_pic`,u.`friend_count`,u.`topic_count`,u.`ftopic_count`,u.`status`," +
			"u.`follower_count`,u.`link_count`,u.`create_time` FROM `tui_link_for_topic_top` tl INNER JOIN `link` l ON " +
			"tl.`topic_id`=? AND tl.`link_id`=l.`id` AND l.`user_id` NOT IN(?) " +
			"AND NOT EXISTS(SELECT 1 FROM `user_follow` uf WHERE uf.`user_id`=? AND uf.`follow_id`=l.`user_id`) " +
			"INNER JOIN `user` u ON u.`id`=l.`user_id` " +
			"ORDER BY tl.`reddit_score` DESC limit ?"

		for _, tId := range topicIds {
			userRows, userErr := db.Query(sql, tId, strUserIds, userId, uCount)
			if userErr == nil {
				for userRows.Next() {
					user := User{}
					userErr = userRows.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 userErr == nil && hashUsers[userId] <= 0 {
						users = append(users, user)
						strUserIds += fmt.Sprintf(",%d", user.Id)
						hashUsers[user.Id] = user.Id
					}

				}
			}
		}
	}
	//fmt.Print(users)
	return users, nil
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:55,代码来源:user.go

示例8: Link_for_topic_later

/**
 * 链接推送给话题(最新)
 */
func Link_for_topic_later(handleTime time.Time, db *goku.MysqlDB) error {

	sql := `INSERT ignore INTO tui_link_for_topic_later(topic_id,link_id,create_time) 
		( 
		SELECT TL.topic_id,H.link_id,H.create_time FROM tui_link_for_handle H 
		INNER JOIN topic_link TL ON H.data_type=1 AND H.insert_time<=? AND H.link_id=TL.link_id 
		);`
	_, err := db.Query(sql, handleTime)

	return err
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:14,代码来源:link_for_topic.go

示例9: Link_for_home_top

/**
 * 链接推送给网站首页(热门)
 */
func Link_for_home_top(handleTime time.Time, db *goku.MysqlDB) error {

	sql := `INSERT ignore INTO tui_link_for_home(link_id,create_time,data_type,score) 
		( 
		SELECT H.link_id,H.create_time,2,L.reddit_score FROM tui_link_for_handle H 
		INNER JOIN link L ON H.insert_time<=? AND L.id=H.link_id 
		); `

	_, err := db.Query(sql, handleTime)

	return err
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:15,代码来源:link_for_home.go

示例10: Comment_DelById

func Comment_DelById(id int64) error {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	_, err := db.Query("UPDATE `comment` SET status=2 WHERE id=?", id)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return err
	}

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

示例11: UpdateInviteEmailStatus

//更新发送的邀请email状态
func UpdateInviteEmailStatus(emails []*EmailInvite) {

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

	for _, email := range emails {
		if email.SendSuccess == true {
			db.Query("UPDATE register_invite SET is_send=1 WHERE guid=?", email.Guid)
		} else {
			db.Query("UPDATE register_invite SET fail_count=fail_count+1 WHERE guid=?", email.Guid)
		}
	}
}
开发者ID:cloudcache,项目名称:ohlala,代码行数:14,代码来源:invite.go

示例12: del_link_for_home

/** 删除`tui_link_for_home`
 * 热门, whereDataType:data_type=2    orderName:score DESC,link_id DESC
 * 热议, whereDataType:data_type IN(3,10,11,12,13,14)    orderName:score desc,link_id DESC
 * 投票, whereDataType:data_type IN(4,5,6,7,8,9)    orderName:score DESC,link_id DESC
 */
func del_link_for_home(whereDataType string, orderName string, db *goku.MysqlDB) error {

	sql := fmt.Sprintf(`SELECT data_type, tcount - %d AS del_count FROM 
		(SELECT link_id,data_type,COUNT(1) AS tcount FROM tui_link_for_home WHERE %s GROUP BY data_type) T
		WHERE T.tcount>%d;`, LinkMaxCount, whereDataType, LinkMaxCount)

	delSqlCreate := `INSERT ignore INTO tui_link_temporary_delete(id)
		( 
		SELECT link_id FROM tui_link_for_home WHERE data_type=%d ORDER BY ` + orderName + ` LIMIT %d,%d 
		); `
	delSqlDelete := `DELETE T FROM tui_link_temporary_delete D INNER JOIN tui_link_for_home T ON T.data_type=%d
		AND T.link_id=D.id; `

	var delCount int64
	var dataType int
	rows, err := db.Query(sql)
	if err == nil {
		for rows.Next() {
			rows.Scan(&dataType, &delCount)
			db.Query("DELETE FROM tui_link_temporary_delete;")
			db.Query(fmt.Sprintf(delSqlCreate, dataType, LinkMaxCount, delCount))
			db.Query(fmt.Sprintf(delSqlDelete, dataType))
		}
	}

	return err
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:32,代码来源:link_for_home.go

示例13: Topic_CheckFollowByDb

// 检查用户是否已经关注话题,
// @isFollowed: 是否已经关注话题
func Topic_CheckFollowByDb(db *goku.MysqlDB, userId, topicId int64) (isFollowed bool) {

	rows, err := db.Query("select * from `topic_follow` where `user_id`=? and `topic_id`=? limit 1",
		userId, topicId)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return
	}
	defer rows.Close()
	if rows.Next() {
		isFollowed = true
	}

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

示例14: Link_for_home_update

/**
 * 链接推送给网站首页(更新现有数据 )
 */
func Link_for_home_update(handleTime time.Time, db *goku.MysqlDB) error {

	sql := `UPDATE tui_link_for_handle H 
		INNER JOIN tui_link_for_home T ON H.insert_time<=? AND H.data_type=2 AND T.link_id=H.link_id 
		INNER JOIN link L ON L.id=H.link_id 
		SET T.score=CASE WHEN T.data_type=2 THEN L.reddit_score -- 热门 
		WHEN T.data_type=3 THEN L.dispute_score -- 热议
		WHEN T.data_type BETWEEN 10 AND 14 THEN L.dispute_score -- 热议
		ELSE L.vote_up-L.vote_down -- 投票 
		END;`

	_, err := db.Query(sql, handleTime)

	return err
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:18,代码来源:link_for_home.go

示例15: User_IsEmailExist

// 检查email地址是否存在。
// 任何出错都认为email地址存在,防止注册
func User_IsEmailExist(email string) bool {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	rows, err := db.Query("select id from `user` where `email_lower`=? limit 1", strings.ToLower(email))
	if err != nil {
		goku.Logger().Errorln(err.Error())
		// 出错直接认为email存在
		return true
	}
	defer rows.Close()
	if rows.Next() {
		return true
	}
	return false
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:18,代码来源:user.go


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