本文整理汇总了Golang中github.com/leanote/leanote/app/db.UpdateByQMap函数的典型用法代码示例。如果您正苦于以下问题:Golang UpdateByQMap函数的具体用法?Golang UpdateByQMap怎么用?Golang UpdateByQMap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了UpdateByQMap函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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"}, ¬es)
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"}, ¬es)
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}, ¬eTag)
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, ¬es)
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
示例16: Update
func (this *SessionService) Update(sessionId, key string, value interface{}) bool {
return db.UpdateByQMap(db.Sessions, bson.M{"SessionId": sessionId},
bson.M{key: value, "UpdatedTime": time.Now()})
}
开发者ID:ClaudeXin,项目名称:leanote,代码行数:4,代码来源:SessionService.go
示例17: UpdateUserBlogStyle
func (this *BlogService) UpdateUserBlogStyle(userId string, userBlog info.UserBlogStyle) bool {
return db.UpdateByQMap(db.UserBlogs, bson.M{"_id": bson.ObjectIdHex(userId)}, userBlog)
}
开发者ID:ZypcGroup,项目名称:leanote,代码行数:3,代码来源:BlogService.go
示例18: UpdateUserBlogBase
// 修改之UserBlogBase
func (this *BlogService) UpdateUserBlogBase(userId string, userBlog info.UserBlogBase) bool {
ok := db.UpdateByQMap(db.UserBlogs, bson.M{"_id": bson.ObjectIdHex(userId)}, userBlog)
return ok
}
开发者ID:ZypcGroup,项目名称:leanote,代码行数:5,代码来源:BlogService.go
示例19: UpdateLeftIsMin
// 左侧是否隐藏
func (this *UserService) UpdateLeftIsMin(userId string, leftIsMin bool) bool {
return db.UpdateByQMap(db.Users, bson.M{"_id": bson.ObjectIdHex(userId)}, bson.M{"LeftIsMin": leftIsMin})
}
开发者ID:rainkong,项目名称:leanote,代码行数:4,代码来源:UserService.go
示例20: UpdateColumnWidth
// 宽度
func (this *UserService) UpdateColumnWidth(userId string, notebookWidth, noteListWidth, mdEditorWidth int) bool {
return db.UpdateByQMap(db.Users, bson.M{"_id": bson.ObjectIdHex(userId)},
bson.M{"NotebookWidth": notebookWidth, "NoteListWidth": noteListWidth, "MdEditorWidth": mdEditorWidth})
}
开发者ID:rainkong,项目名称:leanote,代码行数:5,代码来源:UserService.go
注:本文中的github.com/leanote/leanote/app/db.UpdateByQMap函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论