Ask questions on the official Q&A site at https://ask.datomic.com!

are subqueries only possible with ions? i'm fooling around and i'm running into cognitect/not-found errors that tell me "'datomic/ion-config.edn' is not on the classpath"


here's the subquery i attempted:

(d/q `[:find ~'?contract ~'?latest-snapshot-tx-instant
         [~'?contract :contract/id]
         [(datomic.client.api/q [:find (~'max ~'?snapshot-tx-instant)
                                 [~'?contract :contract/snapshots ~'?_ ~'?snapshot-tx]
                                 [~'?snapshot-tx :db/txInstant ~'?snapshot-tx-instant]])

Joe Lane 2020-10-21T00:57:58.088900Z

use [(q @michael740


that gets me further... thank you!


a humble suggestion to whoever may have control over the documentation: i could not find the q function documentation when googling "datomic subquery"

steveb8n 2020-10-21T04:46:37.092500Z

Q: I want to use an API-Gateway custom authorizer (lambda) with Ions. The authorizer decorates the request which is passed through to the Ion Lambda (I’m not using http-direct yet). The auth data is in the lambda request “context”, not in headers. Using a ring handler which has been “ionized” I can’t figure out how to access that data. Has anyone got any experience with this?

steveb8n 2020-10-21T05:02:17.092800Z

I found the answer in the docs. the “requestContext” is in the web ion request

jaret 2020-10-21T13:45:24.093800Z

Cognitect dev-tools version 0.9.51 now available Version 0.9.51 of Cognitect dev-tools is now available for download. See https://forum.datomic.com/t/cognitect-dev-tools-version-0-9-51-now-available/1666

vncz 2020-10-21T13:57:51.094200Z

@jaret I can't find anything in the documentation about the MemDB feature; what's that about?

jaret 2020-10-21T13:59:55.094400Z

@vincenz.chianese Sorry the doc's cache wasn't busted

vncz 2020-10-21T14:28:55.094800Z

Ah ok sweet, thanks!

zhuxun2 2020-10-21T19:41:35.099900Z

What's the idiomatic way to > retract (`:db.fn/retractEntity`) all the releases that have a particular given :release/artist, and return the list of :release/name's of the releases retracted, all done atomically I know that the first part can be done with a transaction function, and the second part can be extracted manually from the "TX_DATA" key in the transaction report map. However, I found manual extraction to be too much dependent on the structure of the transaction report map, which seems to be rather subject to future changes. I was wondering if there's a more elegant way of doing this that I am not aware of.

favila 2020-10-21T20:08:28.101200Z

the tx-data report map has been stable for years AFAIK. what difficulty are you encountering specificaly?

favila 2020-10-21T20:10:01.101400Z

My go-to strategy in this case would be to look in tx-data for datoms matching pattern [_ :release/name ?value _ false] . That will only tell you that a value was retracted, not that a retractEntity caused it. With some domain knowledge you could refine that further

favila 2020-10-21T20:10:33.101600Z

(note you’ll have to resolve :release/name to its entity id somehow)

zhuxun2 2020-10-21T20:18:54.101900Z

> look in tx-data for datoms matching pattern ... Interesting ... does Datomic provide a mechanism to do this kind of matching against a list of datoms? @favila

zhuxun2 2020-10-21T20:24:01.102300Z

@favila Or do I have to do (map #(nth 2 %) (filter (fn [[e a v t f]] (and (= :release/name a) (not f))) (:tx-data query-report)))?

favila 2020-10-21T20:27:36.102700Z

That should be enough; if you need more sophistication you can use d/q with the :db-before or :db-after dbs

favila 2020-10-21T20:29:56.102900Z

e.g., I want all release names for all entities which lose a release name but don’t gain a new one within a transaction (i.e. they only lose, not change their name):

favila 2020-10-21T20:30:28.103100Z

(d/q '[:find ?release-name
       :in $before $txdata
       [$before ?release-name-attr :db/ident :release/name]
       [$txdata ?e ?release-name-attr ?release-name _ false]
       ($txdata not [?e ?release-name-attr _ _ true])
     (:db-before result) (:tx-data result))

favila 2020-10-21T20:30:31.103300Z


zhuxun2 2020-10-21T20:40:26.103600Z

I think this is what I was looking for. Thanks!

zhuxun2 2020-10-21T20:52:15.103900Z

@favila Wait ... wasn't [$before ?release-name-attr :db/ident :release/name] implied? Why did you have to put it in the query?

favila 2020-10-21T20:55:35.104100Z

$txdata is a vector of datoms, which is a valid data source, but doesn’t understand that :release/name is an ident with an equivalent entity id. So just putting [$txdata _ :release/name] would never match anything

favila 2020-10-21T20:56:41.104300Z

that you can say [_ :attr] or [_ :attr [:lookup "value"] or [_ :attr :ident-value] is magic provided by the datasource

favila 2020-10-21T20:56:56.104500Z

the database “knows” that those map to entity ids and does it for you

favila 2020-10-21T20:57:15.104700Z

but a vector datasource isn’t that smart

favila 2020-10-21T20:57:42.104900Z

so you need to match the entity id of :release/name exactly

zhuxun2 2020-10-21T21:03:18.105200Z

This is very interesting detail. Thanks for the explanation.