如何用原子表示数据透视表(上面有额外的数据)? [英] How to represent pivot table (with extra data on it) in datomic?

查看:82
本文介绍了如何用原子表示数据透视表(上面有额外的数据)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到我们不需要datomic中的普通数据透视表,因为我们可以选择关系的一侧,并在其上放置:db.cardinality / many 属性那里(请务必仅在一个方向上对 )。


我从sql转换时遇到的下一件事是数据透视表,该数据透视表还存储关系的属性,例如:


< pre $ = lang-sql prettyprint-override> series_subscriptions
user_id int
series_id int
expires_at时间戳记

我想知道用原子学建模的选项是什么。
我注意到架构中有些事情我尚不了解其原因或适当的用法,例如复合元组,组件。


一个选择是提高转到其自己的实体,以便它可以处理额外的属性:

 :series-subscription / user; ref,一个
:series-subscription / series; ref,一个
:series-subscription / timestamp;时间戳记,一个

但是以上方法似乎有点错误。这样做意味着在数据记录中,连接将不再是隐式的,这似乎是一种损失。不知道是否有更好的选择。

解决方案

自从2019年7月引入元组以来,元组是更简洁的方法。 / p>

请参阅这个问题



2019年7月对Datomic进行的更新一次包含了许多不同的功能,在线使用情况尚不完善,尽管文档确实对此做了解释(解释起来并不需要太多-一种简单的情况,但也许并不容易)。请注意,专门解决此问题的是 异构 元组,可以忽略其他类型的元组来开始使用此用例。


I realise that we don't need ordinary pivot tables in datomic because we can just pick one side of the relationship and put a :db.cardinality/many attribute on there (being sure to model the relationship in one direction only).

The next thing I encounter in converting from sql is a pivot table that also stores an attribute on the relationship, like:

series_subscriptions
  user_id    int
  series_id  int
  expires_at timestamp

I was wondering what the options are to model this in datomic. I notice there are some things in schema that I don't understand the reason for yet, or appropriate usage, like composite tuples, components.

One option though is elevate the pivot to its own entity so it can handle the extra attribute:

:series-subscription/user       ; ref, one
:series-subscription/series     ; ref, one
:series-subscription/timestamp  ; timestamp, one

But the above seems a bit wrong. Doing it like that means in datalog the join would no longer be implicit, which would appear to be a loss. Wonder if there are better options.

解决方案

Heterogeneous tuples are the more concise way to achieve this since their introduction in July 2019.

See the answer to this question.

The July 2019 update to Datomic contained a lot of different features all at once and usage is not yet well documented online, though the docs do explain it (not much is needed to explain it - a case of simple but, perhaps, not easy). Note it's specifically heterogeneous tuples that solve the concern here, it would work to ignore the other types of tuples to get started for this use case.

这篇关于如何用原子表示数据透视表(上面有额外的数据)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆