本文整理汇总了Golang中gopkg/in/dancannon/gorethink/v2.Table函数的典型用法代码示例。如果您正苦于以下问题:Golang Table函数的具体用法?Golang Table怎么用?Golang Table使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Table函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetTalkByUsersId
func (talk *Talk) GetTalkByUsersId() bool {
talk1 := new(Talk)
talk2 := new(Talk)
curs, _ := r.Table("talks").
Filter(r.Row.Field("UserIdX").Eq(talk.UserIdX)).
Filter(r.Row.Field("UserIdY").Eq(talk.UserIdY)).
Run(api.Sess)
curs2, _ := r.Table("talks").
Filter(r.Row.Field("UserIdX").Eq(talk.UserIdY)).
Filter(r.Row.Field("UserIdY").Eq(talk.UserIdX)).
Run(api.Sess)
curs.One(&talk1)
curs2.One(&talk2)
if len(talk1.Id) == 0 && len(talk2.Id) == 0 {
return false
}
if talk1.Id != "" {
talk.copyTalk(talk1)
} else {
talk.copyTalk(talk2)
}
return true
}
示例2: getListPlace
func (place *Place) getListPlace(getList GetListPlace) ListPlace {
list := ListPlace{}
var curs *r.Cursor
if strings.Compare(getList.Filter, "") == 0 && strings.Compare(getList.Venue, "") == 0 {
curs, _ = r.Table("places").Filter(r.Row.Field("Validated").Eq(true)).Slice(getList.Offset, getList.Offset+getList.Limit).OrderBy("-PostNb").Run(api.Sess)
} else if strings.Compare(getList.Filter, "") != 0 && strings.Compare(getList.Venue, "") == 0 {
curs, _ = r.Table("places").Filter(r.Row.Field("Validated").Eq(true)).Filter(func(customer r.Term) interface{} {
return customer.Field(getList.Filter).Downcase().Match("^" + strings.ToLower(getList.FilterValue))
}).Slice(getList.Offset, getList.Offset+getList.Limit).OrderBy("-PostNb").Run(api.Sess)
} else if strings.Compare(getList.Filter, "") == 0 && strings.Compare(getList.Venue, "") != 0 {
curs, _ = r.Table("places").Filter(r.Row.Field("Validated").Eq(true)).Filter(r.Row.Field("Type").Eq(getList.Venue)).Slice(getList.Offset, getList.Offset+getList.Limit).OrderBy("-PostNb").Run(api.Sess)
} else if strings.Compare(getList.Filter, "") != 0 && strings.Compare(getList.Venue, "") != 0 {
curs, _ = r.Table("places").Filter(r.Row.Field("Validated").Eq(true)).Filter(func(customer r.Term) interface{} {
return customer.Field(getList.Filter).Downcase().Match("^" + strings.ToLower(getList.FilterValue))
}).Filter(r.Row.Field("Type").Eq(getList.Venue)).Slice(getList.Offset, getList.Offset+getList.Limit).OrderBy("-PostNb").Run(api.Sess)
}
curs.All(&list.Places)
return list
}
示例3: createUserFacebook
func (user *User) createUserFacebook(request *restful.Request, response *restful.Response) {
if user.getUserFacebookWithAccessToken(request.HeaderParameter("facebooktoken")) == false {
response.InternalServerError()
helpers.PrintLog(request, response, user.Name)
return
}
newUser := new(User)
//Facebook's data
newUser.FacebookId = user.FacebookId
newUser.UrlPicture = user.UrlPicture
newUser.Name = user.Name
isUserExist := newUser.getUserByFacebookId()
if isUserExist == false {
//user
newUser.Group = 0
newUser.CreateDate = time.Now()
newUser.Email = ""
newUser.Banish = false
}
//Session
newUser.CreateDateToken = time.Now()
newUser.ExpireDateToken = time.Now().AddDate(0, 0, 15)
newUser.Token = uuid.New()
var resp r.WriteResponse
var err error
//insert
if isUserExist == false {
resp, err = r.Table("users").Insert(newUser).RunWrite(api.Sess)
//update
} else {
_, err = r.Table("users").Get(newUser.Id).Update(newUser).RunWrite(api.Sess)
}
if err != nil {
response.WriteHeaderAndEntity(http.StatusConflict, err.Error())
helpers.PrintLog(request, response, user.Name)
return
}
//if user has been insert, we got ID
if isUserExist == false {
newUser.Id = resp.GeneratedKeys[0]
}
response.WriteHeaderAndEntity(http.StatusCreated, newUser)
helpers.PrintLog(request, response, user.Name)
return
}
示例4: SaveAccount
func (m DefaultManager) SaveAccount(account *auth.Account) error {
var (
hash string
eventType string
)
if account.Password != "" {
h, err := auth.Hash(account.Password)
if err != nil {
return err
}
hash = h
}
// check if exists; if so, update
acct, err := m.Account(account.Username)
if err != nil && err != ErrAccountDoesNotExist {
return err
}
// update
if acct != nil {
updates := map[string]interface{}{
"first_name": account.FirstName,
"last_name": account.LastName,
"roles": account.Roles,
}
if account.Password != "" {
updates["password"] = hash
}
if _, err := r.Table(tblNameAccounts).Filter(map[string]string{"username": account.Username}).Update(updates).RunWrite(m.session); err != nil {
return err
}
eventType = "update-account"
} else {
account.Password = hash
if _, err := r.Table(tblNameAccounts).Insert(account).RunWrite(m.session); err != nil {
return err
}
eventType = "add-account"
}
m.logEvent(eventType, fmt.Sprintf("username=%s", account.Username), []string{"security"})
return nil
}
示例5: handleChangeNotification
func handleChangeNotification(socket *websocket.Conn, userID string, err chan string) {
res, errr := r.Table("notifications").
Filter(r.Row.Field("UserId").
Eq(userID)).
Changes().
Run(api.Sess)
var value HandleChange
if errr != nil {
err <- errr.Error()
}
for res.Next(&value) {
var notif api.Notification
var simpleNotif api.WebSocketNotification
mapstructure.Decode(value.NewVal, ¬if)
if notif.Id == "" {
mapstructure.Decode(value.OldVal, ¬if)
simpleNotif.OldVal = true
} else {
simpleNotif.OldVal = false
}
simpleNotif.Title = "notification"
simpleNotif.Type = notif.Type
simpleNotif.Name = notif.Name
simpleNotif.UserIdFrom = notif.UserIdFrom
simpleNotif.IdLink = notif.IdLink
simpleNotif.CreatedAt = notif.CreatedAt
errr := socket.WriteJSON(simpleNotif)
if errr != nil {
err <- errr.Error()
}
}
}
示例6: createUser
func (user *User) createUser(request *restful.Request, response *restful.Response) {
newUser := new(User)
//user
newUser.Email = user.Email
newUser.Name = user.Name
newUser.CreateDate = time.Now()
newUser.Group = 100
newUser.FacebookId = ""
newUser.UrlPicture = ""
newUser.Banish = false
//encrypt password
newUser.Password = helpers.NewCryptPasswd([]byte(user.Password))
//session
newUser.CreateDateToken = time.Now()
newUser.ExpireDateToken = time.Now().AddDate(0, 0, 15)
newUser.Token = uuid.New()
resp, err := r.Table("users").Insert(newUser).RunWrite(api.Sess)
if err != nil {
response.WriteHeaderAndEntity(http.StatusConflict, err.Error())
helpers.PrintLog(request, response, user.Name)
return
}
newUser.Id = resp.GeneratedKeys[0]
newUser.Password = ""
response.WriteHeaderAndEntity(http.StatusCreated, newUser)
}
示例7: getLikesByUserId
func (like *Like) getLikesByUserId(searchWithPost bool, limit int, offset int) interface{} {
var list []Like
var likelist LikeList
curs, err := r.Table("likes").
Filter(r.Row.Field("UserId").Eq(like.user.Id)).
Slice(offset, offset+limit).
Run(api.Sess)
if err != nil && searchWithPost == true {
return LikeAndPostList{}
}
if err != nil && searchWithPost == false {
return likelist
}
curs.All(&list)
defer curs.Close()
if searchWithPost == true {
likeAndPostList := LikeAndPostList{}
var liste []LikeAndPost
for _, aLike := range list {
post := post.Post{Id: aLike.PostId}
post.GetPostById()
likeAndPost := LikeAndPost{Like: aLike, Post: post}
liste = append(liste, likeAndPost)
}
likeAndPostList.List = liste
return likeAndPostList
}
likelist.List = list
return likelist
}
示例8: createMatch
func (match *Match) createMatch(request *restful.Request, response *restful.Response) {
newMatch := new(Match)
newMatch.CreateAt = time.Now()
newMatch.PlaceId = match.post.PlaceId
newMatch.PostId = match.post.Id
newMatch.UserIdX = match.user.Id
newMatch.UserImageX = match.user.UrlPicture
newMatch.UserNameX = match.user.Name
newMatch.UserIdY = match.post.UserId
newMatch.UserNameY = match.post.UserName
newMatch.Validated = false
resp, err := r.Table("matchs").Insert(newMatch).RunWrite(api.Sess)
if err != nil {
response.WriteHeaderAndEntity(http.StatusConflict, err.Error())
helpers.PrintLog(request, response, match.user.Name)
return
}
go func() {
notif := notification.SetMatchReceive()
notif.UserId = match.post.UserId
notif.UserIdFrom = match.user.Id
notif.IdThing = resp.GeneratedKeys[0]
notif.Name = match.user.Name
notif.IdLink = match.post.Id
notif.CreateNotification()
}()
newMatch.Id = resp.GeneratedKeys[0]
response.WriteHeaderAndEntity(http.StatusCreated, newMatch)
helpers.PrintLog(request, response, match.user.Name)
}
示例9: createMessageWithContent
func (message *Message) createMessageWithContent(request *restful.Request, response *restful.Response) {
msg := new(Message)
msg.Content = message.Content
msg.CreatedAt = time.Now()
msg.FromUserId = message.user.Id
msg.TalkId = message.talk.Id
msg.Read = false
if message.talk.UserIdX == message.user.Id {
msg.ToUserId = message.talk.UserIdY
} else {
msg.ToUserId = message.talk.UserIdX
}
resp, err := r.Table("messages").Insert(msg).RunWrite(api.Sess)
if err != nil {
helpers.PrintLog(request, response, message.user.Name)
response.WriteHeaderAndEntity(http.StatusConflict, err.Error())
return
}
msg.Id = resp.GeneratedKeys[0]
message.talk.UpdateLastMessageDate(message.user.Id, message.Content)
response.WriteHeaderAndEntity(http.StatusCreated, msg)
helpers.PrintLog(request, response, message.user.Name)
}
示例10: createPlace
func (place *Place) createPlace(request *restful.Request, response *restful.Response) {
place.Lat = 0
place.Lng = 0
place.PostNb = 0
place.ValidatedAt = *new(time.Time)
place.Validated = false
place.CreateAt = time.Now()
place.UserId = place.user.Id
place.Id = *new(string)
request.Request.ParseMultipartForm(32 << 20)
mpf, hdr, _ := request.Request.FormFile("image")
ext := filepath.Ext(hdr.Filename)
if helpers.CheckFileExtension(ext) == false {
errors := api.Error{}
errors.ListErrors = append(errors.ListErrors, "Only .jpg, .jpeg or .png are authorized.")
response.WriteHeaderAndEntity(406, errors)
helpers.PrintLog(request, response, place.user.Name)
return
}
place.Image = helpers.GenerateHash(50) + ext
go helpers.PutFile("assets/Images/"+place.Image, mpf)
resp, err := r.Table("places").Insert(place).RunWrite(api.Sess)
if err != nil {
response.WriteHeaderAndEntity(http.StatusConflict, err.Error())
return
}
place.Id = resp.GeneratedKeys[0]
response.WriteHeaderAndEntity(http.StatusCreated, place)
helpers.PrintLog(request, response, place.user.Name)
}
示例11: RemoveTalk
func (talk *Talk) RemoveTalk() error {
if talk.GetTalkByUsersId() == true {
_, err := r.Table("talks").Get(talk.Id).Delete().Run(api.Sess)
return err
}
return nil
}
示例12: IncrementPostNb
func (place *Place) IncrementPostNb() error {
place.PostNb += 1
_, err := r.Table("places").Get(place.Id).Update(place).RunWrite(api.Sess)
return err
}
示例13: acceptPost
func (post *Post) acceptPost(request *restful.Request, response *restful.Response) {
post.Validated = true
post.ValidatedAt = time.Now()
if err := post.place.IncrementPostNb(); err != nil {
response.WriteHeaderAndEntity(http.StatusInternalServerError, err.Error())
helpers.PrintLog(request, response, post.user.Name)
return
}
post.IdByPlace = post.place.PostNb
_, err := r.Table("posts").Get(post.Id).Update(post).RunWrite(api.Sess)
if err != nil {
response.WriteHeaderAndEntity(http.StatusInternalServerError, err.Error())
helpers.PrintLog(request, response, post.user.Name)
return
}
go func() {
notif := notification.SetPostAccepted()
notif.UserId = post.UserId
notif.UserIdFrom = post.user.Id
notif.IdThing = post.Id
notif.Name = post.PlaceName
notif.IdLink = post.Id
notif.CreateNotification()
}()
response.WriteHeaderAndEntity(http.StatusOK, post)
helpers.PrintLog(request, response, post.user.Name)
}
示例14: refusePost
func (post *Post) refusePost(request *restful.Request, response *restful.Response) {
_, err := r.Table("posts").Get(post.Id).Delete().Run(api.Sess)
if err != nil {
response.WriteHeaderAndEntity(http.StatusInternalServerError, err.Error())
helpers.PrintLog(request, response, post.user.Name)
return
}
if post.Image != "" {
helpers.RemoveFile("./assets/Images/" + post.Image)
}
if post.user.IsUserIsAdmin() == true {
go func() {
notif := notification.SetPostRefused()
notif.UserId = post.UserId
notif.UserIdFrom = post.user.Id
notif.IdThing = post.Id
notif.Name = post.PlaceName
notif.IdLink = post.Id
notif.CreateNotification()
}()
}
response.WriteHeader(http.StatusOK)
helpers.PrintLog(request, response, post.user.Name)
}
示例15: acceptPlace
func (place *Place) acceptPlace(request *restful.Request, response *restful.Response) {
if place.getGeolocation() == false {
errors := api.Error{}
errors.ListErrors = append(errors.ListErrors, "We were unable to geolocate your plate")
response.WriteHeaderAndEntity(500, errors)
return
}
place.ValidatedAt = time.Now()
place.Validated = true
_, err := r.Table("places").Get(place.Id).Update(place).RunWrite(api.Sess)
if err != nil {
response.WriteHeaderAndEntity(http.StatusConflict, err.Error())
return
}
go func() {
notif := notification.SetPlaceAccepted()
notif.UserId = place.UserId
notif.UserIdFrom = place.user.Id
notif.IdThing = place.Id
notif.Name = place.Name
notif.IdLink = place.Id
notif.CreateNotification()
}()
response.WriteHeaderAndEntity(http.StatusOK, place)
helpers.PrintLog(request, response, place.user.Name)
}