當前位置: 首頁>>代碼示例>>Golang>>正文


Golang db.GetByQ函數代碼示例

本文整理匯總了Golang中github.com/leanote/leanote/app/db.GetByQ函數的典型用法代碼示例。如果您正苦於以下問題:Golang GetByQ函數的具體用法?Golang GetByQ怎麽用?Golang GetByQ使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了GetByQ函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: LoginGetUserInfo

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

	user := info.User{}
	if strings.Contains(emailOrUsername, "@") {
		db.GetByQ(db.Users, bson.M{"Email": emailOrUsername, "Pwd": md5Pwd}, &user)
	} else {
		db.GetByQ(db.Users, bson.M{"Username": emailOrUsername, "Pwd": md5Pwd}, &user)
	}

	return user
}
開發者ID:hello-kukoo,項目名稱:leanote,代碼行數:13,代碼來源:UserService.go

示例2: 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:rainkong,項目名稱:leanote,代碼行數:13,代碼來源:UserService.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:rainkong,項目名稱:leanote,代碼行數:8,代碼來源:UserService.go

示例4: 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:hello-kukoo,項目名稱:leanote,代碼行數:29,代碼來源:TokenService.go

示例5: 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:ClaudeXin,項目名稱:leanote,代碼行數:34,代碼來源:TagService.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:ClaudeXin,項目名稱:leanote,代碼行數:8,代碼來源:NoteService.go

示例7: 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}, &note)
	return this.GetBlogItem(note)
}
開發者ID:sunyinhuiCoding,項目名稱:leanote,代碼行數:9,代碼來源:BlogService.go

示例8: 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:rainkong,項目名稱:leanote,代碼行數:9,代碼來源:UserService.go

示例9: 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:ZypcGroup,項目名稱:leanote,代碼行數:9,代碼來源:BlogService.go

示例10: 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:sunyinhuiCoding,項目名稱:leanote,代碼行數:9,代碼來源:NotebookService.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:sunyinhuiCoding,項目名稱:leanote,代碼行數:53,代碼來源:ShareService.go

示例12: 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)

	//密碼
	c, _ := yuyu.SetConfig()
	data := c.SetTable("ssuser").Fileds("SSUSER_USERID", "SSUSER_PWD").Where("SSUSER_USERID =" + emailOrUsername).FindOne() //Fileds 查詢字段,Where where條件FindOne()查詢一條
	////limit sql中的limit OrderBy sql中查詢的OrderBy
	//data  = c.SetTable("user").Fileds("id", "password", "username").Where("id>1").Limit(1, 5).OrderBy("id Desc").FindAll()
	//data  = t.FindAll() //查詢所有數據,其中OrderBy() Limit() Where() Fileds()等設置條件

	fmt.Println(data)
	fmt.Println(user)
	return user
}
開發者ID:zhizhi1205,項目名稱:leanote,代碼行數:23,代碼來源:UserService.go

示例13: 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)
	guid := NewGuid()
	newFilename := guid + ext

	// TODO 統一目錄格式
	// dir := "files/" + toUserId + "/images"
	dir := "files/" + GetRandomFilePath(toUserId, guid) + "/images"
	filePath := dir + "/" + newFilename
	err := os.MkdirAll(revel.BasePath+dir, 0755)
	if err != nil {
		return false, ""
	}

	_, err = CopyFile(revel.BasePath+"/"+file.Path, revel.BasePath+"/"+filePath)
	if err != nil {
		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:ClaudeXin,項目名稱:leanote,代碼行數:51,代碼來源:FileService.go

示例14: 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:ClaudeXin,項目名稱:leanote,代碼行數:16,代碼來源:ThemeService.go

示例15: 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:ClaudeXin,項目名稱:leanote,代碼行數:15,代碼來源:SessionService.go


注:本文中的github.com/leanote/leanote/app/db.GetByQ函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。