[#372] add support for jdbc + postgres
This commit is contained in:
parent
2fef8a793e
commit
6cd384c215
6 changed files with 46 additions and 4 deletions
4
deps.edn
4
deps.edn
|
|
@ -11,7 +11,9 @@
|
|||
org.clojure/data.xml {:mvn/version "0.2.0-alpha6"}
|
||||
fipp {:mvn/version "0.6.22"}
|
||||
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
|
||||
{:main-opts ["-m" "babashka.main"]}
|
||||
:profile
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
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
|
||||
(- 48103868 47857732) = 246kb added
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,9 @@
|
|||
[cheshire "5.10.0"]
|
||||
[fipp "0.6.22"]
|
||||
[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"]
|
||||
[com.clojure-goes-fast/clj-async-profiler "0.4.0"]]}
|
||||
:uberjar {:global-vars {*assert* false}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ args=( -jar $BABASHKA_JAR \
|
|||
--no-fallback \
|
||||
--no-server \
|
||||
--report-unsupported-elements-at-runtime \
|
||||
"--initialize-at-run-time=org.postgresql.sspi.SSPIClient" \
|
||||
"$BABASHKA_XMX" )
|
||||
|
||||
if [ "$BABASHKA_STATIC" = "true" ]; then
|
||||
|
|
|
|||
31
src/babashka/impl/jdbc.clj
Normal file
31
src/babashka/impl/jdbc.clj
Normal 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})})
|
||||
|
|
@ -15,6 +15,7 @@
|
|||
[babashka.impl.common :as common]
|
||||
[babashka.impl.csv :as csv]
|
||||
[babashka.impl.curl :refer [curl-namespace]]
|
||||
[babashka.impl.jdbc :as jdbc]
|
||||
[babashka.impl.nrepl-server :as nrepl-server]
|
||||
[babashka.impl.pipe-signal-handler :refer [handle-pipe! pipe-signal-received?]]
|
||||
[babashka.impl.repl :as repl]
|
||||
|
|
@ -257,7 +258,8 @@ Everything after that is bound to *command-line-args*."))
|
|||
yaml clj-yaml.core
|
||||
curl babashka.curl
|
||||
transit cognitect.transit
|
||||
bencode bencode.core})
|
||||
bencode bencode.core
|
||||
jdbc next.jdbc})
|
||||
|
||||
(def cp-state (atom nil))
|
||||
|
||||
|
|
@ -292,7 +294,8 @@ Everything after that is bound to *command-line-args*."))
|
|||
'clojure.pprint pprint-namespace
|
||||
'babashka.curl curl-namespace
|
||||
'cognitect.transit transit-namespace
|
||||
'bencode.core bencode-namespace})
|
||||
'bencode.core bencode-namespace
|
||||
'next.jdbc jdbc/njdbc-namespace})
|
||||
|
||||
(def bindings
|
||||
{'java.lang.System/exit exit ;; override exit, so we have more control
|
||||
|
|
|
|||
Loading…
Reference in a new issue