datomic

Ask questions on the official Q&A site at https://ask.datomic.com!
joshkh 2020-10-01T10:55:07.155300Z

pulling a reference to an ident returns an entity with the ident's db id as well as its db ident:

(d/q '{:find [(pull ?n [:some/ref])]
       :in   [$ ?n]}
     db 999)

=> [{:some/ref [{:db/id 987 :db/ident :some/ident}]}]
whereas pulling a tuple with a reference to an ident only returns its db id
(d/q '{:find [(pull ?n [:some/tuple])]
       :in   [$ ?n]}
     db 999) 

=> [{:some/tuple [987]}]
it would be great if pulling a reference to an ident from a tuple behaved the same way as pulling a reference to an ident from outside a tuple. i could untuple the values in the query constraints and find their idents, but that constrains my results to only entities that have :some/tuple values, unlike pull

joshkh 2020-10-01T11:07:46.156600Z

in other words, i can't seem to pull https://docs.datomic.com/cloud/schema/schema-modeling.html#enums from within tuples

vncz 2020-10-01T14:15:13.162Z

Hey! I have recently been looking at Datomic, reading the documentation and watching almost every single video I could possibly find on the internet. I really like what I've seen so far; I do have couple of questions that I still haven't figured out. Any help here would be appreciated. I've seen this idea that once you get a db from a connection — it's an immutable value and you can do queries on it by leveraging the query engine that's embedded in the application. That is a great abstraction, but I am assuming that under the hood the peer library will be grabbing the required datoms from the storage engine; that inevitably will go over the network. With that in mind: • What happens if there's a network failure while fetching the data from the storage? Is the peer library going to retry that automatically? What if it fails continuously? Will I ultimately see a thrown exception out of nowhere? • What happens if to satisfy a query the peer library needs to grab more data from the storage engine? Is that going to block the thread where the query is being executed? (I'm assuming this depends on whether I'm using the sync or async API)

Sam DeSota 2020-10-01T14:26:05.165900Z

Hey all, we just had an issue where ##NaN was transacted into a datomic on-prem db, and a couple weird things happened: • It was impossible to update the values, unless you manually used db/retract + db/add, just using db/add would not automatically retract ##NaN value • We also couldn’t search for the ##NaN values with a query Is this known undefined behavior or a bug that should be reported? Seems like ##NaN values shouldn’t even be allowed to be transacted.

👍 1
vncz 2020-10-01T14:26:18.166200Z

I am also kind of confused of what client I should be using here :thinking_face:

pvillegas12 2020-10-01T14:28:03.167300Z

Does somebody know how to increase the number of instances in a production topology? Switching the auto scaling group to 3 for example failed when trying to deploy our ion in Datomic Cloud

Joe Lane 2020-10-01T14:55:11.167400Z

Have you investigated query groups @pvillegas12?

Joe Lane 2020-10-01T14:56:02.167600Z

See https://docs.datomic.com/cloud/operation/scaling.html

Joe Lane 2020-10-01T14:56:46.167800Z

You likely DON'T want to be autoscaling your primary group.

marshall 2020-10-01T15:07:39.168500Z

The details of the answers to these questions depend a little bit on whether you're talking about the client API (cloud or on-prem) or the peer API (on-prem only)

zane 2020-10-01T15:07:50.168700Z

I recall someone saying there’s a library out there with a clojure.spec spec for Datomic queries. Does anyone know where I could find it?

marshall 2020-10-01T15:08:21.169Z

cloud or on-prem ? or dev-local?

vncz 2020-10-01T15:51:22.169200Z

I have a local Datomic instance running on my computer but I could switch to dev-local if that makes the things easier. I'm more curious about why 3 different libraries

vncz 2020-10-01T15:52:32.169400Z

Ah ok interesting. I'll definitely take a look at it then

marshall 2020-10-01T16:10:28.169600Z

if you're using on-prem you can use the peer library or you can use the peer-server & the client-pro library

vncz 2020-10-01T16:16:51.169800Z

@marshall Is there a documentation page that explains a little bit the differences and when to use what?

marshall 2020-10-01T16:17:17.170Z

the clients vs peer page i linked in the other thread

vncz 2020-10-01T16:26:08.170200Z

Ah all right, I'll check that out before continuing the conversation. Thanks for the help @marshall

Josh 2020-10-01T17:32:04.170400Z

This library defines a bunch of datomic specs https://github.com/alexanderkiel/datomic-spec/blob/master/src/datomic_spec/core.clj

zane 2020-10-01T18:12:04.170700Z

Brilliant. Cheers!

2020-10-01T19:58:30.170900Z

Note, this is the on prem dialect, cloud (and using client to access a peer server on prem), has slight variations

2020-10-01T19:59:23.171200Z

For example, cloud only allows one shape of :find

2020-10-01T20:24:26.172300Z

Is there any way to check that entity id is temporary? Does (*instance?* datomic.db.DbId val) work?

Linus Ericsson 2020-10-05T09:45:47.231300Z

In on-prem (maybe also on client) you should use the :tempids key in the transaction result, there and use datomic.api/resolve-tempid to resolve the tempids to realized entity-ids.

2020-10-05T14:51:42.245400Z

@oscarlinusericsson yep, and I do this. But anyway I need a criteria, are some ids temporary, for resolving it that way. Or you suggest to resolve any id as temporary first, and if it is not resolved this way (or throws an exception), then it probably is a real id and trying to use it an non-temporary?

Linus Ericsson 2020-10-05T15:00:15.250500Z

if you create your ids with datomic.api/tempid then you can check if they are an instance of datomic.db.DbId. But that requires your code to use the tempid function, of course. If you transact data with tempids, that already can be resolved to entities (through external indexes and more), the tempids can be resolved to already existing entities, yes. Tempids do not have to create new entities, they can be resolved to already existing entities.

zilti 2020-10-01T21:25:49.173800Z

What is Datomic's way to achieve this:

[:find ?dbid .
 :in $ ?name ?domain
 :where
 (or [?dbid :company/name ?name]
     [?dbid :company/domain ?domain])]

souenzzo 2020-10-01T21:52:15.174100Z

@zilti or-join

👍 1
favila 2020-10-01T21:58:39.174200Z

depends on context. strings and negative numbers can also possibly be tempids

2020-10-01T22:35:29.174500Z

Hm... So, having an entity id, we can not chose the right way to resolve entity, we should add boolean flag is it tempid or not, and then resolve them different ways depending on this flag...

vncz 2020-10-01T22:59:55.174700Z

@marshall I've just reviewed the document. I guess my confusion is here > Compared to the Peer API, the Client API introduces a network hop for read operations, increasing latency. Doesn't the Peer API also need to grab the data from the storage engine? How does the data get delivered then?

marshall 2020-10-01T23:21:31.174900Z

Peer reads directly from storage itself, client sends the request to peer server or a cloud node, where the storage read occurs