[#372] add support for jdbc + postgres

This commit is contained in:
Michiel Borkent 2020-04-24 15:08:26 +02:00 committed by GitHub
parent 2fef8a793e
commit 6cd384c215
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 46 additions and 4 deletions

View file

@ -11,7 +11,9 @@
org.clojure/data.xml {:mvn/version "0.2.0-alpha6"} org.clojure/data.xml {:mvn/version "0.2.0-alpha6"}
fipp {:mvn/version "0.6.22"} fipp {:mvn/version "0.6.22"}
clj-commons/clj-yaml {:mvn/version "0.7.1"} clj-commons/clj-yaml {:mvn/version "0.7.1"}
com.cognitect/transit-clj {:mvn/version "1.0.324"}} com.cognitect/transit-clj {:mvn/version "1.0.324"}
seancorfield/next.jdbc {:mvn/version "1.0.424"}
org.postgresql/postgresql {:mvn/version "42.2.5"}}
:aliases {:main :aliases {:main
{:main-opts ["-m" "babashka.main"]} {:main-opts ["-m" "babashka.main"]}
:profile :profile

View file

@ -62,6 +62,9 @@ $ BABASHKA_XMX="-J-Xmx4g" script/compile
Keep notes here about how adding libraries and classes to Babashka affects the binary size. Keep notes here about how adding libraries and classes to Babashka affects the binary size.
We're registering the size of the macOS binary (as built on CircleCI). We're registering the size of the macOS binary (as built on CircleCI).
2020/04/23 Added `next.jdbc` and postgres JDBC driver:
(- 51019836 48099780) = 2920kb added
2020/04/23 Added BigDecimal 2020/04/23 Added BigDecimal
(- 48103868 47857732) = 246kb added (- 48103868 47857732) = 246kb added

View file

@ -23,7 +23,9 @@
[cheshire "5.10.0"] [cheshire "5.10.0"]
[fipp "0.6.22"] [fipp "0.6.22"]
[clj-commons/clj-yaml "0.7.1"] [clj-commons/clj-yaml "0.7.1"]
[com.cognitect/transit-clj "1.0.324"]] [com.cognitect/transit-clj "1.0.324"]
[seancorfield/next.jdbc "1.0.424"]
[org.postgresql/postgresql "42.2.5"]]
:profiles {:test {:dependencies [[clj-commons/conch "0.9.2"] :profiles {:test {:dependencies [[clj-commons/conch "0.9.2"]
[com.clojure-goes-fast/clj-async-profiler "0.4.0"]]} [com.clojure-goes-fast/clj-async-profiler "0.4.0"]]}
:uberjar {:global-vars {*assert* false} :uberjar {:global-vars {*assert* false}

View file

@ -46,6 +46,7 @@ args=( -jar $BABASHKA_JAR \
--no-fallback \ --no-fallback \
--no-server \ --no-server \
--report-unsupported-elements-at-runtime \ --report-unsupported-elements-at-runtime \
"--initialize-at-run-time=org.postgresql.sspi.SSPIClient" \
"$BABASHKA_XMX" ) "$BABASHKA_XMX" )
if [ "$BABASHKA_STATIC" = "true" ]; then if [ "$BABASHKA_STATIC" = "true" ]; then

View file

@ -0,0 +1,31 @@
(ns babashka.impl.jdbc
{:no-doc true}
(:require [next.jdbc :as njdbc]
[sci.impl.namespaces :refer [copy-var]]
[sci.impl.vars :as vars]))
(def next-ns (vars/->SciNamespace 'next.jdbc nil))
(defn with-transaction
"Given a transactable object, gets a connection and binds it to `sym`,
then executes the `body` in that context, committing any changes if the body
completes successfully, otherwise rolling back any changes made.
The options map supports:
* `:isolation` -- `:none`, `:read-committed`, `:read-uncommitted`,
`:repeatable-read`, `:serializable`,
* `:read-only` -- `true` / `false`,
* `:rollback-only` -- `true` / `false`."
[_ _ [sym transactable opts] & body]
(let [con (vary-meta sym assoc :tag 'java.sql.Connection)]
`(next.jdbc/transact ~transactable (^{:once true} fn* [~con] ~@body) ~(or opts {}))))
(def njdbc-namespace
{'get-datasource (copy-var njdbc/get-datasource next-ns)
'execute! (copy-var njdbc/execute! next-ns)
'execute-one! (copy-var njdbc/execute-one! next-ns)
'get-connection (copy-var njdbc/get-connection next-ns)
'plan (copy-var njdbc/plan next-ns)
'prepare (copy-var njdbc/prepare next-ns)
'transact (copy-var njdbc/transact next-ns)
'with-transaction (with-meta with-transaction
{:sci/macro true})})

View file

@ -15,6 +15,7 @@
[babashka.impl.common :as common] [babashka.impl.common :as common]
[babashka.impl.csv :as csv] [babashka.impl.csv :as csv]
[babashka.impl.curl :refer [curl-namespace]] [babashka.impl.curl :refer [curl-namespace]]
[babashka.impl.jdbc :as jdbc]
[babashka.impl.nrepl-server :as nrepl-server] [babashka.impl.nrepl-server :as nrepl-server]
[babashka.impl.pipe-signal-handler :refer [handle-pipe! pipe-signal-received?]] [babashka.impl.pipe-signal-handler :refer [handle-pipe! pipe-signal-received?]]
[babashka.impl.repl :as repl] [babashka.impl.repl :as repl]
@ -257,7 +258,8 @@ Everything after that is bound to *command-line-args*."))
yaml clj-yaml.core yaml clj-yaml.core
curl babashka.curl curl babashka.curl
transit cognitect.transit transit cognitect.transit
bencode bencode.core}) bencode bencode.core
jdbc next.jdbc})
(def cp-state (atom nil)) (def cp-state (atom nil))
@ -292,7 +294,8 @@ Everything after that is bound to *command-line-args*."))
'clojure.pprint pprint-namespace 'clojure.pprint pprint-namespace
'babashka.curl curl-namespace 'babashka.curl curl-namespace
'cognitect.transit transit-namespace 'cognitect.transit transit-namespace
'bencode.core bencode-namespace}) 'bencode.core bencode-namespace
'next.jdbc jdbc/njdbc-namespace})
(def bindings (def bindings
{'java.lang.System/exit exit ;; override exit, so we have more control {'java.lang.System/exit exit ;; override exit, so we have more control