Just generate SQL from ClojureQL's disj! conj! and update-in! functions

250 Views Asked by At

Is there a way to just generate the sql queries from ClojureQL's disj! conj! and update-in! functions, instead of executing them directly ?

1

There are 1 best solutions below

3
On BEST ANSWER

No, these methods are directly executing their respective prepared statements. They are all pretty basic. For conj! and update-in!, look at format call in the conj-rows and update-vals functions that you can find inside the internal namespace:

 (format "INSERT INTO %s %s VALUES (%s)"
         (to-tablename table) columns template)

 (format "UPDATE %s SET %s WHERE %s"
         (to-tablename table) columns where)

For disj!, ClojureQL is using the clojure.java.jdbc library delete-rows function which contains:

  (format "DELETE FROM %s WHERE %s"
          (as-identifier table) where)

So basically disj! get the ability to use java.jdbc's with-naming-strategy and with-quoted-identifiers macros for the table name while the other don't.