撤回在 Datomic 中设置了某个 db/txInstant 的实体?
Retract entity with a certain db/txInstant set in Datomic?
我想收回一个实体,同时指定 db/txInstant
属性,但我无法让它工作。收回实体看起来像这样(并且有效):
[[:db.fn/retractEntity [:person/email "jdoe@example.com"]]]
我尝试了多种方法来提供 db/txInstant
属性,例如:
[[:db.fn/retractEntity [:person/email "jdoe@example.com"]]
[:db/txInstant <inst>]]
但这失败了:
Caused by: datomic.impl.Exceptions$IllegalArgumentExceptionInfo: :db.error/not-a-data-function Not a data function: 50
at datomic.error$arg.invoke (error.clj:57)
datomic.error$arg.invoke (error.clj:55)
datomic.db.Db.getFn (db.clj:1794)
datomic.db.ProcessExpander.inject (db.clj:2473)
datomic.db.ProcessInpoint.inject (db.clj:2372)
datomic.db$with_tx$inject_all__2222$fn__2223.invoke (db.clj:2535)
clojure.lang.PersistentVector.reduce (PersistentVector.java:341)
clojure.core$reduce.invokeStatic (core.clj:6544)
clojure.core$reduce.invoke (core.clj:6527)
datomic.db$with_tx$inject_all__2222.invoke (db.clj:2535)
datomic.db$with_tx.invoke (db.clj:2539)
datomic.peer.LocalConnection/fn (peer.clj:557)
datomic.peer.LocalConnection.transactAsync (peer.clj:557)
datomic.peer.LocalConnection.transact (peer.clj:549)
datomic.api$transact.invoke (api.clj:94)
....
所以我的问题只是在 Datomic 中收回实体时如何指定 db/txInstant
属性?
txInstant 据我了解,它是指定更改(撤回或添加)的事务发生的时间。所以如果你在哪里成功地做到这一点,你实际上是在对交易者说:
"Hey there transactor please create a transaction now that happened sometime other then now"
这会破坏数据库中的所有其他时间语义。这就是为什么我们通常在 datomic 中使用命名空间关键字。
而不是设置 :db/txInstant
设置 :my.company.db/txInstant
。这样你就可以找出由你的交易确定的交易时间,系统的其余部分可以确定交易者创建交易的时间,这将使事件流之类的事情保持愉快。
如果您需要将元数据附加到交易(例如交易发生的原因或任何相关数据),您可以这样做。你可以在 Datomic 网站上找到很好的信息:
http://docs.datomic.com/transactions.html
http://blog.datomic.com/2015/12/reified-transactions.html
以及 Tim Ewald 在 2015 年 11 月 Datomic 会议(Clojure Conj 的前奏)中关于这个确切主题的详细视频:
这对我有用:
(d/transact conn [{:db/id #db/id [:db.part/tx]
:db/txInstant #inst "2016-10-29"}
[:db.fn/retractEntity [:person/email "jdoe@example.com"]]])
我想收回一个实体,同时指定 db/txInstant
属性,但我无法让它工作。收回实体看起来像这样(并且有效):
[[:db.fn/retractEntity [:person/email "jdoe@example.com"]]]
我尝试了多种方法来提供 db/txInstant
属性,例如:
[[:db.fn/retractEntity [:person/email "jdoe@example.com"]]
[:db/txInstant <inst>]]
但这失败了:
Caused by: datomic.impl.Exceptions$IllegalArgumentExceptionInfo: :db.error/not-a-data-function Not a data function: 50
at datomic.error$arg.invoke (error.clj:57)
datomic.error$arg.invoke (error.clj:55)
datomic.db.Db.getFn (db.clj:1794)
datomic.db.ProcessExpander.inject (db.clj:2473)
datomic.db.ProcessInpoint.inject (db.clj:2372)
datomic.db$with_tx$inject_all__2222$fn__2223.invoke (db.clj:2535)
clojure.lang.PersistentVector.reduce (PersistentVector.java:341)
clojure.core$reduce.invokeStatic (core.clj:6544)
clojure.core$reduce.invoke (core.clj:6527)
datomic.db$with_tx$inject_all__2222.invoke (db.clj:2535)
datomic.db$with_tx.invoke (db.clj:2539)
datomic.peer.LocalConnection/fn (peer.clj:557)
datomic.peer.LocalConnection.transactAsync (peer.clj:557)
datomic.peer.LocalConnection.transact (peer.clj:549)
datomic.api$transact.invoke (api.clj:94)
....
所以我的问题只是在 Datomic 中收回实体时如何指定 db/txInstant
属性?
txInstant 据我了解,它是指定更改(撤回或添加)的事务发生的时间。所以如果你在哪里成功地做到这一点,你实际上是在对交易者说:
"Hey there transactor please create a transaction now that happened sometime other then now"
这会破坏数据库中的所有其他时间语义。这就是为什么我们通常在 datomic 中使用命名空间关键字。
而不是设置 :db/txInstant
设置 :my.company.db/txInstant
。这样你就可以找出由你的交易确定的交易时间,系统的其余部分可以确定交易者创建交易的时间,这将使事件流之类的事情保持愉快。
如果您需要将元数据附加到交易(例如交易发生的原因或任何相关数据),您可以这样做。你可以在 Datomic 网站上找到很好的信息:
http://docs.datomic.com/transactions.html
http://blog.datomic.com/2015/12/reified-transactions.html
以及 Tim Ewald 在 2015 年 11 月 Datomic 会议(Clojure Conj 的前奏)中关于这个确切主题的详细视频:
这对我有用:
(d/transact conn [{:db/id #db/id [:db.part/tx]
:db/txInstant #inst "2016-10-29"}
[:db.fn/retractEntity [:person/email "jdoe@example.com"]]])