硬核上新——ftrack API中的筛选技巧

对于所有开发者,如何高效率地筛选是非常重要的。ftrack API已经准备了多种灵活的备选方案,让大家可以根据不同的关联来查找自己所需。现在,我们已经将它升级了。

在我们学习新技能之前我们来稍微复习一下怎么用API来做筛选吧。

     选取标量(scalar)属性是最基础的,比如我们可以查找在特定日期曾发表过的备注:

     Note where date is "2018-05-25"

     或者我们可以组合一下条件:

     Note where date > "2018-05-01"  and date < "2018-06-01"

    ftrack当然也支持根据关联筛选,这里我们可以根据标量关系进行查找。比如,我们可以查找某人曾发表过的所有备注:

    Note where author.username is "john.doe"

当然,不同句法也是可以选出同样的内容,比如用“has”来筛选:

Note where author has (username is "john.doe")

 超简单的,对吧。现在我们来试试用集合关系进行查找:

Note where replies.author.username is "john.doe"

细心的读者大概已经注意到我们结合着筛选了一个集合(replies)和一个标量(author),那么假如我们不知道作者的全名(John.doe),但是我们知道他的名字和姓氏(却不知道中间名),那么我们该如何筛选呢?

    Note where replies any (author.first_name is "John" and author.last_name is "Doe")

这时候我们就可以使用“any”来作为筛选的关键字,它可以让我们筛选集合中所有同时满足条件的情形(first_name and last_name)。

让我们来提前感受一下新上的子查询吧

我们升级的ftrack可以使用子查询了。代码句法和之前的筛选非常相似,不过它可以把之前的筛选作为条件:

<Entity> where <Attribute> in (<Query>)

比如,我们可以用新语法重写上面那个查找备注和回复的例子:  Note where id in (select in_reply_to_id from Note where author. username is "john.doe")

我们能得到同样的结果,但是使用的确是不同的语句。此外,子查询也很适用于基于非常规情形查找,比如根据父一级的某个属性来查找备注。

举个例子,把所有任务状态为“正在进行”的相关备注找出来。

Note where parent_id in (select id from Task where status.name is "In progress")

以上是我们新特性简略介绍,对于更多更详细的关于API和筛选的信息,我们可以详细阅读以下网站:

·       API Query Examples:http://help.ftrack.com/articles/1472152-query-examples

·       API Query Syntax:http://help.ftrack.com/articles/1040506-query-syntax

·       Python client:http://ftrack-python-api.rtd.ftrack.com/en/stable/querying.html?_ga=2.56069547.1616721267.1561511769-726959657.1560739233

·       JavaScript client:http://ftrack-javascript-api.rtd.ftrack.com/en/stable/?_ga=2.56069547.1616721267.1561511769-726959657.1560739233

发布了23 篇原创文章 · 获赞 1 · 访问量 1651

猜你喜欢

转载自blog.csdn.net/weixin_44662629/article/details/94206935