datomic

Ask questions on the official Q&A site at https://ask.datomic.com!
kenny 2020-10-17T16:31:57.036900Z

I have a query that looks like this .

'[:find ?r
  :in $ ?c [?cur-r ...]
  :where
  [?c ::rs ?r]]
I'd like to restrict ?r to be all ?r's that are not in ?cur-r. Is there a way to do this?

kenny 2020-10-17T16:38:35.037900Z

I could make ?cur-r a data source but that requires me to have ?cur-r db ids for cur-r. Currently only have a list of lookup refs.

'[:find ?r
  :in $ $cur-r ?c
  :where
  [?c ::rs ?r]
  (not [$cur-r ?r])]

2020-10-17T16:41:34.039300Z

Maybe (not [(identity ?cur-r) ?r]) works

kenny 2020-10-17T16:42:21.039600Z

Returns all ?r's

kenny 2020-10-17T16:43:08.039800Z

?cur-r is passed in as a list of lookup refs

kenny 2020-10-17T16:46:17.040Z

I may just have to convert the ?cur-r lookup refs to eids. Not a big deal but it seems like there should be a way to make this happen in a single query 🙂

favila 2020-10-17T18:11:48.041300Z

(not [(datomic.api/entid $ ?cur-r) ?r])

kenny 2020-10-17T18:12:39.042300Z

Ooo, nice! Is datomic.api documented somewhere?

favila 2020-10-17T18:12:49.042600Z

It’s the peer api

kenny 2020-10-17T18:12:57.042800Z

Oh, right - I'm on cloud.

favila 2020-10-17T18:13:10.043200Z

It might still be there

kenny 2020-10-17T18:13:25.043400Z

Perhaps. Not documented though: https://docs.datomic.com/client-api/datomic.client.api.html

favila 2020-10-17T18:13:47.044Z

It would just be on the server’s classpath

kenny 2020-10-17T18:14:02.044500Z

Yeah. Curious if that's able to be depended on though haha.

favila 2020-10-17T18:18:45.046100Z

If you know they are lookup refs you can decompose and resolve the ref

favila 2020-10-17T18:19:10.047100Z

If not you could reimplement entid as a rule

favila 2020-10-17T18:20:57.049100Z

:in [[?cur-a ?cur-v]] :where [?cur-r ?cur-a ?cur-v]

kenny 2020-10-17T18:24:18.053600Z

Ah, that seems like it’d work! Will try it in a bit. Thanks @favila

favila 2020-10-17T18:24:39.054400Z

As a rule [[(entid [?x] ?eid)[(vector? ?x)]...] [(entid [?x] ?eid) [(int? ?x)][(identity ?x) ?eid]] and a keyword case looking up ident

favila 2020-10-17T18:25:17.055Z

Sorry I can’t type out the whole thing, on a phone

Chicão 2020-10-17T19:53:33.055900Z

Hi, does anyone know how to solve this problem?

bin/transactor config/dev-transactor-template.properties               
Launching with Java options -server -Xms1g -Xmx1g -XX:+UseG1GC -XX:MaxGCPauseMillis=50
Starting datomic:sql://&lt;DB-NAME&gt;?jdbc:<postgresql://localhost:5432/datomic?user=datomic&amp;password=datomic>, you may need to change the user and password parameters to work with your jdbc driver
...
System started datomic:sql://&lt;DB-NAME&gt;?jdbc:<postgresql://localhost:5432/datomic?user=datomic&amp;password=datomic>, you may need to change the user and password parameters to work with your jdbc d
river
Terminating process - Lifecycle thread failed
java.util.concurrent.ExecutionException: org.postgresql.util.PSQLException: ERROR: relation "datomic_kvs" does not exist
  Position: 31
        at java.util.concurrent.FutureTask.report(FutureTask.java:122)
        at java.util.concurrent.FutureTask.get(FutureTask.java:192)
        at clojure.core$deref_future.invokeStatic(core.clj:2300)
        at clojure.core$future_call$reify__8454.deref(core.clj:6974)
        at clojure.core$deref.invokeStatic(core.clj:2320)
        at clojure.core$deref.invoke(core.clj:2306)
        at datomic.lifecycle_ext$standby_loop.invokeStatic(lifecycle_ext.clj:42)
        at datomic.lifecycle_ext$standby_loop.invoke(lifecycle_ext.clj:40)
        at clojure.lang.Var.invoke(Var.java:384)
        at datomic.lifecycle$start$fn__28718.invoke(lifecycle.clj:73)
        at clojure.lang.AFn.run(AFn.java:22)
        at java.lang.Thread.run(Thread.java:748)
Caused by: org.postgresql.util.PSQLException: ERROR: relation "datomic_kvs" does not exist
  Position: 31

Chicão 2020-10-17T19:54:16.056Z

this is my config/properties...

protocol=sql
host=localhost
port=4334
sql-url=jdbc:<postgresql://localhost:5432/datomic>
sql-user=datomic
sql-password=datomic
sql-driver-class=org.postgresql.Driver

Chicão 2020-10-17T20:04:00.056200Z

I solve this problem running

CREATE TABLE datomic_kvs (id text NOT NULL, rev integer, map text, val bytea, CONSTRAINT pk_id PRIMARY KEY (id)) WITH (OIDS = FALSE);
ALTER TABLE datomic_kvs OWNER TO datomic; GRANT ALL ON TABLE datomic_kvs TO datomic; GRANT ALL ON TABLE datomic_kvs TO public;

cjmurphy 2020-10-17T21:34:10.056400Z

https://docs.datomic.com/on-prem/storage.html#sql-database

1✔️
cjmurphy 2020-10-17T21:34:45.056700Z

I can see that's where creating that table is documented.