在Datomic中使用事件时间而不是事务时间? [英] Use event time instead of transaction time in Datomic?

查看:201
本文介绍了在Datomic中使用事件时间而不是事务时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景

我使用Datomic存储由其他系统生成的事件的投影(在这种情况下,投影可以被视为实体在Datomic)。这些事件具有与它们相关联的时间戳,用于告知事件何时(例如)创建。这显然不同于在投影中存储新属性(基于事件)时Datomic将分配给事务的事务时间。我的应用程序的用户对事务时间不感兴趣,而是事件时间。我首先使用Datomic的原因是为了能够获得一个实体(或查询数据库),因为它在特定的时间。但是这个时间不应该是Datomic交易时间,而是事件时间。例如,我希望能够根据此事件时间获取实体:

I'm using Datomic to store projections of events generated by other systems (projections in this case can be regarded as an entity in Datomic). These events have a timestamp associated with them that tells when the event was (for example) created. This is obviously not the same as the transaction time that Datomic will assign to the transaction when it stores a new attribute (based on the event) in the projection. Users of my application are not interested in the transaction time but rather the event time. The reason why I'm using Datomic in the first place is to be able to get an entity (or query the database) as it were at a specific time. However this time should not be the Datomic transaction time but rather the event time. For example I want be able to get an entity based on this event time:

(datomic/entity (datomic/as-of db event-time) id)

strong>

Possible solution

我想到的一个想法是将每个事务的:db / txInstant 事件时间,但我已建议不要这样做作为一般原则。另一个潜在的问题是,您不能分配比模式更早的:db / txInstant 我的应用程序)。一个解决方案是为创建模式的事务设置一个真正早的:db / txInstant

One idea that I'm thinking of is to set :db/txInstant for each transaction to the event time but I've been advised not to do this as a general principle. Another potential problem with this is that you can't assign a :db/txInstant that is older than the schema (which will be the case in my application). A solution to this would be to set a really early :db/txInstant to the transaction creating the schema.

问题

Datomic中如何处理事件时间而不是事务时间?

How does one typically deal with event time rather than transaction time in Datomic? How does the "possible solution" hold up?

推荐答案

一般来说,Datomic的事务时间( t )用于记录系统何时发现事实,而不是事实的域时间。

In general, Datomic's transaction time (t) is intended to record when the system found out about a fact, not the domain time of the fact.

如果您需要处理域时间(即在真实世界中出现的时间,或者示例中的事件时间),我强烈建议使用属性显式地建模域时间(您可以使用类型的属性:db .type / instant )。这将允许您设置日期没有任何限制,以及查询域时间和系统时间单独的问题,如X发生什么时候和我的数据库发现了什么时候发生了什么。。

If you need to handle domain time (i.e. the time something occurred in the 'real world', or event time in your example), I'd strongly recommend modeling the domain time explicitly with an attribute (you can use an attribute of type :db.type/instant). This would allow you to set dates without any restriction as well as query both domain time and system time separately for questions like "when did X happen AND when did my database find out about X happening?".

这篇关于在Datomic中使用事件时间而不是事务时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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