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


Golang db.UpdateByQMap函數代碼示例

本文整理匯總了Golang中github.com/leanote/leanote/app/db.UpdateByQMap函數的典型用法代碼示例。如果您正苦於以下問題:Golang UpdateByQMap函數的具體用法?Golang UpdateByQMap怎麽用?Golang UpdateByQMap使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: ToBlog

// ToBlog or Not
func (this *NotebookService) ToBlog(userId, notebookId string, isBlog bool) bool {
	// 筆記本
	db.UpdateByIdAndUserIdMap(db.Notebooks, notebookId, userId, bson.M{"IsBlog": isBlog})

	// 更新筆記
	q := bson.M{"UserId": bson.ObjectIdHex(userId),
		"NotebookId": bson.ObjectIdHex(notebookId)}
	data := bson.M{"IsBlog": isBlog}
	if isBlog {
		data["PublicTime"] = time.Now()
	} else {
		data["HasSelfDefined"] = false
	}
	db.UpdateByQMap(db.Notes, q, data)

	// noteContents也更新, 這個就麻煩了, noteContents表沒有NotebookId
	// 先查該notebook下所有notes, 得到id
	notes := []info.Note{}
	db.ListByQWithFields(db.Notes, q, []string{"_id"}, &notes)
	if len(notes) > 0 {
		noteIds := make([]bson.ObjectId, len(notes))
		for i, each := range notes {
			noteIds[i] = each.NoteId
		}
		db.UpdateByQMap(db.NoteContents, bson.M{"_id": bson.M{"$in": noteIds}}, bson.M{"IsBlog": isBlog})
	}

	// 重新計算tags
	go (func() {
		blogService.ReCountBlogTags(userId)
	})()

	return true
}
開發者ID:sunyinhuiCoding,項目名稱:leanote,代碼行數:35,代碼來源:NotebookService.go

示例2: UpdateNotebook

// 更新notebook
func (this *NotebookService) UpdateNotebook(userId, notebookId string, needUpdate bson.M) bool {
	needUpdate["UpdatedTime"] = time.Now()

	// 如果有IsBlog之類的, 需要特殊處理
	if isBlog, ok := needUpdate["IsBlog"]; ok {
		// 設為blog/取消
		if is, ok2 := isBlog.(bool); ok2 {
			q := bson.M{"UserId": bson.ObjectIdHex(userId),
				"NotebookId": bson.ObjectIdHex(notebookId)}
			db.UpdateByQMap(db.Notes, q, bson.M{"IsBlog": is})

			// noteContents也更新, 這個就麻煩了, noteContents表沒有NotebookId
			// 先查該notebook下所有notes, 得到id
			notes := []info.Note{}
			db.ListByQWithFields(db.Notes, q, []string{"_id"}, &notes)
			if len(notes) > 0 {
				noteIds := make([]bson.ObjectId, len(notes))
				for i, each := range notes {
					noteIds[i] = each.NoteId
				}
				db.UpdateByQMap(db.NoteContents, bson.M{"_id": bson.M{"$in": noteIds}}, bson.M{"IsBlog": isBlog})
			}
		}
	}

	return db.UpdateByIdAndUserIdMap(db.Notebooks, notebookId, userId, needUpdate)
}
開發者ID:hello-kukoo,項目名稱:leanote,代碼行數:28,代碼來源:NotebookService.go

示例3: UpdateTplContent

// 更新模板內容
func (this *ThemeService) UpdateTplContent(userId, themeId, filename, content string) (ok bool, msg string) {
	basePath := this.GetThemeAbsolutePath(userId, themeId)
	path := basePath + "/" + filename
	if strings.Contains(filename, ".html") {
		Log(">>")
		if ok, msg = this.ValidateTheme(basePath, filename, content); ok {
			// 模板
			if ok, msg = this.mustTpl(filename, content); ok {
				ok = PutFileStrContent(path, content)
			}
		}
		return
	} else if filename == "theme.json" {
		// 主題配置, 判斷是否是正確的json
		theme, err := this.parseConfig(content)
		if err != nil {
			return false, fmt.Sprintf("%v", err)
		}
		// 正確, 更新theme信息
		ok = db.UpdateByQMap(db.Themes, bson.M{"_id": bson.ObjectIdHex(themeId), "UserId": bson.ObjectIdHex(userId)},
			bson.M{
				"Name":      theme.Name,
				"Version":   theme.Version,
				"Author":    theme.Author,
				"AuthorUrl": theme.AuthorUrl,
				"Info":      theme.Info,
			})
		if ok {
			ok = PutFileStrContent(path, content)
		}
		return
	}
	ok = PutFileStrContent(path, content)
	return
}
開發者ID:ClaudeXin,項目名稱:leanote,代碼行數:36,代碼來源:ThemeService.go

示例4: GetUserId

//-----------
// API
func (this *SessionService) GetUserId(sessionId string) string {
	session := this.Get(sessionId)
	// 更新updateTime, 避免過期
	db.UpdateByQMap(db.Sessions, bson.M{"SessionId": sessionId},
		bson.M{"UpdatedTime": time.Now()})
	return session.UserId
}
開發者ID:ClaudeXin,項目名稱:leanote,代碼行數:9,代碼來源:SessionService.go

示例5: SetRecommend

// 推薦博客
func (this *BlogService) SetRecommend(noteId string, isRecommend bool) bool {
	data := bson.M{"IsRecommend": isRecommend}
	if isRecommend {
		data["RecommendTime"] = time.Now()
	}
	return db.UpdateByQMap(db.Notes, bson.M{"_id": bson.ObjectIdHex(noteId), "IsBlog": true}, data)
}
開發者ID:ZypcGroup,項目名稱:leanote,代碼行數:8,代碼來源:BlogService.go

示例6: DeleteTag

// 刪除標簽
// 也刪除所有的筆記含該標簽的
// 返回noteId => usn
func (this *TagService) DeleteTag(userId string, tag string) map[string]int {
	usn := userService.IncrUsn(userId)
	if db.UpdateByQMap(db.NoteTags, bson.M{"UserId": bson.ObjectIdHex(userId), "Tag": tag}, bson.M{"Usn": usn, "IsDeleted": true}) {
		return noteService.UpdateNoteToDeleteTag(userId, tag)
	}
	return map[string]int{}
}
開發者ID:ClaudeXin,項目名稱:leanote,代碼行數:10,代碼來源:TagService.go

示例7: UpdateUserBlogPaging

// 分頁與排序
func (this *BlogService) UpdateUserBlogPaging(userId string, perPageSize int, sortField string, isAsc bool) (ok bool, msg string) {
	if ok, msg = Vds(map[string]string{"perPageSize": strconv.Itoa(perPageSize), "sortField": sortField}); !ok {
		return
	}
	ok = db.UpdateByQMap(db.UserBlogs, bson.M{"_id": bson.ObjectIdHex(userId)},
		bson.M{"PerPageSize": perPageSize, "SortField": sortField, "IsAsc": isAsc})
	return
}
開發者ID:ZypcGroup,項目名稱:leanote,代碼行數:9,代碼來源:BlogService.go

示例8: ThirdAddUser

//---------
// 第三方添加賬號
func (this *UserService) ThirdAddUser(userId, email, pwd string) (ok bool, msg string) {
	// 判斷email是否存在
	if this.IsExistsUser(email) {
		msg = "該用戶已存在"
		return
	}

	ok = db.UpdateByQMap(db.Users, bson.M{"_id": bson.ObjectIdHex(userId)}, bson.M{"Email": email, "Pwd": Md5(pwd)})
	return
}
開發者ID:hello-kukoo,項目名稱:leanote,代碼行數:12,代碼來源:UserService.go

示例9: updateGlobalConfig

// 通用方法
func (this *ConfigService) updateGlobalConfig(userId, key string, value interface{}, isArr, isMap, isArrMap bool) bool {
	// 判斷是否存在
	if _, ok := this.GlobalAllConfigs[key]; !ok {
		// 需要添加
		config := info.Config{ConfigId: bson.NewObjectId(),
			UserId:      bson.ObjectIdHex(userId),
			Key:         key,
			IsArr:       isArr,
			IsMap:       isMap,
			IsArrMap:    isArrMap,
			UpdatedTime: time.Now(),
		}
		if isArr {
			v, _ := value.([]string)
			config.ValueArr = v
			this.GlobalArrayConfigs[key] = v
		} else if isMap {
			v, _ := value.(map[string]string)
			config.ValueMap = v
			this.GlobalMapConfigs[key] = v
		} else if isArrMap {
			v, _ := value.([]map[string]string)
			config.ValueArrMap = v
			this.GlobalArrMapConfigs[key] = v
		} else {
			v, _ := value.(string)
			config.ValueStr = v
			this.GlobalStringConfigs[key] = v
		}
		return db.Insert(db.Configs, config)
	} else {
		i := bson.M{"UpdatedTime": time.Now()}
		this.GlobalAllConfigs[key] = value
		if isArr {
			v, _ := value.([]string)
			i["ValueArr"] = v
			this.GlobalArrayConfigs[key] = v
		} else if isMap {
			v, _ := value.(map[string]string)
			i["ValueMap"] = v
			this.GlobalMapConfigs[key] = v
		} else if isArrMap {
			v, _ := value.([]map[string]string)
			i["ValueArrMap"] = v
			this.GlobalArrMapConfigs[key] = v
		} else {
			v, _ := value.(string)
			i["ValueStr"] = v
			this.GlobalStringConfigs[key] = v
		}
		return db.UpdateByQMap(db.Configs, bson.M{"UserId": bson.ObjectIdHex(userId), "Key": key}, i)
	}
}
開發者ID:rorovic,項目名稱:leanote,代碼行數:54,代碼來源:ConfigService.go

示例10: UpdateUsername

// 更新username
func (this *UserService) UpdateUsername(userId, username string) (bool, string) {
	if userId == "" || username == "" || username == "admin" { // admin用戶是內置的, 不能設置
		return false, "usernameIsExisted"
	}
	usernameRaw := username // 原先的, 可能是同一個, 但有大小寫
	username = strings.ToLower(username)

	// 先判斷是否存在
	userIdO := bson.ObjectIdHex(userId)
	if db.Has(db.Users, bson.M{"Username": username, "_id": bson.M{"$ne": userIdO}}) {
		return false, "usernameIsExisted"
	}

	ok := db.UpdateByQMap(db.Users, bson.M{"_id": userIdO}, bson.M{"Username": username, "UsernameRaw": usernameRaw})
	return ok, ""
}
開發者ID:rainkong,項目名稱:leanote,代碼行數:17,代碼來源:UserService.go

示例11: DeleteTagApi

// 刪除標簽, 供API調用
func (this *TagService) DeleteTagApi(userId string, tag string, usn int) (ok bool, msg string, toUsn int) {
	noteTag := info.NoteTag{}
	db.GetByQ(db.NoteTags, bson.M{"UserId": bson.ObjectIdHex(userId), "Tag": tag}, &noteTag)

	if noteTag.TagId == "" {
		return false, "notExists", 0
	}
	if noteTag.Usn > usn {
		return false, "conflict", 0
	}
	toUsn = userService.IncrUsn(userId)
	if db.UpdateByQMap(db.NoteTags, bson.M{"UserId": bson.ObjectIdHex(userId), "Tag": tag}, bson.M{"Usn": usn, "IsDeleted": true}) {
		return true, "", toUsn
	}
	return false, "", 0
}
開發者ID:ClaudeXin,項目名稱:leanote,代碼行數:17,代碼來源:TagService.go

示例12: DeleteNotebook

// 查看是否有子notebook
// 先查看該notebookId下是否有notes, 沒有則刪除
func (this *NotebookService) DeleteNotebook(userId, notebookId string) (bool, string) {
	if db.Count(db.Notebooks, bson.M{"ParentNotebookId": bson.ObjectIdHex(notebookId),
		"UserId": bson.ObjectIdHex(userId)}) == 0 { // 無
		if db.Count(db.Notes, bson.M{"NotebookId": bson.ObjectIdHex(notebookId),
			"UserId":  bson.ObjectIdHex(userId),
			"IsTrash": false}) == 0 { // 不包含trash
			// 不是真刪除 1/20, 為了同步筆記本
			ok := db.UpdateByQMap(db.Notebooks, bson.M{"_id": bson.ObjectIdHex(notebookId)}, bson.M{"IsDeleted": true, "Usn": userService.IncrUsn(userId)})
			return ok, ""
			//			return db.DeleteByIdAndUserId(db.Notebooks, notebookId, userId), ""
		}
		return false, "筆記本下有筆記"
	} else {
		return false, "筆記本下有子筆記本"
	}
}
開發者ID:intZz,項目名稱:leanote,代碼行數:18,代碼來源:NotebookService.go

示例13: ActiveEmail

// 注冊後驗證郵箱
func (this *UserService) ActiveEmail(token string) (ok bool, msg, email string) {
	tokenInfo := info.Token{}
	if ok, msg, tokenInfo = tokenService.VerifyToken(token, info.TokenActiveEmail); ok {
		// 修改之後的郵箱
		email = tokenInfo.Email
		userInfo := this.GetUserInfoByEmail(email)
		if userInfo.UserId == "" {
			ok = false
			msg = "不存在該用戶"
			return
		}

		// 修改之, 並將verified = true
		ok = db.UpdateByQMap(db.Users, bson.M{"_id": userInfo.UserId}, bson.M{"Verified": true})
		return
	}

	ok = false
	msg = "該鏈接已過期"
	return
}
開發者ID:rainkong,項目名稱:leanote,代碼行數:22,代碼來源:UserService.go

示例14: UpdateEmail

// 修改郵箱
// 在此之前, 驗證token是否過期
// 驗證email是否有人注冊了
func (this *UserService) UpdateEmail(token string) (ok bool, msg, email string) {
	tokenInfo := info.Token{}
	if ok, msg, tokenInfo = tokenService.VerifyToken(token, info.TokenUpdateEmail); ok {
		// 修改之後的郵箱
		email = tokenInfo.Email
		// 先驗證該email是否被注冊了
		if userService.IsExistsUser(email) {
			ok = false
			msg = "該郵箱已注冊"
			return
		}

		// 修改之, 並將verified = true
		ok = db.UpdateByQMap(db.Users, bson.M{"_id": tokenInfo.UserId}, bson.M{"Email": email, "Verified": true})
		return
	}

	ok = false
	msg = "該鏈接已過期"
	return
}
開發者ID:rainkong,項目名稱:leanote,代碼行數:24,代碼來源:UserService.go

示例15: UpdateNoteToDeleteTag

// 刪除tag
// 返回所有note的Usn
func (this *NoteService) UpdateNoteToDeleteTag(userId string, targetTag string) map[string]int {
	query := bson.M{"UserId": bson.ObjectIdHex(userId),
		"Tags": bson.M{"$in": []string{targetTag}}}
	notes := []info.Note{}
	db.ListByQ(db.Notes, query, &notes)
	ret := map[string]int{}
	for _, note := range notes {
		tags := note.Tags
		if tags == nil {
			continue
		}
		for i, tag := range tags {
			if tag == targetTag {
				tags = tags
				tags = append(tags[:i], tags[i+1:]...)
				break
			}
		}
		usn := userService.IncrUsn(userId)
		db.UpdateByQMap(db.Notes, bson.M{"_id": note.NoteId}, bson.M{"Usn": usn, "Tags": tags})
		ret[note.NoteId.Hex()] = usn
	}
	return ret
}
開發者ID:ClaudeXin,項目名稱:leanote,代碼行數:26,代碼來源:NoteService.go


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