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

Golang db.GetByQ函数代码示例

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

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



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

示例1: GetUserInfoByName

// 使用email(username), 得到用户信息
func (this *UserService) GetUserInfoByName(emailOrUsername string) info.User {
	emailOrUsername = strings.ToLower(emailOrUsername)

	user := info.User{}
	if strings.Contains(emailOrUsername, "@") {
		db.GetByQ(db.Users, bson.M{"Email": emailOrUsername}, &user)
	} else {
		db.GetByQ(db.Users, bson.M{"Username": emailOrUsername}, &user)
	}
	this.setUserLogo(&user)
	return user
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:13,代码来源:UserService.go


示例2: VerifyToken

// 验证token, 是否存在, 过时?
func (this *TokenService) VerifyToken(token string, tokenType int) (ok bool, msg string, tokenInfo info.Token) {
	overHours = this.GetOverHours(tokenType)

	ok = false
	if token == "" {
		msg = "不存在"
		return
	}

	db.GetByQ(db.Tokens, bson.M{"Token": token}, &tokenInfo)

	if tokenInfo.UserId == "" {
		msg = "不存在"
		return
	}

	// 验证是否过时
	now := time.Now()
	duration := now.Sub(tokenInfo.CreatedTime)

	if duration.Hours() > overHours {
		msg = "过期"
		return
	}

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


示例3: GetUserInfoByEmail

// 得到用户信息 email
func (this *UserService) GetUserInfoByEmail(email string) info.User {
	user := info.User{}
	db.GetByQ(db.Users, bson.M{"Email": email}, &user)
	// Logo路径问题, 有些有http: 有些没有
	this.setUserLogo(&user)
	return user
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:8,代码来源:UserService.go


示例4: AddOrUpdateTag

// 添加或更新标签, 先查下是否存在, 不存在则添加, 存在则更新
// 都要统计下tag的note数
// 什么时候调用? 笔记添加Tag, 删除Tag时
// 删除note时, 都可以调用
// 万能
func (this *TagService) AddOrUpdateTag(userId string, tag string) info.NoteTag {
	userIdO := bson.ObjectIdHex(userId)
	noteTag := info.NoteTag{}
	db.GetByQ(db.NoteTags, bson.M{"UserId": userIdO, "Tag": tag}, &noteTag)

	// 存在, 则更新之
	if noteTag.TagId != "" {
		// 统计note数
		count := noteService.CountNoteByTag(userId, tag)
		noteTag.Count = count
		noteTag.UpdatedTime = time.Now()
		//		noteTag.Usn = userService.IncrUsn(userId), 更新count而已
		db.UpdateByIdAndUserId(db.NoteTags, noteTag.TagId.Hex(), userId, noteTag)
		return noteTag
	}

	// 不存在, 则创建之
	noteTag.TagId = bson.NewObjectId()
	noteTag.Count = 1
	noteTag.Tag = tag
	noteTag.UserId = bson.ObjectIdHex(userId)
	noteTag.CreatedTime = time.Now()
	noteTag.UpdatedTime = noteTag.CreatedTime
	noteTag.Usn = userService.IncrUsn(userId)
	noteTag.IsDeleted = false
	db.Insert(db.NoteTags, noteTag)

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


示例5: GetUserInfoByUsername

// 得到用户信息 username
func (this *UserService) GetUserInfoByUsername(username string) info.User {
	user := info.User{}
	username = strings.ToLower(username)
	db.GetByQ(db.Users, bson.M{"Username": username}, &user)
	// Logo路径问题, 有些有http: 有些没有
	this.setUserLogo(&user)
	return user
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:9,代码来源:UserService.go


示例6: GetNoteByIdAndUserId

func (this *NoteService) GetNoteByIdAndUserId(noteId, userId string) (note info.Note) {
	note = info.Note{}
	if noteId == "" || userId == "" {
		return
	}
	db.GetByQ(db.Notes, bson.M{"_id": bson.ObjectIdHex(noteId), "UserId": bson.ObjectIdHex(userId), "IsDeleted": false}, &note)
	return
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:8,代码来源:NoteService.go


示例7: GetSingleByUserIdAndUrlTitle

func (this *BlogService) GetSingleByUserIdAndUrlTitle(userId, singleIdOrUrlTitle string) info.BlogSingle {
	page := info.BlogSingle{}
	if IsObjectId(singleIdOrUrlTitle) {
		db.Get(db.BlogSingles, singleIdOrUrlTitle, &page)
	} else {
		db.GetByQ(db.BlogSingles, bson.M{"UserId": bson.ObjectIdHex(userId), "UrlTitle": encodeValue(singleIdOrUrlTitle)}, &page)
	}
	return page
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:9,代码来源:BlogService.go


示例8: GetNotebookByUserIdAndUrlTitle

func (this *NotebookService) GetNotebookByUserIdAndUrlTitle(userId, notebookIdOrUrlTitle string) info.Notebook {
	notebook := info.Notebook{}
	if IsObjectId(notebookIdOrUrlTitle) {
		db.Get(db.Notebooks, notebookIdOrUrlTitle, &notebook)
	} else {
		db.GetByQ(db.Notebooks, bson.M{"UserId": bson.ObjectIdHex(userId), "UrlTitle": encodeValue(notebookIdOrUrlTitle)}, &notebook)
	}
	return notebook
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:9,代码来源:NotebookService.go


示例9: GetBlogByIdAndUrlTitle

// 通过id或urlTitle得到博客
func (this *BlogService) GetBlogByIdAndUrlTitle(userId string, noteIdOrUrlTitle string) (blog info.BlogItem) {
	if IsObjectId(noteIdOrUrlTitle) {
		return this.GetBlog(noteIdOrUrlTitle)
	}
	note := info.Note{}
	db.GetByQ(db.Notes, bson.M{"UserId": bson.ObjectIdHex(userId), "UrlTitle": encodeValue(noteIdOrUrlTitle),
		"IsBlog":  true,
		"IsTrash": false, "IsDeleted": false}, &note)
	return this.GetBlogItem(note)
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:11,代码来源:BlogService.go


示例10: CopyImage

// 复制图片
func (this *FileService) CopyImage(userId, fileId, toUserId string) (bool, string) {
	// 是否已经复制过了
	file2 := info.File{}
	db.GetByQ(db.Files, bson.M{"UserId": bson.ObjectIdHex(toUserId), "FromFileId": bson.ObjectIdHex(fileId)}, &file2)
	if file2.FileId != "" {
		return true, file2.FileId.Hex()
	}

	// 复制之

	file := info.File{}
	db.GetByIdAndUserId(db.Files, fileId, userId, &file)

	if file.FileId == "" || file.UserId.Hex() != userId {
		return false, ""
	}

	_, ext := SplitFilename(file.Name)
	newFilename := NewGuid() + ext

	dir := "files/" + toUserId + "/images"
	filePath := dir + "/" + newFilename
	//modified by JacobXie
	var err error
	if qiniuService.IsUseQiniu() {
		err = qiniuService.CopyOnQiniu(file.Path, filePath)
	} else {
		err = os.MkdirAll(dir, 0755)
		if err != nil {
			return false, ""
		}

		_, err = CopyFile(revel.BasePath+"/"+file.Path, revel.BasePath+"/"+filePath)
	}
	if err != nil {
		Log(err)
		return false, ""
	}

	fileInfo := info.File{Name: newFilename,
		Title:      file.Title,
		Path:       filePath,
		Size:       file.Size,
		FromFileId: file.FileId}
	id := bson.NewObjectId()
	fileInfo.FileId = id
	fileId = id.Hex()
	Ok, _ := this.AddImage(fileInfo, "", toUserId, false)

	if Ok {
		return Ok, id.Hex()
	}
	return false, ""
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:55,代码来源:FileService.go


示例11: ListShareNotesByNotebookId

// 得到共享笔记本下的notes
func (this *ShareService) ListShareNotesByNotebookId(notebookId, myUserId, sharedUserId string,
	page, pageSize int, sortField string, isAsc bool) []info.ShareNoteWithPerm {
	// 1 首先判断是否真的sharedUserId 共享了 notebookId 给 myUserId
	q := this.getOrQ(myUserId)
	q["NotebookId"] = bson.ObjectIdHex(notebookId)
	q["UserId"] = bson.ObjectIdHex(sharedUserId)
	shareNotebook := info.ShareNotebook{}
	db.GetByQ(db.ShareNotebooks,
		q,
		&shareNotebook)

	if shareNotebook.NotebookId == "" {
		return nil
	}

	perm := shareNotebook.Perm

	// 2 得到该notebook下分页显示所有的notes
	_, notes := noteService.ListNotes(sharedUserId, notebookId, false, page, pageSize, sortField, isAsc, false)

	// 3 添加权限信息
	// 3.1 如果该notebook自己有其它权限信息, 比如1, 那么覆盖notebook的权限信息
	noteIds := make([]bson.ObjectId, len(notes))
	for i, note := range notes {
		noteIds[i] = note.NoteId
	}
	// 笔记的权限
	shareNotes := []info.ShareNote{}
	delete(q, "NotebookId")
	q["NoteId"] = bson.M{"$in": noteIds}
	db.ShareNotes.Find(q).Sort("-ToUserId").All(&shareNotes) // 给个的权限>给组织的权限
	notePerms := map[bson.ObjectId]int{}
	for _, each := range shareNotes {
		if _, ok := notePerms[each.NoteId]; !ok {
			notePerms[each.NoteId] = each.Perm
		}
	}
	Log("笔记权限")
	LogJ(notePerms)

	// 3.2 组合
	notesWithPerm := make([]info.ShareNoteWithPerm, len(notes))
	for i, each := range notes {
		thisPerm := perm
		if selfPerm, ok := notePerms[each.NoteId]; ok {
			thisPerm = selfPerm
		}

		notesWithPerm[i] = info.ShareNoteWithPerm{each, thisPerm}
	}
	return notesWithPerm
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:53,代码来源:ShareService.go


示例12: GetThemeInfo

// 得到主题信息, 为了给博客用
func (this *ThemeService) GetThemeInfo(themeId, style string) map[string]interface{} {
	q := bson.M{}
	if themeId == "" {
		if style == "" {
			style = defaultStyle
		}
		q["Style"] = style
		q["IsDefault"] = true
	} else {
		q["_id"] = bson.ObjectIdHex(themeId)
	}
	theme := info.Theme{}
	db.GetByQ(db.Themes, q, &theme)
	return theme.Info
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:16,代码来源:ThemeService.go


示例13: Get

func (this *SessionService) Get(sessionId string) info.Session {
	session := info.Session{}
	db.GetByQ(db.Sessions, bson.M{"SessionId": sessionId}, &session)

	// 如果没有session, 那么插入一条之
	if session.Id == "" {
		session.Id = bson.NewObjectId()
		session.SessionId = sessionId
		session.CreatedTime = time.Now()
		session.UpdatedTime = session.CreatedTime
		db.Insert(db.Sessions, session)
	}

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


示例14: 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:JacobXie,项目名称:leanote-daocloud,代码行数:17,代码来源:TagService.go


示例15: GetUserId

// 通过email得到userId
func (this *UserService) GetUserId(email string) string {
	email = strings.ToLower(email)
	user := info.User{}
	db.GetByQ(db.Users, bson.M{"Email": email}, &user)
	return user.UserId.Hex()
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:7,代码来源:UserService.go


示例16: GetUserBlogByDomain

func (this *BlogService) GetUserBlogByDomain(domain string) info.UserBlog {
	blogUser := info.UserBlog{}
	db.GetByQ(db.UserBlogs, bson.M{"Domain": domain}, &blogUser)
	this.fixUserBlog(&blogUser)
	return blogUser
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:6,代码来源:BlogService.go


示例17: GetBlogNote

// 得到blog, blogService用
// 不要传userId, 因为是公开的
func (this *NoteService) GetBlogNote(noteId string) (note info.Note) {
	note = info.Note{}
	db.GetByQ(db.Notes, bson.M{"_id": bson.ObjectIdHex(noteId),
		"IsBlog": true, "IsTrash": false, "IsDeleted": false}, &note)
	return
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:8,代码来源:NoteService.go


示例18: GetUserInfoByThirdUserId

func (this *UserService) GetUserInfoByThirdUserId(thirdUserId string) info.User {
	user := info.User{}
	db.GetByQ(db.Users, bson.M{"ThirdUserId": thirdUserId}, &user)
	this.setUserLogo(&user)
	return user
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:6,代码来源:UserService.go


示例19: GetThemeById

func (this *ThemeService) GetThemeById(themeId string) info.Theme {
	theme := info.Theme{}
	db.GetByQ(db.Themes, bson.M{"_id": bson.ObjectIdHex(themeId)}, &theme)
	return theme
}
开发者ID:JacobXie,项目名称:leanote-daocloud,代码行数:5,代码来源:ThemeService.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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