Fork me on GitHub

hey everyone, I am new to clojure and datomic, and I have a simple questions does anyone know why this query:

(d/q '[:find ?id ?type ?urgent
                          [?e :job/id ?id]
                          [?e :job/type ?type]
                          [?e :job/urgent ?urgent]] (get-db))
returns the following: #object[java.util.HashSet 0x4362c471 [[690de6bc-163c-4345-bf6f-25dd0c58e864 bills-questions false]]] but all I want is [690de6bc-163c-4345-bf6f-25dd0c58e864 bills-questions false] I can get the answer I want but using first, but why is datomic retuning such a weird output, is there a way to get just what I actually want?


See here: Basically with :find ?a ?b ?c :where ... you’ll get a set of tuples. This makes sense if you consider that there could be more than one result from your query. If you know there will only be a single result you can use :find [?a ?b ?c] :where ... instead


I have an entity with two reference fields on it. Is there a way to write a datomic query that, given an ID, returns the entity if the id is contained in either ref field? Like an or for a query?


does anyone know how I can save a vector on datomic and retrieve it as if it was any other literal value?

Christian Johansen07:04:05

@mv (or [?e :ns/ref1?id] [?e :ns/ref2?id])

Christian Johansen07:04:31

Datomic queries on the mobile while walking: hard

Christian Johansen07:04:47

@brnbraga95 you can't. store values unsorted with cardinality many. If you need ordering, store refs and add a sort attribute to the entities


if I use cardinality many, then how can I at least retrieve all the values at once and store into an array? assuming lets say, I have an array of favorite foods.

Christian Johansen19:04:58

the entity or pull APIs would be good for that. e.g. (-> (d/entity (d/db conn) my-ref) :myentity/favorite-foods)


problem is that I believe I am not using the entity-id so it just creates a new entity.

(d/transact (get-connection) [
    {:job/id (first job)
      :job/type ((second job) "type")
      :job/urgent ((second job) "urgent")
      :job/timestamp (bigint (System/currentTimeMillis))
      :job/requester agent-id 
      :job/status "doing"}

Christian Johansen07:04:34

Technically you could also store vectors as edn strings, but I wouldn't recommend it


@marshall The password with datomic free works beautifully as soon as I update the peer too. Maybe add this to the page. Feeling stupid after having run in circles for a couple of hours 😉


Is datomic a good fit for a chat app? I have more reads than writes, but if I get too much messages/second to persist and only one transactor at a time can handle writes, I might end up in a situation where the transactor run out of memory. Even in HA mode, an other transactor would replace the dead one, but it would end up in the same situation. Is this true ?


can I assume that a Client that loses its connection to the datomic system will automatically be able to use the connection once it's again available? or is there some logic required to again setup the connection?


peers reconnect automatically (actually it can be sometimes hard to detect--only transactions will fail). I don't know about clients

Datomic Platonic21:04:09

we're getting ActiveMQNotConnectedException trying to connect to datomic on remote host, our url string looks like this: "datomic:<sql://datomic?jdbc:postgresql://>

Datomic Platonic21:04:12

are we mangling the ports somehow? we can connect to 5432 (postgres) but 8998 (peer) and the peer api are not connecting


the URI should be storage

Datomic Platonic21:04:43

the same ports all work fine when the transactor/peer/postgres are all on localhost


the transactor writes its location to storage


the peer reads it from there


and then connects to it


the ArtemisMQ error indicates your peer is connecting to storage but not to the transactor


you need to specify HOST and/or ALT-HOST in the transactor properties file

Datomic Platonic21:04:07

can HOST be localhost? our file reads protocol=sql host=localhost port=4334

Datomic Platonic21:04:15

(we're running the transactor and peer on the same box)


not if the peer is on a different box


what is the full exception?


is there any additional information in the ex-info?


usually tells you what address(es) it’s tried

Datomic Platonic21:04:28

no, just a short stack trace with create-session-factory


this is peer or client?


you mentioned port 8998, which is why i asked


the transactor is up and running?

Datomic Platonic21:04:55

ok transactor is running with datomic:sql://<DB-NAME>?jdbc:<postgresql://localhost:5432/datomic?user=alice&password=secret>

Datomic Platonic21:04:21

peer is serving datomic:<sql://datomic?jdbc:postgresql://localhost:5432/datomic?user=alice&password=secret>


peer-server ??

Datomic Platonic21:04:59

that is the peer server INFO log message


ok, so you are using client

Datomic Platonic21:04:43

transactor and peer are both running on the same remote machine, and we're attempting to launch the PEER client from a laptop REPL


ok; what is in your connection config?


you’ll need the access-key and secret you specified when you started peer server


peer-server is only used to allow clients to connect (not other peers)


if you’re trying to connect a peer (i.e. using datomic.api) from another system, you need to add an alt-host value to your transactor properties file that is the remotely-resolvable address of the transactor instance

Datomic Platonic21:04:39

our clojure repl has [datomic.api] from the datomic-pro, and we have the following uri: datomic:<sql://datomic?jdbc:postgresql://>


that ^ won’t work unless you’ve added as the host (or alt-host) in txor properties file

Datomic Platonic21:04:14

where is the remote IP address for the box with transactor+peer running, and alice and secret are the params in the file


the peer will find postgres at that address specified by the URI


it will find “localhost” written in storage


b/c that’s what you have in host in your properties file


then it will try to connect to the transactor at localhost:4334


it’s almost always better to use the actual system address (as resolvable from outside) for the value of host in your properties file


incidentally, if you’re using a peer you don’t need peer-server running


(unless you’re using peer-server for clients elswhere/also)

Datomic Platonic21:04:18

ah! that worked! we seemed to have made the classic> server error

Datomic Platonic21:04:45

+1 by the way on not needing to start the extra peer server

Datomic Platonic21:04:02

we intend to run 4 peer clients and no cloud api clients for the moment

Datomic Platonic21:04:12

thanks @marshall


does anyone know how I can every value from a certain field that has cardinality many? @christian767 told me to use this (-> (d/entity (d/db conn) my-ref) :myentity/favorite-foods) but I did not quite understood this query