Fork me on GitHub
#luminus
<
2017-02-25
>
rickmoynihan00:02:39

ballpark depending on your use case JWT might not be secure: http://cryto.net/~joepie91/blog/2016/06/13/stop-using-jwt-for-sessions/

janvanryswyck14:02:42

I’m having a hard time getting transactions to work In database/core.clj I have something like this: (defstate ^:dynamic db :start (conman/connect! {:jdbc-url (env :database-url)}) :stop (conman/disconnect! db)) (conman/bind-connection db "sql/eventstore.sql") (defn within-transaction [operation] (conman/with-transaction [db] (do operation db)))

janvanryswyck14:02:13

And is a separate file I have (db/within-transaction (fn[trn-conn] (append-to-event-stream trn-conn events))) where I explicitly specify the connection to every DB operation. But it seems that nothing ever gets persisted

janvanryswyck14:02:36

All (easy) examples I can find start transactions in functions within database/core.clj but not in other files.

janvanryswyck14:02:31

Can’t seem to get this working. Either records get persisted, but when an exception occurs, nothing gets reverted OR nothing gets persisted at all in a happy path scenario

yogthos15:02:45

could you try using the regular clojure.java.jdbc with-db-transaction instead. You'd just have to pass the transactional connection to the query functions using it.

janvanryswyck15:02:59

Yes, that does seem to do the trick

janvanryswyck15:02:02

Also moving conman/with-transaction to the separate file seems to work as well

janvanryswyck15:02:39

(conman/with-transaction [db] (append-to-event-stream aggregate-id aggregate-version events))

janvanryswyck15:02:33

This was it doesn’t seem to be necessary to pass in the individual connection to the query functions

yogthos16:02:53

yeah I think it's the problem with the way the conman with-transaction macro is setup

janvanryswyck16:02:43

It would be nice if somehow this could work: (defn within-transaction [operation] (conman/with-transaction [db] (do operation)))

janvanryswyck16:02:23

Without passing a transactional connection. This would mean that it would somehow be picked up automagically.

janvanryswyck16:02:33

Not sure if that would work though

janvanryswyck16:02:12

I’m still a the noob level with the Luminus template

yogthos21:02:16

so this is what with-transaction looks like:

(defmacro with-transaction [args & body]
  `(clojure.java.jdbc/with-db-transaction [t-conn# ~(first args) ~@(rest args)]
     (binding [~(first args) t-conn#]
       ~@body)))
I think that if you pass a fully qualified db or have it referenced explicitly in the namespace you run with-transaction, it should work as expected