Fork me on GitHub
#datomic
<
2018-04-03
>
brunobraga01:04:36

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
                          :where
                          [?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?

timgilbert03:04:20

See here: https://docs.datomic.com/on-prem/query.html#find-specifications 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

mv02:04:00

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?

brunobraga06:04:25

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

brunobraga12:04:09

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)

brunobraga22:04:54

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

magra09:04:17

@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 😉

ggaillard10:04:52

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 ?

stijn12:04:11

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?

favila18:04:02

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://1.2.3.4:5432/datomic?user=alice&password=secret>

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

marshall21:04:39

the URI should be storage

Datomic Platonic21:04:43

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

marshall21:04:48

the transactor writes its location to storage

marshall21:04:52

the peer reads it from there

marshall21:04:55

and then connects to it

marshall21:04:11

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

marshall21:04:27

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)

marshall21:04:19

not if the peer is on a different box

marshall21:04:18

what is the full exception?

marshall21:04:36

is there any additional information in the ex-info?

marshall21:04:47

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

Datomic Platonic21:04:28

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

marshall21:04:20

this is peer or client?

marshall21:04:34

you mentioned port 8998, which is why i asked

marshall21:04:13

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>

marshall21:04:43

peer-server ??

Datomic Platonic21:04:59

that is the peer server INFO log message

marshall21:04:05

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

marshall21:04:24

ok; what is in your connection config?

marshall21:04:13

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

marshall21:04:38

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

marshall21:04:23

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://1.2.3.4:5432/datomic?user=alice=password=secret>

marshall21:04:09

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

Datomic Platonic21:04:14

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

marshall21:04:40

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

marshall21:04:48

it will find “localhost” written in storage

marshall21:04:58

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

marshall21:04:06

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

marshall21:04:32

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

marshall21:04:28

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

marshall21:04:46

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

Datomic Platonic21:04:18

ah! that worked! we seemed to have made the classic 127.0.0.1->0.0.0.0 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

brunobraga23:04:39

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