加入rethinkdb

时间:2016-07-31 09:03:19

标签: rethinkdb

我在RethinkDB表中存储了以下数据结构:

{
   id: string,
   parentId: string,
   timestamp: number,
   data: Object
}

此数据结构形成一棵树,可以使用下图描绘(白色记录表示携带记录的普通数据,红色记录的data属性等于null表示删除操作) :

Diagram

现在,对于表格中的每条记录,我希望能够计算nextRecord。哪个是与当前记录最接近的记录。当只有一条记录指向父级时,任务似乎很简单:

1 => 2
4 => 9
5 => 6
6 => 8
...

但是当父记录被几个子记录引用时,计算这样的值变得更加困难:

2 => 3
3 => 5
7 => 11

在没有子引用时也是如此,在这种情况下结果应该是null(例如记录#8没有子记录,因此应该返回null)。

所以我不是要求自己编写查询(另一方面对我来说真的很棒),但至少指出了我可以找到解决这个问题的方向。

提前谢谢!

1 个答案:

答案 0 :(得分:1)

您可以使用ion-segment-button{ //max-width: 25px; border-style: solid; } .segment-button { border-style: none; border-color: #e62100; color: #e62100; border-width: thin; } .segment-button:first-of-type { border-radius: 90px 90px 90px 90px; // margin-right: 0px; margin-left: 0px; line-height: 3.4rem; height: 100%; width: 100%} .segment-button:not(:first-of-type) { border-radius: 90px 90px 90px 90px; // margin-right: 0px; margin-left: 20px; line-height: 3.4rem; height: 100%; width: 100%;} .segment-button:last-of-type { border-radius: 90px 90px 90px 90px; margin-right: 0px; margin-left: 20px; line-height: 3.4rem; height: 100%; width: 100%;} .segment-activated{ background-color: #e62100; color: #ffffff; } parentId上的复合索引有效地执行此操作。您可以像这样创建索引:

timestamp

完成后,您可以找到父母PARENT最早的项目,如下所示:

r.table('data').indexCreate('parent_timestamp', function(row) {
  return [row('parentId'), row('timestamp')];
})