本文整理匯總了Golang中github.com/nosqldb/zhujian/app/db.Insert函數的典型用法代碼示例。如果您正苦於以下問題:Golang Insert函數的具體用法?Golang Insert怎麽用?Golang Insert使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Insert函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: LikeBlog
// 點讚
// retun ok , isLike
func (this *BlogService) LikeBlog(noteId, userId string) (ok bool, isLike bool) {
ok = false
isLike = false
if noteId == "" || userId == "" {
return
}
// 判斷是否點過讚, 如果點過那麽取消點讚
note := noteService.GetNoteById(noteId)
if !note.IsBlog /*|| note.UserId.Hex() == userId */ {
return
}
noteIdO := bson.ObjectIdHex(noteId)
userIdO := bson.ObjectIdHex(userId)
var n int
if !db.Has(db.BlogLikes, bson.M{"NoteId": noteIdO, "UserId": userIdO}) {
n = 1
// 添加之
db.Insert(db.BlogLikes, info.BlogLike{LikeId: bson.NewObjectId(), NoteId: noteIdO, UserId: userIdO, CreatedTime: time.Now()})
isLike = true
} else {
// 已點過, 那麽刪除之
n = -1
db.Delete(db.BlogLikes, bson.M{"NoteId": noteIdO, "UserId": userIdO})
isLike = false
}
ok = db.Update(db.Notes, bson.M{"_id": noteIdO}, bson.M{"$inc": bson.M{"LikeNum": n}})
return
}
示例2: ImportTheme
// 導入主題
// path == /llllllll/..../public/upload/.../aa.zip, 絕對路徑
func (this *ThemeService) ImportTheme(userId, path string) (ok bool, msg string) {
themeIdO := bson.NewObjectId()
themeId := themeIdO.Hex()
targetPath := this.getUserThemePath(userId, themeId) // revel.BasePath + "/public/upload/" + userId + "/themes/" + themeId
if ok, msg = archive.Unzip(path, targetPath); !ok {
DeleteFile(targetPath)
return
}
// 主題驗證
if ok, msg = this.ValidateTheme(targetPath, "", ""); !ok {
DeleteFile(targetPath)
return
}
// 解壓成功, 那麽新建之
// 保存到數據庫中
theme, _ := this.getThemeConfig(targetPath)
if theme.Name == "" {
ok = false
DeleteFile(targetPath)
msg = "解析錯誤"
return
}
theme.ThemeId = themeIdO
theme.Path = this.getUserThemePath2(userId, themeId)
theme.CreatedTime = time.Now()
theme.UpdatedTime = theme.CreatedTime
theme.UserId = bson.ObjectIdHex(userId)
ok = db.Insert(db.Themes, theme)
if !ok {
DeleteFile(targetPath)
}
DeleteFile(path)
return
}
示例3: AddOrUpdateSingle
// 更新或添加
func (this *BlogService) AddOrUpdateSingle(userId, singleId, title, content string) (ok bool) {
ok = false
if singleId != "" {
ok = db.UpdateByIdAndUserIdMap(db.BlogSingles, singleId, userId, bson.M{
"Title": title,
"Content": content,
"UpdatedTime": time.Now(),
})
if ok {
// 還要修改UserBlog中的Singles
this.updateBlogSingles(userId, false, false, singleId, title, "")
}
return
}
// 添加
page := info.BlogSingle{
SingleId: bson.NewObjectId(),
UserId: bson.ObjectIdHex(userId),
Title: title,
Content: content,
UrlTitle: GetUrTitle(userId, title, "single"),
CreatedTime: time.Now(),
}
page.UpdatedTime = page.CreatedTime
ok = db.Insert(db.BlogSingles, page)
// 還要修改UserBlog中的Singles
this.updateBlogSingles(userId, false, true, page.SingleId.Hex(), title, page.UrlTitle)
return
}
示例4: CopyDefaultTheme
// 新建主題
// 複製默認主題到文件夾下
func (this *ThemeService) CopyDefaultTheme(userBlog info.UserBlog) (ok bool, themeId string) {
newThemeId := bson.NewObjectId()
themeId = newThemeId.Hex()
userId := userBlog.UserId.Hex()
themePath := this.getUserThemePath(userId, themeId)
err := os.MkdirAll(themePath, 0755)
if err != nil {
return
}
// 複製默認主題
defaultThemePath := this.getDefaultThemePath(userBlog.Style)
err = CopyDir(defaultThemePath, themePath)
if err != nil {
return
}
// 保存到數據庫中
theme, _ := this.getThemeConfig(themePath)
theme.ThemeId = newThemeId
theme.Path = this.getUserThemePath2(userId, themeId)
theme.CreatedTime = time.Now()
theme.UpdatedTime = theme.CreatedTime
theme.UserId = bson.ObjectIdHex(userId)
ok = db.Insert(db.Themes, theme)
return ok, themeId
}
示例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
}
示例6: AddNote
func (this *NoteService) AddNote(note info.Note, fromApi bool) info.Note {
if note.NoteId.Hex() == "" {
noteId := bson.NewObjectId()
note.NoteId = noteId
}
note.CreatedTime = time.Now()
note.UpdatedTime = note.CreatedTime
note.IsTrash = false
note.UpdatedUserId = note.UserId
note.UrlTitle = GetUrTitle(note.UserId.Hex(), note.Title, "note")
note.Usn = userService.IncrUsn(note.UserId.Hex())
notebookId := note.NotebookId.Hex()
// api會傳IsBlog, web不會傳
if !fromApi {
// 設為blog
note.IsBlog = notebookService.IsBlog(notebookId)
}
// if note.IsBlog {
note.PublicTime = note.UpdatedTime
// }
db.Insert(db.Notes, note)
// tag1
tagService.AddTags(note.UserId.Hex(), note.Tags)
// recount notebooks' notes number
notebookService.ReCountNotebookNumberNotes(notebookId)
return note
}
示例7: AddAttach
// add attach
// api調用時, 添加attach之前是沒有note的
// fromApi表示是api添加的, updateNote傳過來的, 此時不要incNote's usn, 因為updateNote會inc的
func (this *AttachService) AddAttach(attach info.Attach, fromApi bool) (ok bool, msg string) {
attach.CreatedTime = time.Now()
ok = db.Insert(db.Attachs, attach)
note := noteService.GetNoteById(attach.NoteId.Hex())
// api調用時, 添加attach之前是沒有note的
var userId string
if note.NoteId != "" {
userId = note.UserId.Hex()
} else {
userId = attach.UploadUserId.Hex()
}
if ok {
// 更新筆記的attachs num
this.updateNoteAttachNum(attach.NoteId, 1)
}
if !fromApi {
// 增長note's usn
noteService.IncrNoteUsn(attach.NoteId.Hex(), userId)
}
return
}
示例8: ReCountBlogTags
// 重新計算博客的標簽
// 在設置設置/取消為博客時調用
func (this *BlogService) ReCountBlogTags(userId string) bool {
// 得到所有博客
notes := []info.Note{}
userIdO := bson.ObjectIdHex(userId)
query := bson.M{"UserId": userIdO, "IsTrash": false, "IsBlog": true}
db.ListByQWithFields(db.Notes, query, []string{"Tags"}, ¬es)
db.DeleteAll(db.TagCounts, bson.M{"UserId": userIdO, "IsBlog": true})
if notes == nil || len(notes) == 0 {
return true
}
// 統計所有的Tags和數目
tagsCount := map[string]int{}
for _, note := range notes {
tags := note.Tags
if tags != nil && len(tags) > 0 {
for _, tag := range tags {
count := tagsCount[tag]
count++
tagsCount[tag] = count
}
}
}
// 一個個插入
for tag, count := range tagsCount {
db.Insert(db.TagCounts,
info.TagCount{UserId: userIdO, IsBlog: true, Tag: tag, Count: count})
}
return true
}
示例9: AddShareNotebook1
// 添加一個notebook共享
// [ok]
func (this *ShareService) AddShareNotebook1(shareNotebook info.ShareNotebook) bool {
// 添加一條記錄說明兩者存在關係
this.AddHasShareNote(shareNotebook.UserId.Hex(), shareNotebook.ToUserId.Hex())
shareNotebook.CreatedTime = time.Now()
return db.Insert(db.ShareNotebooks, shareNotebook)
}
示例10: newHistory
// 新建曆史
func (this *NoteContentHistoryService) newHistory(noteId, userId string, eachHistory info.EachHistory) {
history := info.NoteContentHistory{NoteId: bson.ObjectIdHex(noteId),
UserId: bson.ObjectIdHex(userId),
Histories: []info.EachHistory{eachHistory},
}
// 保存之
db.Insert(db.NoteContentHistories, history)
}
示例11: AddGroup
// 添加分組
func (this *GroupService) AddGroup(userId, title string) (bool, info.Group) {
group := info.Group{
GroupId: bson.NewObjectId(),
UserId: bson.ObjectIdHex(userId),
Title: title,
CreatedTime: time.Now(),
}
return db.Insert(db.Groups, group), group
}
示例12: AddNoteContent
// 添加筆記本內容
// [ok]
func (this *NoteService) AddNoteContent(noteContent info.Note) info.Note {
noteContent.CreatedTime = time.Now()
noteContent.UpdatedTime = noteContent.CreatedTime
noteContent.UpdatedUserId = noteContent.UserId
db.Insert(db.Notes, noteContent)
// 更新筆記圖片
noteImageService.UpdateNoteImages(noteContent.UserId.Hex(), noteContent.NoteId.Hex(), "", noteContent.Content)
return noteContent
}
示例13: updateGlobalConfig
// 通用方法
func (this *ConfigService) updateGlobalConfig(userId, key string, value interface{}, isArr, isMap, isArrMap bool) bool {
// 判斷是否存在
if _, ok := this.GlobalAllConfigs[key]; !ok {
// 需要添加
config := info.Config{ConfigId: bson.NewObjectId(),
UserId: bson.ObjectIdHex(userId),
Key: key,
IsArr: isArr,
IsMap: isMap,
IsArrMap: isArrMap,
UpdatedTime: time.Now(),
}
if isArr {
v, _ := value.([]string)
config.ValueArr = v
this.GlobalArrayConfigs[key] = v
} else if isMap {
v, _ := value.(map[string]string)
config.ValueMap = v
this.GlobalMapConfigs[key] = v
} else if isArrMap {
v, _ := value.([]map[string]string)
config.ValueArrMap = v
this.GlobalArrMapConfigs[key] = v
} else {
v, _ := value.(string)
config.ValueStr = v
this.GlobalStringConfigs[key] = v
}
return db.Insert(db.Configs, config)
} else {
i := bson.M{"UpdatedTime": time.Now()}
this.GlobalAllConfigs[key] = value
if isArr {
v, _ := value.([]string)
i["ValueArr"] = v
this.GlobalArrayConfigs[key] = v
} else if isMap {
v, _ := value.(map[string]string)
i["ValueMap"] = v
this.GlobalMapConfigs[key] = v
} else if isArrMap {
v, _ := value.([]map[string]string)
i["ValueArrMap"] = v
this.GlobalArrMapConfigs[key] = v
} else {
v, _ := value.(string)
i["ValueStr"] = v
this.GlobalStringConfigs[key] = v
}
return db.UpdateByQMap(db.Configs, bson.M{"UserId": bson.ObjectIdHex(userId), "Key": key}, i)
}
}
示例14: AddImage
// add Image
func (this *FileService) AddImage(image info.File, albumId, userId string, needCheckSize bool) (ok bool, msg string) {
image.CreatedTime = time.Now()
if albumId != "" {
image.AlbumId = bson.ObjectIdHex(albumId)
} else {
image.AlbumId = bson.ObjectIdHex(DEFAULT_ALBUM_ID)
image.IsDefaultAlbum = true
}
image.UserId = bson.ObjectIdHex(userId)
ok = db.Insert(db.Files, image)
return
}
示例15: AddShareNotebookGroup
// 共享筆記給分組
func (this *ShareService) AddShareNotebookGroup(userId, notebookId, groupId string, perm int) bool {
if !groupService.IsExistsGroupUser(userId, groupId) {
return false
}
// 先刪除之
this.DeleteShareNotebookGroup(userId, notebookId, groupId)
shareNotebook := info.ShareNotebook{NotebookId: bson.ObjectIdHex(notebookId),
UserId: bson.ObjectIdHex(userId), // 冗餘字段
ToGroupId: bson.ObjectIdHex(groupId),
Perm: perm,
CreatedTime: time.Now(),
}
return db.Insert(db.ShareNotebooks, shareNotebook)
}