Fork me on GitHub
#datomic
<
2021-07-10
>
stuartrexking03:07:03

Does Datomic Ions have lifecycle hooks? I want to manage a DB connection pool and external services with system start or halt events. I canโ€™t see anything in the documentation. How do I do this?

mdave08:07:13

Is it possible to pass a pull pattern as an input to a query? For example this works:

(def p '*)
(d/pull (d/db conn) [p] 1)
And I'm trying to achieve something similar here:
(d/q '[:find (pull ?e [?p])
       :in $ ?e ?p
       :where
       [?e :db/ident _]]
     (d/db conn) 1 '*)
But getting:
Execution error (Exceptions$IllegalArgumentExceptionInfo) at datomic.error/arg (error.clj:79). :db.error/invalid-attr-spec Attribute identifier ?p of class: class java.lang.String does not start with a colon
It's the same error when I try passing a keyword attribute or a the wildcard as a string "*".

oxalorg (Mitesh)08:07:43

Can you try this:

(d/q '[:find (pull ?e p)
       :in $ ?e p
       :where
       [?e :db/ident _]]
     (d/db conn) 1 '[*])

๐Ÿ’ฏ 3
mdave09:07:38

Thank you!

๐Ÿ‘ 3
mdave09:07:45

Actually I tried this version too, but with ?p. I didn't realize that question mark is not only a convention but it's interpreted in a different way in the queries.

oxalorg (Mitesh)09:07:01

Yup this was confusing and I'm not a 100% sure why that is. I think this is because ? symbol is for variables which the query engine must substitute for running the queries. But a pull-pattern is fixed and it doesn't make sense that the query engine should go and replace it. But that's just a guess, if someone can chime in and clear this up it would be super helpful!

๐Ÿ‘ 3