Does jdbc/with-options
work with jdbc/with-transaction
?
@danisam17 Per the Getting Started docs:
> Note: Because get-datasource
and get-connection
return plain JDBC objects (`javax.sql.DataSource` and java.sql.Connection
respectively), next.jdbc/with-options
cannot flow options across those calls, so if you are explicitly managing connections or transactions as above, you would need to have local bindings for the wrapped versions:
(and then it has specific examples on how to handle that)
See https://cljdoc.org/d/seancorfield/next.jdbc/1.1.547/doc/getting-started#options--result-set-builders
Oh I see, thanks a lot @seancorfield
hey! I feel like I'm about to ask a very newb question but I'm new to Clojure in general 🙈
I have the following dependencies in my project.clj
:
[seancorfield/next.jdbc "1.1.547"]
    `[org.postgresql/postgresql "42.2.10"]`
    `[honeysql "1.0.444"]`
and then have the following in my require
in core.clj
:
[next.jdbc :as jdbc]
    `[honeysql.core :as sql]`
And I'm getting the following compilation error:
Exception in thread "main" <http://java.io|java.io>.FileNotFoundException: Could not locate clojure/datafy__init.class or clojure/datafy.clj on classpath., compiling:(next/jdbc/result_set.clj:1:1)
when I take out the require
of [next.jdbc :as jdbc]
it DOES successfully compile
Any idea what I'm doing wrong? Thanks 😃
Sounds like you're on an old version of Clojure.
next.jdbc
requires at least Clojure 1.10.
https://cljdoc.org/d/seancorfield/next.jdbc/1.1.547/doc/getting-started -- "It is designed to work with Clojure 1.10 or later"
@binny Does that help?
oh damn! That's it! I see I'm running on 1.8. It's now downloading the new jar....I will update when it runs!
uuhhmm. Now it's throwing me another error but it's not connected since the error still occurs when I require jdbc:
Exception in thread "main" Syntax error macroexpanding clojure.core/refer-clojure at (clojure/core/async.clj:9:1).
Call to clojure.core/refer-clojure did not conform to spec.
It seems like upgrading gave me another issue 😜
To the Googles!
Thanks for your super quick response, @seancorfield
figured this one out too. I'm using Morse (Telegram bot interface) and that dep was outdated. Thanks again!
Clojure 1.9 tightened up a lot of the syntax checks.
With next.jdbc, how do i get a query like (jdbc/execute! ds ["select (foo,bar) from tableX join tableY on ....."])
to return a maps with of the form [{:foo ...,:bar ...} , ...]
?
I now get a vector with {:row PGObject}
elements
Is there some option i have to pass to execute!
?
What do folks recommend for managing DB changes? Seeing Migratus, Ragtime, and Joplin. I've used Migratus before but it's been a while and wanted to see what others thought.
I used migratus, but now Liquibase.
Ragtime works fine for me and my team, we use it with postgres
In next.jdbc
how would I convert org.postgresql.jdbc.PgArray
in the result set to clojure array?
@danisam17 something like this: https://github.com/nomnom-insights/nomnom.utility-belt.sql/blob/master/src/utility_belt/sql/conv.clj#L32-L38
@danisam17 https://cljdoc.org/d/seancorfield/next.jdbc/1.1.547/doc/getting-started/tips-tricks#working-with-arrays (the docs have all sorts of useful stuff in them -- they're worth reading 🙂 )
@danielglauser We wrote our own, using sequential numbers like Ragtime and if we were starting again, I think we'd use Migratus instead.
What are the differences/advantages over Ragtime?
Using sequential numbers is problematic -- read the Migratus docs for an explanation.
I see - we use timestamps with ragtime
(hard learned lesson from early days of Rails)
Even so, it's an ordered sequence (problematic) rather than recording all the applied ones vs not-yet-applied, right?
(but, yeah, timestamps are better)