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


Golang MysqlDB.Close方法代碼示例

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


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

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

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

// userId 取消關注 followId
func User_UnFollow(userId, followId int64) (bool, error) {
	if userId < 1 || followId < 1 {
		return false, errors.New("參數錯誤")
	}
	if userId == followId {
		return false, errors.New("不能取消關注自己")
	}
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	r, err := db.Delete("user_follow", "`user_id`=? AND `follow_id`=?", userId, followId)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return false, err
	}

	var afrow int64
	afrow, err = r.RowsAffected()
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return false, err
	}

	if afrow > 0 {
		LinkForUser_UnFollowUser(userId, followId)
		// 更新粉絲數
		User_IncCount(db, userId, "friend_count", -1)
		// 更新關注數
		User_IncCount(db, followId, "follower_count", -1)
		return true, nil
	}
	return false, nil
}
開發者ID:yonglehou,項目名稱:ohlala,代碼行數:34,代碼來源:user.go

示例4: User_GetByTicket

func User_GetByTicket(ticket string) (*User, error) {
	redisClient := GetRedis()
	defer redisClient.Quit()

	id, err := redisClient.Get(ticket)
	if err != nil {
		return nil, err
	}

	if id.String() == "" {
		return nil, nil
	}

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

	var user *User = new(User)
	err = db.GetStruct(user, "id=?", id.String())
	if err != nil {
		fmt.Printf("err: %v\n", err)
		return nil, err
	}
	if user.Id > 0 {
		return user, nil
	}
	return nil, nil
}
開發者ID:yonglehou,項目名稱:ohlala,代碼行數:27,代碼來源:user.go

示例5: admin_index

func admin_index(ctx *goku.HttpContext) goku.ActionResulter {
	var db *goku.MysqlDB = models.GetDB()
	defer db.Close()

	linkCount, err := db.Count("link", "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["linkCount"] = linkCount

	userCount, err := db.Count("user", "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["userCount"] = userCount

	topicCount, err := db.Count("topic", "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["topicCount"] = topicCount

	commentCount, err := db.Count("comment", "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["commentCount"] = commentCount

	return ctx.View(nil)
}
開發者ID:yonglehou,項目名稱:ohlala,代碼行數:34,代碼來源:index.go

示例6: User_SaveMap

func User_SaveMap(m map[string]interface{}) (sql.Result, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()
	m["email_lower"] = strings.ToLower(m["email"].(string))
	r, err := db.Insert("user", m)
	return r, err
}
開發者ID:t7er,項目名稱:ohlala,代碼行數:7,代碼來源:user.go

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

示例8: SaveUserFavorite

//收藏link
func SaveUserFavorite(f map[string]interface{}) error {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()
	_, err := db.Insert("user_favorite_link", f)

	return err
}
開發者ID:cloudcache,項目名稱:ohlala,代碼行數:8,代碼來源:favorite_link.go

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

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

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

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

示例13: Topic_UnFollow

// 用戶userId 取消關注 話題topicId
func Topic_UnFollow(userId, topicId int64) (bool, error) {
	if userId < 1 || topicId < 1 {
		return false, errors.New("參數錯誤")
	}
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	r, err := db.Delete("topic_follow", "`user_id`=? AND `topic_id`=?", userId, topicId)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return false, err
	}

	var afrow int64
	afrow, err = r.RowsAffected()
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return false, err
	}

	if afrow > 0 {
		// 取消關注話題成功,將話題的鏈接從用戶的推送列表中移除
		LinkForUser_UnFollowTopic(userId, topicId)
		// 更新用戶關注話題的數量
		User_IncCount(db, userId, "ftopic_count", -1)
		// 更新話題的關注用戶數
		Topic_IncCount(db, topicId, "follower_count", -1)
		return true, nil
	}
	return false, nil
}
開發者ID:yonglehou,項目名稱:ohlala,代碼行數:32,代碼來源:topic.go

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

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


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