This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-04
Channels
- # announcements (7)
- # babashka (26)
- # babashka-sci-dev (19)
- # beginners (66)
- # calva (4)
- # clj-kondo (55)
- # cljs-dev (173)
- # cljsrn (17)
- # clojure (86)
- # clojure-art (3)
- # clojure-australia (1)
- # clojure-europe (24)
- # clojure-india (1)
- # clojure-nl (3)
- # clojure-uk (6)
- # clojured (5)
- # clojurescript (39)
- # cursive (8)
- # data-oriented-programming (20)
- # datomic (9)
- # emacs (10)
- # events (1)
- # figwheel-main (16)
- # fulcro (33)
- # gratitude (1)
- # helix (2)
- # hugsql (2)
- # jobs (2)
- # kaocha (4)
- # leiningen (5)
- # lsp (110)
- # malli (1)
- # missionary (17)
- # observability (3)
- # re-frame (10)
- # reagent (1)
- # reitit (7)
- # rewrite-clj (3)
- # shadow-cljs (63)
- # sql (19)
- # tools-build (74)
- # tools-deps (32)
- # transit (1)
- # xtdb (5)
Moving this conversation to the #sql channel... Looking at the hikari-cp code, make-datasource
should return a DataSource
object that next.jdbc
should be happy with so I guess I'd need to see how you're using it to provide more details...
It seems to work for me @errelinaaron:
(! 521)-> clojure -Sdeps '{:deps {hikari-cp {:mvn/version "RELEASE"}}}' -M:test:rebel:dev/repl
DEPRECATED: Libs must be qualified, change hikari-cp => hikari-cp/hikari-cp
Downloading: com/bhauman/rebel-readline/maven-metadata.xml from clojars
Selected port 57739 for the Socket REPL...
Starting Rebel Readline as the REPL...
[Rebel readline] Type :repl/help for online help info
dev=> (require '[hikari-cp.core :refer [make-datasource]] '[next.jdbc :as jdbc])
nil
dev=> (def ds (make-datasource {:jdbc-url "jdbc:" :username "root" :password (System/getenv "MYSQL_ROOT_PASSWORD")}))
#'dev/ds
dev=> (jdbc/execute! ds ["select * from status"])
[#:status{:id 1, :name "approved"} #:status{:id 2, :name "new"} #:status{:id 3, :name "rejected"}]
dev=>
(I ran that in the next.jdbc
project so :test
brings in all the drivers)After seeing your example, I realized I used wrong syntax:
(def datasource-options
{:auto-commit true
:read-only false
:connection-timeout 30000
:validation-timeout 5000
:idle-timeout 600000
:max-lifetime 1800000
:minimum-idle 10
:maximum-pool-size 20
:pool-name "db-pool"
:adapter "postgresql"
:username "user"
:password "passwd"
:database-name "mydbname"
:server-name "localhost"
:port-number 5432
:register-mbeans false})
(defonce datasource
(delay (hcp/make-datasource datasource-options)))
(def database-connection {:datasource @datasource})
;; add-rush-orders is a fn generated by HugSQL
;; it accepts a db, ds, or connection
defn first-connect []
(add-rush-orders (jdbc/get-connection database-connection) {:orders sh/first-five-rows}))
It seems, after making the datasource, I should start passing it to next.jdbc
's fns, other than making that connection var? I'll follow your example. Really helpful. Thank you againNo, just use the DataSource
object directly.
next.jdbc
can work with Connection
and DataSource
(Java) objects directly. If you pass it something else, it will try to turn it into a datasource and then get the connection from that.
I would strongly recommend not using hikari-cp
-- it's pointless when HikariCP is directly supported in next.jdbc
.
That way you can just follow the next.jdbc
documentation and examples (instead of getting confused trying to combine two libraries that don't know about each other).
Hi, are migrating to next.jdbc and the documentation has been fantastic. 🙏 Thanks @seancorfield.
I’ve been playing around with plan
and wondering if there’s a way to make it support kebab case (like execute!
):
(->> (plan db {:select [:*]
:from [:account]})
(into [] (comp
(map :account/kebab_data)
(map :foo)
(take 1))))
works, but:
(->> (plan db {:select [:*]
:from [:account]})
(into [] (comp
(map :account/kebab-data)
(map :foo)
(take 1))))
Does not work. Any ideas?Sorry for being off-topic, but wondering in the future would you consider adding examples of using next.jdbc
in hikari-cp
's doc? I think that would be greatly helpful as next.jdbc is quite popular and nice to use.
@errelinaaron hikari-cp is "just" a connection pool, so once it's setup it shouldn't be any different from a regular JDBC connection - next.jdbc
doesn't really care as long as it's valid
Yes, that's correct. I'm new to Clojure and know little about Java, so sometimes even a small difference between syntaxes of two similar libs could confuse me. Since I see there are examples for different types of databases, I think it might also be helpful if the doc could include examples of next.jdbc
. Anyway, thanks for making that point clear, helpful too:grin:👍
(defonce datasource
(delay
(connection/->pool
HikariDataSource
{:dbtype "postgresql"
:dbname "plan-b"
:minimumIdle 5
:maximumPoolSize 5})))
You don’t need to use the clojure https://github.com/tomekw/hikari-cp wrapper with next.jdbc. You can just use the HikariCP java library.
Hi @U0JEEGD4N, thank you for the reply. You're right. That's what I found later when reading next.jdbc
's doc. I was just curious if I guessed it right. Based on @seancorfield’s reply, I found I should directly pass @datasource
to next.jdbc
Fns. But, again, as you already pointed out, the wrapper becomes optional in my case. I'll stay out of this thread to avoid distracting your original post too much. Thank you all:clap:
I don't use hikari-cp
and know nothing about it -- the code I pasted was my first ever interaction with it -- and since next.jdbc
supports HikariCP directly (and c3p0 too) there's no point in me confusing next.jdbc
's users by pointing to a library they do not need to use.
@errelinaaron And please don't hijack other people's threads.
@U0JEEGD4N plan
operates on a lower level than execute!
and is specifically intended to avoid using builders -- and stuff like snake_case/kebab-case is only handled in builders.
Thought that might be the case. Thanks for the prompt reply!
So the answer is "no". The reducing functions for plan
only have access to the simple names in the ResultSet
. In particular, :account/snake_case
is a bit pointless since there's no qualifiers inside plan
-- that's also about naming inside builders.