我有这个架构:
[
{:db/id #db/id[:db.part/db]
:db/ident :atr/amount
:db/valueType :db.type/bigdec
:db/cardinality :db.cardinality/one
:db/fulltext false
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :atr/clientId
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/fulltext true
:db/doc "The client who owns this atr"
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :atr/currency
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/fulltext true
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :atr/valueDate
:db/valueType :db.type/instant
:db/cardinality :db.cardinality/one
:db/fulltext true
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :community/reference
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db.install/_attribute :db.part/db}
]
我尝试插入这些数据:
[
{:db/id 1, :atr/amount 10, :atr/currency "USD", :atr/clientId "clientId", :atr/valueDate "2014-02-14"}
]
我收到此错误消息:
Caused by: java.lang.IllegalArgumentException: :db.error/wrong-type-for-attribute Value 10 is not a valid :bigdec for attribute :atr/amount
如何描述要导入datomic的bigdec数据?
答案 0 :(得分:3)
在这种情况下,您需要使用适当的数据文字来表示值(使用M表示BigDecimal):
(def foo-tx
[
{:db/id (d/tempid :db.part/user)
:atr/amount 10M
:atr/currency "USD"
:atr/clientId "clientId"
:atr/valueDate #inst "1985-04-12T23:20:50.52Z"} ;;)(new java.util.Date)}
])
或以其他方式创建正确的值类型(与下面的日期一样):
(def foo-tx
[
{:db/id (d/tempid :db.part/user)
:atr/amount 10M
:atr/currency "USD"
:atr/clientId "clientId"
:atr/valueDate (new java.util.Date)}
])
这两个示例都将针对您的架构进行正确的交易。