REST API を介して Datomic で「外部結合」を実行しようとしています。https://github.com/Datomic/day-of-datomic/blob/master/tutorial/social_news.cljから、最後の例を取り上げました。
(defn maybe
"Returns the set of attr for e, or nil if e does not possess
any values for attr."
[db e attr]
(seq (map :a (d/datoms db :eavt e attr))))
;; find all users
(q '[:find ?e ?upvote
:where
[?e :user/email]
[(user/maybe $ ?e :user/upVotes) ?upvote]]
(db conn))
データベースに Maybe 関数を挿入したので、次のようにクエリを実行できます。
[:find ?n ?v :in $ :where [?e ?a ?v] [?a :db/ident :db/fn] [?e :db/ident ?n]]
戻り値
:maybe #db/fn{:code "(seq (map :a (d/datoms db :eavt e attr)))", :params [db e attr], :requires [], :imports [], :lang :clojure}
ただし、クエリで関数を呼び出す方法がわかりません。一部のトランザクションに:data/user
属性があり、それが存在する場所の値を取得したいと考えています。実行しようとしているクエリは次のとおりです。:maybe
上記で定義したデータベース関数になりたいです。
[:find ?attr ?v ?when ?who :where
[17592186045423 ?a ?v ?tx true]
[?a :db/ident ?attr]
[(:maybe $ ?tx :data/user) ?who]
[?tx :db/txInstant ?when]]
かなり明白な何かが欠けていると確信していますが、これで1日立ち往生しています。助けてくれてありがとう!