Database 将输入映射作为Datomic查询参数传递
如何将映射作为Database 将输入映射作为Datomic查询参数传递,database,clojure,datomic,Database,Clojure,Datomic,如何将映射作为传递?将输入到数据查询,并对映射进行分解,以便与事实进行匹配 当我运行以下查询时,我得到一个NullPointerException: (d/q '[:find ?e :where :in $ ?input [?e :amount ?amount] [(:amount ?input) ?amount]] (d/db conn) {:amount 123.0M}) => Syntax error (Nu
传递?将
输入到数据查询,并对映射进行分解,以便与事实进行匹配
当我运行以下查询时,我得到一个NullPointerException
:
(d/q '[:find ?e
:where
:in $ ?input
[?e :amount ?amount]
[(:amount ?input) ?amount]]
(d/db conn)
{:amount 123.0M})
=> Syntax error (NullPointerException) compiling at ...
但是,将金额作为输入参数传递,可以:
(d/q '[:find ?e
:where
:in $ ?amount
[?e :amount ?amount]
(d/db conn)
123.0M)
=> [[1234]]
您无法将映射传递到数据日志查询,您仅限于标量、元组、集合和关系: 如果您有一个比示例复杂得多的映射,并且需要使用其中的许多值,则必须在查询外部(如@Alan Thompson所建议的)对其进行分解,并将值作为元组传入:
(让[输入fn(juxt:amount:timestamp:quantity)
输入数据{:时间戳“29/08/2019”:数量3:金额123.0}
输入(输入fn输入数据)]
(d/q'[:查找?e
:单位:$[?金额?时间戳?数量]
:在哪里
[?e:金额?金额]
[?e:时间戳?时间戳]
[?e:数量?数量]]
(d/db连接)
(投入)
也许您只需要在Datomic之外进行解构,就像您的工作示例一样