当前位置: 首页>>代码示例>>Golang>>正文


Golang Query.Type方法代码示例

本文整理汇总了Golang中socialapi/request.Query.Type方法的典型用法代码示例。如果您正苦于以下问题:Golang Query.Type方法的具体用法?Golang Query.Type怎么用?Golang Query.Type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在socialapi/request.Query的用法示例。


在下文中一共展示了Query.Type方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ByName

// ByName fetches the channel by name, type_constant and group_name, it doesnt
// have the best name, but evolved to this situation :/
func (c *Channel) ByName(q *request.Query) (Channel, error) {
	var channel Channel

	if q.GroupName == "" {
		return channel, ErrGroupNameIsNotSet
	}

	if q.Type == "" {
		q.Type = Channel_TYPE_TOPIC
	}

	query := &bongo.Query{
		Selector: map[string]interface{}{
			"group_name":    q.GroupName,
			"type_constant": q.Type,
			"name":          q.Name,
		},
		Pagination: *bongo.NewPagination(q.Limit, q.Skip),
	}

	query.AddScope(RemoveTrollContent(c, q.ShowExempt))

	err := c.One(query)
	if err != nil && err != bongo.RecordNotFound {
		return channel, err
	}

	return *c, nil
}
开发者ID:,项目名称:,代码行数:31,代码来源:

示例2: BySlug

// BySlug fetchs channel message by its slug
// checks if message is in the channel or not
func (c *ChannelMessage) BySlug(query *request.Query) error {
	if query.Slug == "" {
		return ErrSlugIsNotSet
	}

	// fetch message itself
	q := &bongo.Query{
		Selector: map[string]interface{}{
			"slug": query.Slug,
		},
	}

	q.AddScope(RemoveTrollContent(
		c, query.ShowExempt,
	))

	if err := c.One(q); err != nil {
		return err
	}

	query.Type = Channel_TYPE_GROUP
	res, err := c.isInChannel(query, "public")
	if err != nil {
		return err
	}

	if res {
		return nil
	}

	query.Type = Channel_TYPE_ANNOUNCEMENT
	res, err = c.isInChannel(query, "changelog")
	if err != nil {
		return err
	}

	if !res {
		return bongo.RecordNotFound
	}

	return nil
}
开发者ID:,项目名称:,代码行数:44,代码来源:

示例3: ByParticipants

// ByParticipants fetches the channels by their respective participants
func (c *Channel) ByParticipants(participants []int64, q *request.Query) ([]Channel, error) {
	if q.GroupName == "" {
		return nil, ErrGroupNameIsNotSet
	}

	if len(participants) == 0 {
		return nil, ErrChannelParticipantIsNotSet
	}

	if q.Type == "" {
		q.Type = Channel_TYPE_PRIVATE_MESSAGE
	}

	var channelIds []int64

	cp := NewChannelParticipant()

	err := bongo.B.DB.
		Model(cp).
		Table(cp.BongoName()).
		Joins(
			`left join api.channel on
		 api.channel_participant.channel_id = api.channel.id`).
		Where(
			`api.channel_participant.account_id IN ( ? ) and
		 api.channel_participant.status_constant = ? and
		 api.channel.group_name = ? and
		 api.channel.deleted_at < '0001-01-02 00:00:00+00' and
		 api.channel.type_constant = ?`,
			participants,
			ChannelParticipant_STATUS_ACTIVE,
			q.GroupName,
			q.Type,
		).
		Group("channel_participant.channel_id, channel.created_at").
		Having("COUNT (channel_participant.channel_id) = ?", len(participants)).
		Order("channel.created_at").
		Limit(q.Limit).
		Offset(q.Skip).
		Pluck("api.channel_participant.channel_id", &channelIds).Error
	if err != nil {
		return nil, err
	}

	return c.FetchByIds(channelIds)
}
开发者ID:,项目名称:,代码行数:47,代码来源:

示例4: getUserChannelsQuery

func getUserChannelsQuery(q *request.Query) *gorm.DB {
	c := models.NewChannel()

	if q.Type == "" {
		q.Type = models.Channel_TYPE_PRIVATE_MESSAGE
	}

	return bongo.B.DB.
		Model(c).
		Table(c.BongoName()).
		Select("api.channel_participant.channel_id").
		Joins("left join api.channel_participant on api.channel_participant.channel_id = api.channel.id").
		Where("api.channel_participant.account_id = ? and "+
			"api.channel.group_name = ? and "+
			"api.channel.type_constant = ? and "+
			"api.channel_participant.status_constant = ?",
			q.AccountId,
			q.GroupName,
			q.Type,
			models.ChannelParticipant_STATUS_ACTIVE)
}
开发者ID:,项目名称:,代码行数:21,代码来源:

示例5: Search

func (c *Channel) Search(q *request.Query) ([]Channel, error) {
	if q.GroupName == "" {
		return nil, ErrGroupNameIsNotSet
	}

	if q.Type == "" {
		q.Type = Channel_TYPE_TOPIC
	}

	var channels []Channel

	bongoQuery := &bongo.Query{
		Selector: map[string]interface{}{
			"group_name":    q.GroupName,
			"type_constant": q.Type,
		},
		Pagination: *bongo.NewPagination(q.Limit, q.Skip),
	}

	bongoQuery.AddScope(RemoveTrollContent(c, q.ShowExempt))

	query := bongo.B.BuildQuery(c, bongoQuery)

	// use 'ilike' for case-insensitive search
	query = query.Where("name ilike ?", "%"+q.Name+"%")

	if err := bongo.CheckErr(
		query.Find(&channels),
	); err != nil {
		return nil, err
	}

	if channels == nil {
		return make([]Channel, 0), nil
	}

	return channels, nil
}
开发者ID:,项目名称:,代码行数:38,代码来源:


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