Fork me on GitHub
#datomic
<
2020-10-21
>
Michael Stokley00:10:02

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"

Michael Stokley00:10:26

here's the subquery i attempted:

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

Michael Stokley01:10:32

that gets me further... thank you!

Michael Stokley01:10:51

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

steveb8n04:10:37

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?

steveb8n05:10:17

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

jaret13:10:24

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

🎉 3
vncz13:10:51

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

jaret13:10:55

@U015VUATAVC Sorry the doc's cache wasn't busted

vncz14:10:55

Ah ok sweet, thanks!

zhuxun219:10:35

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.

favila20:10:28

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

favila20:10:01

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

👍 3
favila20:10:33

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

zhuxun220:10:54

> 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? @U09R86PA4

zhuxun220:10:01

@U09R86PA4 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)))?

favila20:10:36

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

favila20:10:56

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):

favila20:10:28

(d/q '[:find ?release-name
       :in $before $txdata
       :where
       [$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))

👍 3
favila20:10:31

(untested)

zhuxun220:10:26

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

zhuxun220:10:15

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

favila20:10:35

$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

👍 3
favila20:10:41

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

favila20:10:56

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

favila20:10:15

but a vector datasource isn’t that smart

favila20:10:42

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

zhuxun221:10:18

This is very interesting detail. Thanks for the explanation.