Ask questions on the official Q&A site at https://ask.datomic.com!
oxalorg (Mitesh) 2020-12-02T13:36:53.039700Z

I'm trying to add a child entity with a ref to a parent entity using a lookup-ref

(d/transact conn {:comments/title "foo" :comments/article [:article/title "bar"]})
But I have incomplete data of B. So sometimes there is no article called "bar". This gives me a :db.error/not-an-entity error. How would I go about writing this query so that if "bar" does not exist then only add the child "foo" but keep it's :child/parent attribute as empty?

plexus 2020-12-02T14:48:43.041200Z

I'm setting up Datomic Analytics for a client, and am running into an issue with BigDecimal

{:type "java.lang.ArithmeticException",
   :message "Rounding necessary",
   :suppressed [],

plexus 2020-12-02T14:49:08.041400Z

could this be a bug in the connector?

ghadi 2020-12-02T16:17:41.042100Z

@plexus I seem to recall the latest release notes having something about that


are there diagramming techniques or approaches that are more suited to datomic than traditional sql rectangles - "an entity relationship diagram"?


like drawing nodes and named edges, maybe?

alexmiller 2020-12-02T17:03:34.044200Z

erds are still pretty useful as long as you keep in mind that entity "types" are a fiction of your model, not a constraint in Datomic

alexmiller 2020-12-02T17:04:49.044500Z

for example, here's a Datomic schema Rich made for Codeq https://github.s3.amazonaws.com/downloads/Datomic/codeq/codeq.pdf


thank you! looks like it leaves off the entity names - which, as you say, are a fiction.

alexmiller 2020-12-02T17:07:07.045Z

in any of those rectangles you have a bunch of attributes that are used together (but just keep in mind that the box doesn't really exist). the lines (attributes) are the important part

alexmiller 2020-12-02T17:08:10.045300Z

I think yellow boxes there indicate uniqueness

alexmiller 2020-12-02T17:08:57.045500Z

there is one for the mbrainz sample at https://github.com/Datomic/mbrainz-sample

alexmiller 2020-12-02T17:09:44.045800Z

that one has a stronger sense of entity type (but really is just a shared namespace for the attrs)

alexmiller 2020-12-02T17:11:36.046Z

these are both good examples of what Datomic devs do - different variants may emphasize different aspects of the schema (type, cardinality, uniqueness, component)


this is very helpful, i appreciate it.


good to know that this is the diagramming style favored by other datomic developers.

pithyless 2020-12-02T17:15:43.046600Z

@mitesh 3 common ways to go about this: 1. Change the [:article/title "bar"] to {:article/title "bar"}. Assuming :article/title is unique and :comments/article is a to-one relationship, this won't throw the error, but will either use the existing article or create a new article (with just that attribute). 2. If you don't want to create a new (possibly incomplete article), you need to query the db for existence before doing the transact and modify the transaction accordingly. 3. If you're querying the DB to check for existence and then doing a transact, this may lead to a race-condition. If this is important to avoid, you can instead create a custom transaction function and move the check for existence within the transactor. This will guarantee that you don't have a race-condition (your transaction function will check for existence of the article and then transform the transaction data accordingly before committing).

Wojtek 2020-12-02T20:31:27.049200Z

I have few really slow datomic queries - how could I improve them?


The usual answer would be: do you have the order of your clauses correct

Wojtek 2020-12-02T23:54:24.050200Z

thank you! but I have already tried to reorder my clauses without improvement 😞