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

Golang v2.Table函数代码示例

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

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



在下文中一共展示了Table函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:26,代码来源:lib.go


示例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
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:28,代码来源:lib.go


示例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
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:51,代码来源:methods.go


示例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
}
开发者ID:XuesongYang,项目名称:shipyard,代码行数:48,代码来源:manager.go


示例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, &notif)
		if notif.Id == "" {
			mapstructure.Decode(value.OldVal, &notif)
			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()
		}
	}
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:34,代码来源:websockets.go


示例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)
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:30,代码来源:methods.go


示例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
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:34,代码来源:lib.go


示例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)
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:34,代码来源:methods.go


示例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)
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:25,代码来源:methods.go


示例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)
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:34,代码来源:methods.go


示例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
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:7,代码来源:lib.go


示例12: IncrementPostNb

func (place *Place) IncrementPostNb() error {
	place.PostNb += 1

	_, err := r.Table("places").Get(place.Id).Update(place).RunWrite(api.Sess)

	return err
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:7,代码来源:lib.go


示例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)
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:29,代码来源:methods.go


示例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)
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:25,代码来源:methods.go


示例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)
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:31,代码来源:methods.go


示例16: UpdateLikeNb

func (post *Post) UpdateLikeNb(nb int) error {

	post.LikeNb += nb
	_, err := r.Table("posts").Get(post.Id).Update(post).RunWrite(api.Sess)

	return err
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:7,代码来源:lib.go


示例17: handleImage

func (place *Place) handleImage(request *restful.Request, response *restful.Response) {
	errors := api.Error{}

	request.Request.ParseMultipartForm(32 << 20)
	mpf, hdr, _ := request.Request.FormFile("image")

	ext := filepath.Ext(hdr.Filename)
	if helpers.CheckFileExtension(ext) == false {
		errors.ListErrors = append(errors.ListErrors, "Only .jpg, .jpeg or .png are authorized.")
		response.WriteHeaderAndEntity(406, errors)
		return
	}
	if strings.Compare(place.Image, "") != 0 {
		helpers.RemoveFile("./assets/Images/" + place.Image)
	}
	place.Image = helpers.GenerateHash(50) + ext
	go helpers.PutFile("assets/Images/"+place.Image, mpf)

	_, err := r.Table("places").Get(place.Id).Update(place).RunWrite(api.Sess)
	if err != nil {
		response.WriteHeaderAndEntity(http.StatusConflict, err.Error())
		return
	}
	response.WriteHeaderAndEntity(http.StatusOK, place)

	helpers.PrintLog(request, response, place.user.Name)
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:27,代码来源:methods.go


示例18: newConnectionHandler

func newConnectionHandler(c *config.Config, router *httprouter.Router) *connection.Handler {
	ctx := c.Context()

	h := &connection.Handler{}
	h.H = &herodot.JSON{}
	h.W = ctx.Warden
	h.SetRoutes(router)

	switch con := ctx.Connection.(type) {
	case *config.MemoryConnection:
		h.Manager = connection.NewMemoryManager()
		break
	case *config.RethinkDBConnection:
		con.CreateTableIfNotExists("hydra_policies")
		m := &connection.RethinkManager{
			Session: con.GetSession(),
			Table:   r.Table("hydra_policies"),
		}
		if err := m.ColdStart(); err != nil {
			logrus.Fatalf("Could not fetch initial state: %s", err)
		}
		m.Watch(context.Background())
		h.Manager = m
		break
	default:
		panic("Unknown connection type.")
	}

	return h
}
开发者ID:jemacom,项目名称:hydra,代码行数:30,代码来源:handler_connection_factory.go


示例19: newClientManager

func newClientManager(c *config.Config) client.Manager {
	ctx := c.Context()

	switch con := ctx.Connection.(type) {
	case *config.MemoryConnection:
		return &client.MemoryManager{
			Clients: map[string]*fosite.DefaultClient{},
			Hasher:  ctx.Hasher,
		}
	case *config.RethinkDBConnection:
		con.CreateTableIfNotExists("hydra_clients")
		m := &client.RethinkManager{
			Session: con.GetSession(),
			Table:   r.Table("hydra_clients"),
			Hasher:  ctx.Hasher,
		}
		if err := m.ColdStart(); err != nil {
			logrus.Fatalf("Could not fetch initial state: %s", err)
		}
		m.Watch(context.Background())
		return m
	default:
		panic("Unknown connection type.")
	}
}
开发者ID:jemacom,项目名称:hydra,代码行数:25,代码来源:handler_client_factory.go


示例20: newJWKHandler

func newJWKHandler(c *config.Config, router *httprouter.Router) *jwk.Handler {
	ctx := c.Context()
	h := &jwk.Handler{
		H: &herodot.JSON{},
		W: ctx.Warden,
	}
	h.SetRoutes(router)

	switch con := ctx.Connection.(type) {
	case *config.MemoryConnection:
		ctx.KeyManager = &jwk.MemoryManager{}
		break
	case *config.RethinkDBConnection:
		con.CreateTableIfNotExists("hydra_json_web_keys")
		m := &jwk.RethinkManager{
			Session: con.GetSession(),
			Keys:    map[string]jose.JsonWebKeySet{},
			Table:   r.Table("hydra_json_web_keys"),
			Cipher: &jwk.AEAD{
				Key: c.GetSystemSecret(),
			},
		}
		if err := m.ColdStart(); err != nil {
			logrus.Fatalf("Could not fetch initial state: %s", err)
		}
		m.Watch(context.Background())
		ctx.KeyManager = m
		break
	default:
		logrus.Fatalf("Unknown connection type.")
	}

	h.Manager = ctx.KeyManager
	return h
}
开发者ID:jemacom,项目名称:hydra,代码行数:35,代码来源:handler_jwk_factory.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang v1.NewWatcher函数代码示例发布时间:2022-05-28
下一篇:
Golang v2.Expr函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap