How to import :bigdec data into datomic

Mike Hogan

I have this schema:

[
  {: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}
]

I try to insert this data:

[
    {:db/id 1, :atr/amount 10, :atr/currency "USD", :atr/clientId "clientId", :atr/valueDate "2014-02-14"}
]

I get this error message:

Caused by: java.lang.IllegalArgumentException: :db.error/wrong-type-for-attribute Value 10 is not a valid :bigdec for attribute :atr/amount

How do I describe bigdec data for import into datomic?

Ben Kamphaus

You need to use the appropriate data literal to express the value in this case (using M to indicate 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)}
   ])

Or otherwise create the correct value type (as with date below):

(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)}
   ])

Both of these examples will transact correctly against your schema.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How does the storage backend influence Datomic?

From Dev

How can I use Datomic Pro on Heroku?

From Dev

How do I undo or reverse a transaction in datomic?

From Dev

Importing data older than last transaction into datomic

From Dev

How to import data into postgres

From Dev

How to normalize data on import efficiently?

From Dev

How to import "loader" format data using SQLDeveloper?

From Dev

How to retract attributes in Datomic?

From Dev

How can I get the current Datomic schema?

From Dev

how to get the datetime of the last transaction in a datomic db?

From Dev

How to import data to a vector in R

From Dev

How to import SQL table data to Redis Cache?

From Dev

Inserting data into Datomic partition

From Dev

How to Import statistica data (*.sta) into R

From Dev

How to Import Data from excel to SPSS

From Dev

Clojure bigdec division rules

From Dev

How can I import XML data into Hadoop

From Dev

How to query datomic for all datoms in a particular partition?

From Dev

Datomic - how to retract all values of an attribute

From Dev

Using Plumatic Schema to coerce to bigdec

From Dev

How to represent an entity with an existing UUID in Datomic?

From Dev

How to import data.table indexing functionality?

From Dev

How to use / in a Datomic query?

From Dev

How to import data into postgres

From Dev

Importing data older than last transaction into datomic

From Dev

How to import Excel data into gridview

From Dev

How to Import Webview data into the listview

From Dev

Inserting data into Datomic partition

From Dev

How to find entities with one of several attributes in Datomic