Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions clj-test/jdbc/core_test.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
(ns jdbc.core-test
(:require [jdbc.core :as jdbc]))
(:require [jdbc.core :as jdbc]
;; the placeholder rewriter lives in the pg driver; requiring it here
;; lets the sqlite-only run cover the lexer table. Loading db.pg does
;; not need libpq present, only calling into it does.
[db.pg]))

(def failures (atom 0))

Expand Down Expand Up @@ -87,7 +91,7 @@
;; really a placeholder must neither be rewritten nor consume a number. These
;; run without a database, so the sqlite-only build covers them.
(println "postgres placeholder rewriting")
(let [rewrite (deref (resolve (symbol "jdbc.core" "pg-placeholders")))]
(let [rewrite (deref (resolve (symbol "db.pg" "pg-placeholders")))]
(doseq [[label in out]
[["no placeholders" "select 1" "select 1"]
["bare placeholder" "?" "$1"]
Expand Down
33 changes: 33 additions & 0 deletions clj/db/jdbc.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
(ns db.jdbc
"Entry point: loads the java.sql shim, then the real clojure.jdbc on top of it,
then points clojure.jdbc's connection construction at the native drivers.

Require this once before using jdbc.core. Two things depend on the order. The
shim has to be loaded before clojure.jdbc's namespaces compile, because they
resolve java.sql constants at compile time. And the IConnection extension below
has to be loaded after clojure.jdbc's own, since the later extension is the one
that wins, which is how a dbspec reaches db.sqlite / db.pg instead of
DriverManager.

(require '[db.jdbc])
(require '[jdbc.core :as jdbc])
(with-open [conn (jdbc/connection \"sqlite::memory:\")]
(jdbc/fetch conn \"select 1 as one\"))

Not wired in yet. While this repo still ships its own clj/jdbc/core.clj, that
copy shadows the dependency on the classpath and the require below resolves to it
rather than to clojure.jdbc, so this namespace only does what it says once that
file is removed."
(:require [db.jdbc-shim :as shim]
[jdbc.proto :as proto]
[jdbc.core]))

;; DriverManager and DataSource have nothing to load here, so a dbspec map or uri
;; string builds a shim connection over the native driver instead. Registered after
;; jdbc.impl's own extensions so these take precedence.
(extend-protocol proto/IConnection
java.lang.String
(connection [s] (shim/connection s))

clojure.lang.IPersistentMap
(connection [m] (shim/connection m)))
Loading
Loading