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


Golang Term.And方法代码示例

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


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

示例1: List

func (t *ThreadsTable) List(
	owner string,
	sort []string,
	offset int,
	limit int,
	labels []string,
) ([]*models.Thread, error) {

	term := t.GetTable()

	if owner != "" {
		term = t.GetTable().GetAllByIndex("owner", owner)
	}

	// If sort array has contents, parse them and add to the term
	if sort != nil && len(sort) > 0 {
		var conds []interface{}
		for _, cond := range sort {
			if cond[0] == '-' {
				conds = append(conds, gorethink.Desc(cond[1:]))
			} else if cond[0] == '+' || cond[0] == ' ' {
				conds = append(conds, gorethink.Asc(cond[1:]))
			} else {
				conds = append(conds, gorethink.Asc(cond))
			}
		}

		term = term.OrderBy(conds...)
	}

	// Parse labels
	hasLabels := []string{}
	excLabels := []string{}
	for _, label := range labels {
		if label[0] == '-' {
			excLabels = append(excLabels, label[1:])
		} else {
			hasLabels = append(hasLabels, label)
		}
	}

	// Transform that into a term
	if len(hasLabels) > 0 || len(excLabels) > 0 {
		var hasTerm gorethink.Term
		if len(hasLabels) == 1 {
			hasTerm = gorethink.Row.Field("labels").Contains(hasLabels[0])
		} else if len(hasLabels) > 0 {
			for i, label := range hasLabels {
				if i == 0 {
					hasTerm = gorethink.Row.Field("labels").Contains(label)
				} else {
					hasTerm = hasTerm.And(gorethink.Row.Field("labels").Contains(label))
				}
			}
		}

		var excTerm gorethink.Term
		if len(excLabels) == 1 {
			excTerm = gorethink.Not(gorethink.Row.Field("labels").Contains(excLabels[0]))
		} else {
			for i, label := range excLabels {
				if i == 0 {
					excTerm = gorethink.Not(gorethink.Row.Field("labels").Contains(label))
				} else {
					excTerm = excTerm.And(gorethink.Not(gorethink.Row.Field("labels").Contains(label)))
				}
			}
		}

		// Append them into the term
		if len(hasLabels) > 0 && len(excLabels) > 0 {
			term = term.Filter(hasTerm.And(excTerm))
		} else if len(hasLabels) > 0 && len(excLabels) == 0 {
			term = term.Filter(hasTerm)
		} else if len(hasLabels) == 0 && len(excLabels) > 0 {
			term = term.Filter(excTerm)
		}
	}

	// Slice the result
	if offset != 0 || limit != 0 {
		term = term.Slice(offset, offset+limit)
	}

	// Add manifests
	term = term.Map(func(thread gorethink.Term) gorethink.Term {
		return thread.Merge(gorethink.Db(t.GetDBName()).Table("emails").Between([]interface{}{
			thread.Field("id"),
			time.Date(1990, time.January, 1, 23, 0, 0, 0, time.UTC),
		}, []interface{}{
			thread.Field("id"),
			time.Date(2090, time.January, 1, 23, 0, 0, 0, time.UTC),
		}, gorethink.BetweenOpts{
			Index: "threadAndDate",
		}).OrderBy(gorethink.OrderByOpts{Index: "threadAndDate"}).
			Nth(0).Pluck("manifest"))
	})

	// Run the query
	cursor, err := term.Run(t.GetSession())
//.........这里部分代码省略.........
开发者ID:carriercomm,项目名称:lavabot,代码行数:101,代码来源:table_threads.go


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