datomic

Ask questions on the official Q&A site at https://ask.datomic.com!
henrik 2020-09-03T09:14:16.201200Z

Why does,

(d/q {:query {:find [?d]
              :where [[_ :some.test/thing ?d]]}
      :args [db]})
Given me a `java.lang.RuntimeException: "Unable to resolve symbol: ?d in this context"`?

henrik 2020-09-03T09:15:30.201700Z

(Trying out dev-local)

cmdrdats 2020-09-03T09:16:43.202100Z

it needs to be quoted so that clojure doesn't try resolve the symbol - '{:find ...}

henrik 2020-09-03T09:17:20.202300Z

Doh, thanks

cmdrdats 2020-09-03T09:17:49.202500Z

:thumbsup:

henrik 2020-09-03T09:18:18.202700Z

Docs don’t specify quoting as necessary: https://docs.datomic.com/cloud/query/query-executing.html#querying-a-database

cmdrdats 2020-09-03T09:18:48.202900Z

curious - that must be a typo

cmdrdats 2020-09-03T09:19:17.203100Z

unless d/q is a macro in the cloud api

henrik 2020-09-03T09:19:17.203300Z

Maybe, or I’m missing some subtlety. @alexmiller?

cmdrdats 2020-09-03T09:19:31.203500Z

I'm used to the on-prem datomic

henrik 2020-09-03T09:19:52.203700Z

I’ve only used Cloud, but it was a while back

cmdrdats 2020-09-03T09:20:02.203900Z

using on-prem now?

henrik 2020-09-03T09:23:28.204100Z

No, I’ve been doing some other stuff for a while (UX, PLing), but I can’t let dev-local just sit there without trying it out. 🙂

cmdrdats 2020-09-03T10:07:00.204300Z

xD

favila 2020-09-03T13:31:51.204500Z

I think the necessity of quoting is considered “obvious”--a query is a data structure and the symbols in it are not supposed to be resolved eagerly in clojure but used inside the query engine. This can’t be solved with a macro because queries don’t need to be literals

favila 2020-09-03T13:35:20.204700Z

that example in the doc you linked to is just a flat-out bug 🙂

cmdrdats 2020-09-03T14:00:51.205100Z

@favila surely a macro could technically solve this, since it would be able to walk the inputs and quote the symbols.. it would be ugly, so I way prefer the quoting, but doable?

favila 2020-09-03T14:01:40.205300Z

How would a macro look at a query provided as an argument by reference?

favila 2020-09-03T14:01:44.205500Z

vs a literal

favila 2020-09-03T14:02:11.205700Z

(let [q my-query] (d/q q db))?

cmdrdats 2020-09-03T14:15:41.205900Z

I guess it could rewrite the symbols to function calls that would try resolve in local environment or resolve in actual symbols instead.. it would be such a terrible hack

henrik 2020-09-03T14:24:57.206100Z

It’s not that far-fetched, if you consider the find clause a kind of declaration. It’s semantically not much weirder than naming parameters in a defn , even though they may not be declared anywhere beforehand.

cmdrdats 2020-09-03T14:25:53.206300Z

it would be fickle as anything though xD

cmdrdats 2020-09-03T14:26:00.206500Z

quoted is so much simpler

henrik 2020-09-03T14:27:23.206700Z

And yet we don’t have to (defn hello '[person-name] …). But hey, it doesn’t matter much. 🙂

favila 2020-09-03T14:39:30.207Z

the difference is that the slot in defn must be a literal

favila 2020-09-03T14:40:08.207200Z

you can’t (let [my-arg-vector '[person-name]] (defn hello my-arg-vector,,,))

favila 2020-09-03T14:40:32.207400Z

requiring a query literal would be a poor limitation to impose on d/q

favila 2020-09-03T14:40:50.207600Z

(IMO)

Stefan 2020-09-03T14:47:00.210100Z

Hi! In my new job we’re using Datomic Pro on-prem. We’re now trying to setup continuous integration (CircleCI), but lein deps raises an error that it cannot get datomic from http://my.datomic.com (“not authorized”). What is the “idiomatic” way to use Datomic in continuous integration? Both for testing and for generating release builds? Thanks!

2020-09-03T14:48:51.211400Z

do you have a private maven repo that the CI can access? If so you could mirror the dependency there

cmdrdats 2020-09-03T14:49:03.211700Z

(defmacro q [body]
  (println &env))

Stefan 2020-09-03T14:49:05.211900Z

No I’m afraid not.

cmdrdats 2020-09-03T14:49:08.212Z

(let [qr [:find]] (q qr))
{qr #object[clojure.lang.Compiler$LocalBinding 0x694600ab clojure.lang.Compiler$LocalBinding@694600ab]}

cmdrdats 2020-09-03T14:49:33.212700Z

but yes - there would be all sorts of caveats

cmdrdats 2020-09-03T14:49:50.213100Z

it would be terrible xD

alexmiller 2020-09-03T14:50:26.214200Z

you do have a private maven repo with your on-prem license

alexmiller 2020-09-03T14:51:23.216400Z

I'm not sure what's supported in circleci wrt setting up access to it

marshall 2020-09-03T14:51:26.216700Z

if you login to your http://my.datomic.com dashboard there are instructions for configuring access to the private maven repo

marshall 2020-09-03T14:51:52.217900Z

you’ll need to add user/pw to your leiningen config. older versions required gpg-encrypted key files

marshall 2020-09-03T14:51:58.218300Z

i dont know if that’s still true

Stefan 2020-09-03T14:52:31.219300Z

Ah that’s good to know, I had no idea. I will have to check with the person who set it up originally then. I think given your info we should be able to get it going, thanks!!

2020-09-03T14:52:33.219400Z

CircleCi has a feature to pass secrets as env. vars., you could use that to pass the pw to the build

👍 2
henrik 2020-09-03T14:56:14.220700Z

(defmacro d-q [q-map]
  `(d/q ~(assoc q-map :query `(quote ~(:query q-map)))))
😅

2020-09-03T14:56:58.221800Z

if you use leiningen you can call clojure code with unquote, to inject the env var:

:repositories {"my repo"
                 {:url "<http://my.repo.url>"
                  :name "repo name"
                  :username "usernamr"
                  :password ~(System/getenv "DATOMIC_PASSWORD")}}
 

Jasper 2020-09-03T15:42:11.223400Z

Great, thanks a lot, we got it working like that

Björn Ebbinghaus 2020-09-03T16:39:08.225500Z

Is there a way to pull an entity by a composite tuple made out of refs?

favila 2020-09-03T16:52:04.225700Z

Yes, but you need to use raw entity ids

favila 2020-09-03T16:52:54.225900Z

[:aref+bref [123 456]]

favila 2020-09-03T16:53:15.226100Z

(for e.g., assuming that attr is :db/unique and that a and b are both refs)

Björn Ebbinghaus 2020-09-03T16:59:14.226300Z

Hm.. 😕 I hoped I could get away with lookup refs instead of eids…

Björn Ebbinghaus 2020-09-03T16:59:19.226500Z

Thank you anyway

Jake Shelby 2020-09-03T20:40:21.230200Z

[Datomic Cloud] I've seen several references in the documentation that says the Application Name, in context of a CF template param, "cannot be changed later" - however, that parameter does show up if I attempt a parameter upgrade in CF. Will bad things happen if I change that? ... Also - what if I really really do need to change the application name? Like in the case of scaling up my system, by breaking the main app out into a new compute group, but needing to still deploy tx fns to the primary group from a separate application name?

➕ 1