当前位置: 首页>>代码示例>>Golang>>正文


Golang db.ListByQ函数代码示例

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


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

示例1: MapUserAndBlogByUserIds

// 返回info.UserAndBlog
func (this *UserService) MapUserAndBlogByUserIds(userIds []bson.ObjectId) map[string]info.UserAndBlog {
	users := []info.User{}
	db.ListByQ(db.Users, bson.M{"_id": bson.M{"$in": userIds}}, &users)

	userBlogs := []info.UserBlog{}
	db.ListByQ(db.UserBlogs, bson.M{"_id": bson.M{"$in": userIds}}, &userBlogs)

	userBlogMap := make(map[bson.ObjectId]info.UserBlog, len(userBlogs))
	for _, user := range userBlogs {
		userBlogMap[user.UserId] = user
	}

	userAndBlogMap := make(map[string]info.UserAndBlog, len(users))

	for _, user := range users {
		this.setUserLogo(&user)

		userBlog, ok := userBlogMap[user.UserId]
		if !ok {
			continue
		}

		userAndBlogMap[user.UserId.Hex()] = info.UserAndBlog{
			UserId:    user.UserId,
			Username:  user.Username,
			Email:     user.Email,
			Logo:      user.Logo,
			BlogTitle: userBlog.Title,
			BlogLogo:  userBlog.Logo,
			BlogUrl:   blogService.GetUserBlogUrl(&userBlog, user.Username),
		}
	}
	return userAndBlogMap
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:35,代码来源:UserService.go

示例2: GetNotebookShareGroups

// 得到笔记本分享给的groups
func (this *ShareService) GetNotebookShareGroups(notebookId, userId string) []info.ShareNotebook {
	groups := groupService.GetGroupsContainOf(userId)

	// 得到有分享的分组
	shares := []info.ShareNotebook{}
	db.ListByQ(db.ShareNotebooks,
		bson.M{"NotebookId": bson.ObjectIdHex(notebookId), "UserId": bson.ObjectIdHex(userId), "ToGroupId": bson.M{"$exists": true}}, &shares)
	mapShares := map[bson.ObjectId]info.ShareNotebook{}
	for _, share := range shares {
		mapShares[share.ToGroupId] = share
	}
	LogJ(shares)

	// 所有的groups都有share, 但没有share的group没有shareId
	shares2 := make([]info.ShareNotebook, len(groups))
	for i, group := range groups {
		share, ok := mapShares[group.GroupId]
		if !ok {
			share = info.ShareNotebook{}
		}
		share.ToGroup = group
		shares2[i] = share
	}

	return shares2
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:27,代码来源:ShareService.go

示例3: ListBlogNotebooks

// 得到用户共享的notebooks
// 3/19 博客不是deleted
func (this *BlogService) ListBlogNotebooks(userId string) []info.Notebook {
	notebooks := []info.Notebook{}
	orQ := []bson.M{
		bson.M{"IsDeleted": false},
		bson.M{"IsDeleted": bson.M{"$exists": false}},
	}
	db.ListByQ(db.Notebooks, bson.M{"UserId": bson.ObjectIdHex(userId), "IsBlog": true, "$or": orQ}, &notebooks)
	return notebooks
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:11,代码来源:BlogService.go

示例4: getImagesByNoteIds

func (this *NoteImageService) getImagesByNoteIds(noteIds []bson.ObjectId) map[string][]info.File {
	noteNoteImages := []info.NoteImage{}
	db.ListByQ(db.NoteImages, bson.M{"NoteId": bson.M{"$in": noteIds}}, &noteNoteImages)

	// 得到imageId, 再去files表查所有的Files
	imageIds := []bson.ObjectId{}

	// 图片1 => N notes
	imageIdNotes := map[string][]string{} // imageId => [noteId1, noteId2, ...]
	for _, noteImage := range noteNoteImages {
		imageId := noteImage.ImageId
		imageIds = append(imageIds, imageId)

		imageIdHex := imageId.Hex()
		noteId := noteImage.NoteId.Hex()
		if notes, ok := imageIdNotes[imageIdHex]; ok {
			imageIdNotes[imageIdHex] = append(notes, noteId)
		} else {
			imageIdNotes[imageIdHex] = []string{noteId}
		}
	}

	// 得到所有files
	files := []info.File{}
	db.ListByQ(db.Files, bson.M{"_id": bson.M{"$in": imageIds}}, &files)

	// 建立note->file关联
	noteImages := make(map[string][]info.File)
	for _, file := range files {
		fileIdHex := file.FileId.Hex() // == imageId
		// 这个fileIdHex有哪些notes呢?
		if notes, ok := imageIdNotes[fileIdHex]; ok {
			for _, noteId := range notes {
				if files, ok2 := noteImages[noteId]; ok2 {
					noteImages[noteId] = append(files, file)
				} else {
					noteImages[noteId] = []info.File{file}
				}
			}
		}
	}
	return noteImages
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:43,代码来源:NoteImageService.go

示例5: MapUserInfoByUserIds

// 用户信息即可
func (this *UserService) MapUserInfoByUserIds(userIds []bson.ObjectId) map[bson.ObjectId]info.User {
	users := []info.User{}
	db.ListByQ(db.Users, bson.M{"_id": bson.M{"$in": userIds}}, &users)

	userMap := make(map[bson.ObjectId]info.User, len(users))
	for _, user := range users {
		this.setUserLogo(&user)
		userMap[user.UserId] = user
	}
	return userMap
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:12,代码来源:UserService.go

示例6: UpgradeBlog

// 添加了PublicTime, RecommendTime
func (this *UpgradeService) UpgradeBlog() bool {
	notes := []info.Note{}
	db.ListByQ(db.Notes, bson.M{"IsBlog": true}, &notes)

	// PublicTime, RecommendTime = UpdatedTime
	for _, note := range notes {
		if note.IsBlog && note.PublicTime.Year() < 100 {
			db.UpdateByIdAndUserIdMap2(db.Notes, note.NoteId, note.UserId, bson.M{"PublicTime": note.UpdatedTime, "RecommendTime": note.UpdatedTime})
			Log(note.NoteId.Hex())
		}
	}

	return true
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:15,代码来源:UpgradeService.go

示例7: getAttachsByNoteIds

// api调用, 通过noteIds得到note's attachs, 通过noteId归类返回
func (this *AttachService) getAttachsByNoteIds(noteIds []bson.ObjectId) map[string][]info.Attach {
	attachs := []info.Attach{}
	db.ListByQ(db.Attachs, bson.M{"NoteId": bson.M{"$in": noteIds}}, &attachs)
	noteAttchs := make(map[string][]info.Attach)
	for _, attach := range attachs {
		noteId := attach.NoteId.Hex()
		if itAttachs, ok := noteAttchs[noteId]; ok {
			noteAttchs[noteId] = append(itAttachs, attach)
		} else {
			noteAttchs[noteId] = []info.Attach{attach}
		}
	}
	return noteAttchs
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:15,代码来源:AttachService.go

示例8: DeleteAllAttachs

// Delete note to delete attas firstly
func (this *AttachService) DeleteAllAttachs(noteId, userId string) bool {
	note := noteService.GetNoteById(noteId)
	if note.UserId.Hex() == userId {
		attachs := []info.Attach{}
		db.ListByQ(db.Attachs, bson.M{"NoteId": bson.ObjectIdHex(noteId)}, &attachs)
		for _, attach := range attachs {
			attach.Path = strings.TrimLeft(attach.Path, "/")
			//modified by JacobXie
			if qiniuService.IsUseQiniu() {
				qiniuService.DeleteOnQiniu(attach.Path)
			} else {
				os.Remove(revel.BasePath + "/" + attach.Path)
			}
		}
		return true
	}

	return false
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:20,代码来源:AttachService.go

示例9: GetUserInfosOrderBySeq

// 通过ids得到users, 按id的顺序组织users
func (this *UserService) GetUserInfosOrderBySeq(userIds []bson.ObjectId) []info.User {
	users := []info.User{}
	db.ListByQ(db.Users, bson.M{"_id": bson.M{"$in": userIds}}, &users)

	usersMap := map[bson.ObjectId]info.User{}
	for _, user := range users {
		usersMap[user.UserId] = user
	}

	hasAppend := map[bson.ObjectId]bool{} // 为了防止userIds有重复的
	users2 := []info.User{}
	for _, userId := range userIds {
		if user, ok := usersMap[userId]; ok && !hasAppend[userId] {
			hasAppend[userId] = true
			users2 = append(users2, user)
		}
	}
	return users2
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:20,代码来源:UserService.go

示例10: ListAttachs

// list attachs
func (this *AttachService) ListAttachs(noteId, userId string) []info.Attach {
	attachs := []info.Attach{}

	// 判断是否有权限为笔记添加附件, userId为空时表示是分享笔记的附件
	if userId != "" && !shareService.HasUpdateNotePerm(noteId, userId) {
		return attachs
	}

	// 笔记是否是自己的
	note := noteService.GetNoteByIdAndUserId(noteId, userId)
	if note.NoteId == "" {
		return attachs
	}

	// TODO 这里, 优化权限控制

	db.ListByQ(db.Attachs, bson.M{"NoteId": bson.ObjectIdHex(noteId)}, &attachs)

	return attachs
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:21,代码来源:AttachService.go

示例11: InitGlobalConfigs

// appStart时 将全局的配置从数据库中得到作为全局
func (this *ConfigService) InitGlobalConfigs() bool {
	this.GlobalAllConfigs = map[string]interface{}{}
	this.GlobalStringConfigs = map[string]string{}
	this.GlobalArrayConfigs = map[string][]string{}
	this.GlobalMapConfigs = map[string]map[string]string{}
	this.GlobalArrMapConfigs = map[string][]map[string]string{}

	this.adminUsername, _ = revel.Config.String("adminUsername")
	if this.adminUsername == "" {
		this.adminUsername = "admin"
	}
	this.siteUrl, _ = revel.Config.String("site.url")

	userInfo := userService.GetUserInfoByAny(this.adminUsername)
	if userInfo.UserId == "" {
		return false
	}
	this.adminUserId = userInfo.UserId.Hex()

	configs := []info.Config{}
	db.ListByQ(db.Configs, bson.M{"UserId": userInfo.UserId}, &configs)

	for _, config := range configs {
		if config.IsArr {
			this.GlobalArrayConfigs[config.Key] = config.ValueArr
			this.GlobalAllConfigs[config.Key] = config.ValueArr
		} else if config.IsMap {
			this.GlobalMapConfigs[config.Key] = config.ValueMap
			this.GlobalAllConfigs[config.Key] = config.ValueMap
		} else if config.IsArrMap {
			this.GlobalArrMapConfigs[config.Key] = config.ValueArrMap
			this.GlobalAllConfigs[config.Key] = config.ValueArrMap
		} else {
			this.GlobalStringConfigs[config.Key] = config.ValueStr
			this.GlobalAllConfigs[config.Key] = config.ValueStr
		}
	}

	return true
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:41,代码来源:ConfigService.go

示例12: GetGroupsContainOf

// 获取包含此用户的组对象数组
// 获取该用户所属组, 和我的组
func (this *GroupService) GetGroupsContainOf(userId string) []info.Group {
	// 我的组
	myGroups := this.GetGroups(userId)
	myGroupMap := map[bson.ObjectId]bool{}

	for _, group := range myGroups {
		myGroupMap[group.GroupId] = true
	}

	// 所属组
	groupIds := this.GetBelongToGroupIds(userId)

	groups := []info.Group{}
	db.ListByQ(db.Groups, bson.M{"_id": bson.M{"$in": groupIds}}, &groups)

	for _, group := range groups {
		if !myGroupMap[group.GroupId] {
			myGroups = append(myGroups, group)
		}
	}

	return myGroups
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:25,代码来源:GroupService.go

示例13: CopyAttachs

// 复制笔记时需要复制附件
// noteService调用, 权限已判断
func (this *AttachService) CopyAttachs(noteId, toNoteId, toUserId string) bool {
	attachs := []info.Attach{}
	db.ListByQ(db.Attachs, bson.M{"NoteId": bson.ObjectIdHex(noteId)}, &attachs)

	// 复制之
	toNoteIdO := bson.ObjectIdHex(toNoteId)
	for _, attach := range attachs {
		attach.AttachId = ""
		attach.NoteId = toNoteIdO

		// 文件复制一份
		_, ext := SplitFilename(attach.Name)
		newFilename := NewGuid() + ext
		dir := "files/" + toUserId + "/attachs"
		filePath := dir + "/" + newFilename
		//modified by JacobXie
		var err error
		if qiniuService.IsUseQiniu() {
			err = qiniuService.CopyOnQiniu(attach.Path, filePath)
		} else {
			err = os.MkdirAll(revel.BasePath+"/"+dir, 0755)
			if err != nil {
				return false
			}
			_, err = CopyFile(revel.BasePath+"/"+attach.Path, revel.BasePath+"/"+filePath)
		}
		if err != nil {
			return false
		}
		attach.Name = newFilename
		attach.Path = filePath

		this.AddAttach(attach, false)
	}

	return true
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:39,代码来源:AttachService.go

示例14: moveTag

func (this *UpgradeService) moveTag() {
	usnI := 1
	tags := []info.Tag{}
	db.ListByQ(db.Tags, bson.M{}, &tags)
	for _, eachTag := range tags {
		tagTitles := eachTag.Tags
		now := time.Now()
		if tagTitles != nil && len(tagTitles) > 0 {
			for _, tagTitle := range tagTitles {
				noteTag := info.NoteTag{}
				noteTag.TagId = bson.NewObjectId()
				noteTag.Count = 1
				noteTag.Tag = tagTitle
				noteTag.UserId = eachTag.UserId
				noteTag.CreatedTime = now
				noteTag.UpdatedTime = now
				noteTag.Usn = usnI
				noteTag.IsDeleted = false
				db.Insert(db.NoteTags, noteTag)
				usnI++
			}
		}
	}
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:24,代码来源:UpgradeService.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:JacobXie,项目名称:leanote-daocloud,代码行数:26,代码来源:NoteService.go


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