本文整理匯總了Golang中github.com/QLeelulu/goku.MysqlDB.InsertStruct方法的典型用法代碼示例。如果您正苦於以下問題:Golang MysqlDB.InsertStruct方法的具體用法?Golang MysqlDB.InsertStruct怎麽用?Golang MysqlDB.InsertStruct使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/QLeelulu/goku.MysqlDB
的用法示例。
在下文中一共展示了MysqlDB.InsertStruct方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Topic_SaveTopics
// 保持topic到數據庫,同時建立topic與link的關係表
// 如果topic已經存在,則直接建立與link的關聯
// 全部成功則返回true
func Topic_SaveTopics(topics string, linkId int64) bool {
if topics == "" {
return true
}
var db *goku.MysqlDB = GetDB()
defer db.Close()
success := true
topicList := strings.Split(topics, ",")
for _, topic := range topicList {
topicLower := strings.ToLower(topic)
t := new(Topic)
err := db.GetStruct(t, "`name_lower`=?", topic)
if err != nil {
goku.Logger().Logln(topic)
goku.Logger().Errorln(err.Error())
success = false
continue
}
if t.Id < 1 {
t.Name = topic
t.NameLower = topicLower
_, err = db.InsertStruct(t)
if err != nil {
goku.Logger().Errorln(err.Error())
success = false
continue
}
}
if t.Id > 0 && linkId > 0 {
_, err = db.Insert("topic_link", map[string]interface{}{"topic_id": t.Id, "link_id": linkId})
if err != nil {
goku.Logger().Errorln(err.Error())
success = false
} else {
// 成功,更新話題的鏈接數量統計
Topic_IncCount(db, t.Id, "link_count", 1)
redisClient := GetRedis()
defer redisClient.Quit()
// 加入推送隊列
// 格式: pushtype,topicid,linkid,timestamp
qv := fmt.Sprintf("%v,%v,%v,%v", LinkForUser_ByTopic, t.Id, linkId, time.Now().Unix())
_, err = redisClient.Lpush(golink.KEY_LIST_PUSH_TO_USER, qv)
if err != nil {
goku.Logger().Errorln(err.Error())
}
}
}
}
return success
}
示例2: saveRegisterInvite
//保存一個邀請
func saveRegisterInvite(userId int64, toEmail string, db *goku.MysqlDB) (string, error) {
if userId <= int64(0) || toEmail == "" {
return "", errors.New("用戶id不合法")
}
invite := new(RegisterInvite)
invite.Guid = utils.GeneticKey()
invite.UserId = userId
invite.ToEmail = toEmail
invite.IsRegister = false
invite.ExpiredDate = time.Now().AddDate(0, 0, golink.Register_Invite_Expired_Day)
invite.IsSend = false
invite.FailCount = 0
_, err := db.InsertStruct(invite)
return invite.Guid, err
}
示例3: CreateRegisterInviteWithoutEmail
//獲取一個邀請碼(非郵件邀請方式,可能是通過qq和微薄發送)
func CreateRegisterInviteWithoutEmail(userId int64) (string, error) {
if userId <= int64(0) {
return "", errors.New("用戶id不合法")
}
var db *goku.MysqlDB = GetDB()
defer db.Close()
invite := new(RegisterInvite)
invite.Guid = utils.GeneticKey()
invite.UserId = userId
invite.ToEmail = ""
invite.IsRegister = false
invite.ExpiredDate = time.Now().AddDate(0, 0, golink.Register_Invite_Expired_Day)
invite.IsSend = true
invite.FailCount = 0
_, err := db.InsertStruct(invite)
return invite.Guid, err
}