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

Golang db.Count函数代码示例

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

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



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

示例1: 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
			return db.DeleteByIdAndUserId(db.Notebooks, notebookId, userId), ""
		}
		return false, "笔记本下有笔记"
	} else {
		return false, "笔记本下有子笔记本"
	}
}
开发者ID:sunyinhuiCoding,项目名称:leanote,代码行数:15,代码来源:NotebookService.go


示例2: ReCountNotebookNumberNotes

// 重新统计笔记本下的笔记数目
// noteSevice: AddNote, CopyNote, CopySharedNote, MoveNote
// trashService: DeleteNote (recove不用, 都统一在MoveNote里了)
func (this *NotebookService) ReCountNotebookNumberNotes(notebookId string) bool {
	notebookIdO := bson.ObjectIdHex(notebookId)
	count := db.Count(db.Notes, bson.M{"NotebookId": notebookIdO, "IsTrash": false})
	Log(count)
	Log(notebookId)
	return db.UpdateByQField(db.Notebooks, bson.M{"_id": notebookIdO}, "NumberNotes", count)
}
开发者ID:sunyinhuiCoding,项目名称:leanote,代码行数:10,代码来源:NotebookService.go


示例3: ListImagesWithPage

// list images
// if albumId == "" get default album images
func (this *FileService) ListImagesWithPage(userId, albumId, key string, pageNumber, pageSize int) info.Page {
	skipNum, sortFieldR := parsePageAndSort(pageNumber, pageSize, "CreatedTime", false)
	files := []info.File{}

	q := bson.M{"UserId": bson.ObjectIdHex(userId), "Type": ""} // life
	if albumId != "" {
		q["AlbumId"] = bson.ObjectIdHex(albumId)
	} else {
		q["IsDefaultAlbum"] = true
	}
	if key != "" {
		q["Title"] = bson.M{"$regex": bson.RegEx{".*?" + key + ".*", "i"}}
	}

	//	LogJ(q)

	count := db.Count(db.Files, q)

	db.Files.
		Find(q).
		Sort(sortFieldR).
		Skip(skipNum).
		Limit(pageSize).
		All(&files)

	return info.Page{Count: count, List: files}
}
开发者ID:sunyinhuiCoding,项目名称:leanote,代码行数:29,代码来源:FileService.go


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


示例5: CountBlog

func (this *NoteService) CountBlog(userId string) int {
	q := bson.M{"IsBlog": true, "IsTrash": false, "IsDeleted": false}
	if userId != "" {
		q["UserId"] = bson.ObjectIdHex(userId)
	}
	return db.Count(db.Notes, q)
}
开发者ID:ClaudeXin,项目名称:leanote,代码行数:7,代码来源:NoteService.go


示例6: CountNote

//------------
// 统计
func (this *NoteService) CountNote(userId string) int {
	q := bson.M{"IsTrash": false}
	if userId != "" {
		q["UserId"] = bson.ObjectIdHex(userId)
	}
	return db.Count(db.Notes, q)
}
开发者ID:sunyinhuiCoding,项目名称:leanote,代码行数:9,代码来源:NoteService.go


示例7: DeleteAlbum

// delete album
// presupposition: has no images under this ablum
func (this *AlbumService) DeleteAlbum(userId, albumId string) (bool, string) {
	if db.Count(db.Files, bson.M{"AlbumId": bson.ObjectIdHex(albumId),
		"UserId": bson.ObjectIdHex(userId),
	}) == 0 {
		return db.DeleteByIdAndUserId(db.Albums, albumId, userId), ""
	}
	return false, "has images"
}
开发者ID:kevinhuo88888,项目名称:leanote,代码行数:10,代码来源:AlbumService.go


示例8: CountNoteByTag

// 通过标签来查询
func (this *NoteService) CountNoteByTag(userId string, tag string) int {
	if tag == "" {
		return 0
	}
	query := bson.M{"UserId": bson.ObjectIdHex(userId),
		//		"IsTrash": false,
		"IsDeleted": false,
		"Tags":      bson.M{"$in": []string{tag}}}
	return db.Count(db.Notes, query)
}
开发者ID:ClaudeXin,项目名称:leanote,代码行数:11,代码来源:NoteService.go


示例9: updateNoteAttachNum

// 更新笔记的附件个数
// addNum 1或-1
func (this *AttachService) updateNoteAttachNum(noteId bson.ObjectId, addNum int) bool {
	num := db.Count(db.Attachs, bson.M{"NoteId": noteId})
	/*
		note := info.Note{}
		note = noteService.GetNoteById(noteId.Hex())
		note.AttachNum += addNum
		if note.AttachNum < 0 {
			note.AttachNum = 0
		}
		Log(note.AttachNum)
	*/
	return db.UpdateByQField(db.Notes, bson.M{"_id": noteId}, "AttachNum", num)
}
开发者ID:sunyinhuiCoding,项目名称:leanote,代码行数:15,代码来源:AttachService.go


示例10: IsExistsUserByUsername

// 是否存在该用户 username
func (this *UserService) IsExistsUserByUsername(username string) bool {
	return db.Count(db.Users, bson.M{"Username": username}) >= 1
}
开发者ID:rainkong,项目名称:leanote,代码行数:4,代码来源:UserService.go


示例11: CountUser

// 统计
func (this *UserService) CountUser() int {
	return db.Count(db.Users, bson.M{})
}
开发者ID:rainkong,项目名称:leanote,代码行数:4,代码来源:UserService.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang db.Delete函数代码示例发布时间:2022-05-23
下一篇:
Golang opencv.IplImage类代码示例发布时间: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