本文整理汇总了Golang中github.com/leanote/leanote/app/db.GetByQ函数的典型用法代码示例。如果您正苦于以下问题:Golang GetByQ函数的具体用法?Golang GetByQ怎么用?Golang GetByQ使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetByQ函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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}, ¬eTag)
// 存在, 则更新之
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}, ¬e)
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}, ¬e)
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, ¬ebook)
} else {
db.GetByQ(db.Notebooks, bson.M{"UserId": bson.ObjectIdHex(userId), "UrlTitle": encodeValue(notebookIdOrUrlTitle)}, ¬ebook)
}
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
示例16: 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}, ¬eTag)
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:ClaudeXin,项目名称:leanote,代码行数:17,代码来源:TagService.go
示例17: ListShareNotesByNotebookId
// 得到共享笔记本下的notes
func (this *ShareService) ListShareNotesByNotebookId(notebookId, myUserId, sharedUserId string,
page, pageSize int, sortField string, isAsc bool) []info.ShareNoteWithPerm {
// 1 首先判断是否真的sharedUserId 共享了 notebookId 给 myUserId
shareNotebook := info.ShareNotebook{}
db.GetByQ(db.ShareNotebooks, bson.M{"NotebookId": bson.ObjectIdHex(notebookId),
"UserId": bson.ObjectIdHex(sharedUserId), "ToUserId": bson.ObjectIdHex(myUserId)}, &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
}
notePerms := this.getNotesPerm(noteIds, myUserId, sharedUserId)
// 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:bigxing,项目名称:leanote,代码行数:37,代码来源:ShareService.go
示例18: 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:ClaudeXin,项目名称:leanote,代码行数:5,代码来源:ThemeService.go
示例19: GetUserInfoByEmail
// 得到用户信息 email
func (this *UserService) GetUserInfoByEmail(email string) info.User {
user := info.User{}
db.GetByQ(db.Users, bson.M{"Email": email}, &user)
return user
}
开发者ID:hello-kukoo,项目名称:leanote,代码行数:6,代码来源:UserService.go
示例20: GetUserInfoByUsername
// 得到用户信息 username
func (this *UserService) GetUserInfoByUsername(username string) info.User {
user := info.User{}
db.GetByQ(db.Users, bson.M{"Username": username}, &user)
return user
}
开发者ID:hello-kukoo,项目名称:leanote,代码行数:6,代码来源:UserService.go
注:本文中的github.com/leanote/leanote/app/db.GetByQ函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论