Fork me on GitHub
#sql
<
2020-03-10
>
kwladyka08:03:59

@seancorfield as far as I understand binding and with-redefs it should work for with-redefs even more, because it works also for Thread

kwladyka09:03:13

unless there is something what I don’t know about Clojure

kwladyka09:03:46

#object[org.postgresql.jdbc.PgConnection 0x5f7b586a org.postgresql.jdbc.PgConnection@5f7b586a]

(with-redefs [db-psql/db tx]
  (println db-psql/db)
  (tests))
this even show different value for db than original

kwladyka09:03:03

the value is also replaced in inner function which I call

kwladyka09:03:20

(defn create-shop [shop]
  (println postgres/db)
  (postgres/insert! :shops shop))

kwladyka09:03:00

but not here

(def insert! (partial sql/insert! (or (println "!!!" db) db))

kwladyka09:03:30

it doesn’t replace db only in final function

kwladyka09:03:54

(defn insert! [& args]
  (println "!!!!!!" db)
  (apply sql/insert! db args))
but it works with defn

kwladyka09:03:05

ok I don’t understand this

kwladyka09:03:23

(def a 1)

(with-redefs [a 2]
  (println a))
this shows 2

kwladyka09:03:59

(def a 1)
(def b (partial println "!" a "!"))

(with-redefs [a 2]
  (b a))
this print ! 1 ! 2

kwladyka09:03:18

so it looks like with-redefs doesn’t work with partial?

kwladyka09:03:50

binding doing the same

kwladyka09:03:55

this is the partial issue

kwladyka09:03:15

it looks like it get value of def and doesn’t refer to this def anymore

kwladyka10:03:27

oh I know why… I solved this on #clojure

souenzzo13:03:16

About qualified/unqualified keys, checkout https://github.com/souenzzo/eql-as I'm using it on every project that I work It solves both qualified->unqualified and un->qualified

👍 4