• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang db.Delete函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/leanote/leanote/app/db.Delete函数的典型用法代码示例。如果您正苦于以下问题:Golang Delete函数的具体用法?Golang Delete怎么用?Golang Delete使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: LikeBlog

// 点赞
// retun ok , isLike
func (this *BlogService) LikeBlog(noteId, userId string) (ok bool, isLike bool) {
	ok = false
	isLike = false
	if noteId == "" || userId == "" {
		return
	}
	// 判断是否点过赞, 如果点过那么取消点赞
	note := noteService.GetNoteById(noteId)
	if !note.IsBlog /*|| note.UserId.Hex() == userId */ {
		return
	}

	noteIdO := bson.ObjectIdHex(noteId)
	userIdO := bson.ObjectIdHex(userId)
	var n int
	if !db.Has(db.BlogLikes, bson.M{"NoteId": noteIdO, "UserId": userIdO}) {
		n = 1
		// 添加之
		db.Insert(db.BlogLikes, info.BlogLike{LikeId: bson.NewObjectId(), NoteId: noteIdO, UserId: userIdO, CreatedTime: time.Now()})
		isLike = true
	} else {
		// 已点过, 那么删除之
		n = -1
		db.Delete(db.BlogLikes, bson.M{"NoteId": noteIdO, "UserId": userIdO})
		isLike = false
	}
	ok = db.Update(db.Notes, bson.M{"_id": noteIdO}, bson.M{"$inc": bson.M{"LikeNum": n}})

	return
}
开发者ID:ZypcGroup,项目名称:leanote,代码行数:32,代码来源:BlogService.go


示例2: DeleteAttach

// delete attach
func (this *AttachService) DeleteAttach(attachId, userId string) (bool, string) {
	attach := info.Attach{}
	db.Get(db.Attachs, attachId, &attach)
	
	if(attach.AttachId != "") {
		// 判断是否有权限为笔记添加附件
		if !shareService.HasUpdateNotePerm(attach.NoteId.Hex(), userId) {
			return false, "No Perm"
		}
		
		if db.Delete(db.Attachs, bson.M{"_id": bson.ObjectIdHex(attachId)}) {
			this.updateNoteAttachNum(attach.NoteId, -1)
			attach.Path = strings.TrimLeft(attach.Path, "/")
			err := os.Remove(revel.BasePath + "/" + attach.Path)
			if err == nil {
				// userService.UpdateAttachSize(note.UserId.Hex(), -attach.Size)
				// 修改note Usn
				noteService.IncrNoteUsn(attach.NoteId.Hex(), userId)
				
				return true, "delete file success"
			}
			return false, "delete file error"
		}
		return false, "db error"
	}
	return false, "no such item"
}
开发者ID:intZz,项目名称:leanote,代码行数:28,代码来源:AttachService.go


示例3: DeleteUser

// 删除用户
func (this *GroupService) DeleteUser(ownUserId, groupId, userId string) (ok bool, msg string) {
	// groupId是否是ownUserId的?
	if !this.isMyGroup(ownUserId, groupId) {
		return false, "forbidden"
	}
	return db.Delete(db.GroupUsers, bson.M{"GroupId": bson.ObjectIdHex(groupId), "UserId": bson.ObjectIdHex(userId)}), ""
}
开发者ID:sunyinhuiCoding,项目名称:leanote,代码行数:8,代码来源:GroupService.go


示例4: DeleteUser

// 删除用户
func (this *GroupService) DeleteUser(ownUserId, groupId, userId string) (ok bool, msg string) {
	// groupId是否是ownUserId的?
	/*
		if !this.IsExistsGroupUser(ownUserId, groupId) {
			return false, "forbiddenNotMyGroup"
		}
	*/
	if !this.isMyGroup(ownUserId, groupId) {
		return false, "forbiddenNotMyGroup"
	}

	// 删除该用户分享到本组的笔记本, 笔记
	shareService.DeleteShareNotebookGroupWhenDeleteGroupUser(userId, groupId)
	shareService.DeleteShareNoteGroupWhenDeleteGroupUser(userId, groupId)

	return db.Delete(db.GroupUsers, bson.M{"GroupId": bson.ObjectIdHex(groupId), "UserId": bson.ObjectIdHex(userId)}), ""
}
开发者ID:ClaudeXin,项目名称:leanote,代码行数:18,代码来源:GroupService.go


示例5: AddShareNoteToUserId

// 第三方测试没有userId
func (this *ShareService) AddShareNoteToUserId(noteId string, perm int, userId, toUserId string) (bool, string, string) {
	// 添加一条记录说明两者存在关系
	this.AddHasShareNote(userId, toUserId)

	// 先删除之
	db.Delete(db.ShareNotes, bson.M{"NoteId": bson.ObjectIdHex(noteId),
		"UserId":   bson.ObjectIdHex(userId),
		"ToUserId": bson.ObjectIdHex(toUserId),
	})

	shareNote := info.ShareNote{NoteId: bson.ObjectIdHex(noteId),
		UserId:      bson.ObjectIdHex(userId),
		ToUserId:    bson.ObjectIdHex(toUserId),
		Perm:        perm,
		CreatedTime: time.Now(),
	}
	return db.Insert(db.ShareNotes, shareNote), "", toUserId
}
开发者ID:howardroark2018,项目名称:leanote-all,代码行数:19,代码来源:ShareService.go


示例6: DeleteComment

// 作者(或管理员)可以删除所有评论
// 自己可以删除评论
func (this *BlogService) DeleteComment(noteId, commentId, userId string) bool {
	note := noteService.GetNoteById(noteId)
	if !note.IsBlog {
		return false
	}

	comment := info.BlogComment{}
	db.Get(db.BlogComments, commentId, &comment)

	if comment.CommentId == "" {
		return false
	}

	if userId == configService.GetAdminUserId() || note.UserId.Hex() == userId || comment.UserId.Hex() == userId {
		if db.Delete(db.BlogComments, bson.M{"_id": bson.ObjectIdHex(commentId)}) {
			// 评论-1
			db.Update(db.Notes, bson.M{"_id": bson.ObjectIdHex(noteId)}, bson.M{"$inc": bson.M{"CommentNum": -1}})
			return true
		}
	}

	return false
}
开发者ID:ZypcGroup,项目名称:leanote,代码行数:25,代码来源:BlogService.go


示例7: AddShareNote

/*
func (this *ShareService) AddShareNote(shareNote info.ShareNote) bool {
	shareNote.CreatedTime = time.Now()
	return db.Insert(db.ShareNotes, shareNote)
}
*/
func (this *ShareService) AddShareNote(noteId string, perm int, userId, email string) (bool, string, string) {
	// 通过email得到被共享的userId
	toUserId := userService.GetUserId(email)
	if toUserId == "" {
		return false, "无该用户", ""
	}

	// 添加一条记录说明两者存在关系
	this.AddHasShareNote(userId, toUserId)

	// 先删除之
	db.Delete(db.ShareNotes, bson.M{"NoteId": bson.ObjectIdHex(noteId),
		"UserId":   bson.ObjectIdHex(userId),
		"ToUserId": bson.ObjectIdHex(toUserId),
	})

	shareNote := info.ShareNote{NoteId: bson.ObjectIdHex(noteId),
		UserId:      bson.ObjectIdHex(userId),
		ToUserId:    bson.ObjectIdHex(toUserId),
		Perm:        perm,
		CreatedTime: time.Now(),
	}
	return db.Insert(db.ShareNotes, shareNote), "", toUserId
}
开发者ID:sunyinhuiCoding,项目名称:leanote,代码行数:30,代码来源:ShareService.go


示例8: DeleteShareNotebookGroup

// 删除
func (this *ShareService) DeleteShareNotebookGroup(userId, notebookId, groupId string) bool {
	return db.Delete(db.ShareNotebooks, bson.M{"NotebookId": bson.ObjectIdHex(notebookId),
		"UserId":    bson.ObjectIdHex(userId),
		"ToGroupId": bson.ObjectIdHex(groupId),
	})
}
开发者ID:sunyinhuiCoding,项目名称:leanote,代码行数:7,代码来源:ShareService.go


示例9: DeleteShareNoteGroupWhenDeleteGroupUser

func (this *ShareService) DeleteShareNoteGroupWhenDeleteGroupUser(userId, groupId string) bool {
	return db.Delete(db.ShareNotes, bson.M{
		"UserId":    bson.ObjectIdHex(userId),
		"ToGroupId": bson.ObjectIdHex(groupId),
	})
}
开发者ID:howardroark2018,项目名称:leanote-all,代码行数:6,代码来源:ShareService.go


示例10: DeleteAllShareNoteGroup

func (this *ShareService) DeleteAllShareNoteGroup(groupId string) bool {
	return db.Delete(db.ShareNotes, bson.M{
		"ToGroupId": bson.ObjectIdHex(groupId),
	})
}
开发者ID:howardroark2018,项目名称:leanote-all,代码行数:5,代码来源:ShareService.go


示例11: DeleteTheme

// 删除主题
func (this *ThemeService) DeleteTheme(userId, themeId string) (ok bool) {
	return db.Delete(db.Themes, bson.M{"_id": bson.ObjectIdHex(themeId), "UserId": bson.ObjectIdHex(userId), "IsActive": false})
}
开发者ID:ClaudeXin,项目名称:leanote,代码行数:4,代码来源:ThemeService.go


示例12: Clear

// 注销时清空session
func (this *SessionService) Clear(sessionId string) bool {
	return db.Delete(db.Sessions, bson.M{"SessionId": sessionId})
}
开发者ID:ClaudeXin,项目名称:leanote,代码行数:4,代码来源:SessionService.go


示例13: DeleteToken

// 删除token
func (this *TokenService) DeleteToken(userId string, tokenType int) bool {
	return db.Delete(db.Tokens, bson.M{"_id": bson.ObjectIdHex(userId), "Type": tokenType})
}
开发者ID:hello-kukoo,项目名称:leanote,代码行数:4,代码来源:TokenService.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang db.DeleteAll函数代码示例发布时间:2022-05-23
下一篇:
Golang db.Count函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap