Skip to content

Commit

Permalink
Update database.sql dependency
Browse files Browse the repository at this point in the history
Remove references to Boundary record.
  • Loading branch information
weavejester committed Nov 10, 2024
1 parent 243d63c commit d851b2d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.11.4"]
[org.duct-framework/database.sql "0.3.0"]
[org.duct-framework/database.sql "0.4.0"]
[org.duct-framework/logger "0.4.0"]
[com.github.seancorfield/next.jdbc "1.3.955"]
[com.zaxxer/HikariCP "6.1.0"]
Expand Down
8 changes: 4 additions & 4 deletions src/duct/database/sql/hikaricp.clj
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@

(defmethod ig/init-key :duct.database.sql/hikaricp
[_ {:keys [logger] :as options}]
(sql/->Boundary (-> (dissoc options :logger)
(as-> cfg (conn/->pool HikariDataSource cfg))
(cond-> logger (wrap-logger logger)))))
(-> (dissoc options :logger)
(as-> cfg (conn/->pool HikariDataSource cfg))
(cond-> logger (wrap-logger logger))))

(defmethod ig/halt-key! :duct.database.sql/hikaricp [_ {:keys [datasource]}]
(defmethod ig/halt-key! :duct.database.sql/hikaricp [_ datasource]
(.close ^HikariDataSource (unwrap-logger datasource)))
30 changes: 15 additions & 15 deletions test/duct/database/sql/hikaricp_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,16 @@

(deftest connection-test
(testing "jdbc-url"
(let [config {::sql/hikaricp {:jdbcUrl "jdbc:sqlite:"}}
system (ig/init config)
hikaricp (::sql/hikaricp system)]
(is (instance? duct.database.sql.Boundary hikaricp))
(let [datasource (:datasource hikaricp)]
(is (instance? javax.sql.DataSource datasource))
(is (not (closed? datasource)))
(ig/halt! system)
(is (closed? datasource))))))
(let [config {::sql/hikaricp {:jdbcUrl "jdbc:sqlite:"}}
system (ig/init config)
ds (::sql/hikaricp system)]
(is (instance? javax.sql.DataSource ds))
(is (not (closed? ds)))
(ig/halt! system)
(is (closed? ds)))))

(deftest execute-test
(let [spec (ig/init-key ::sql/hikaricp {:jdbcUrl "jdbc:sqlite:"})]
(let [spec {:datasource (ig/init-key ::sql/hikaricp {:jdbcUrl "jdbc:sqlite:"})}]
(jdbc/execute! spec ["CREATE TABLE foo (id INT)"])
(jdbc/db-do-commands spec ["INSERT INTO foo VALUES (1)" "INSERT INTO foo VALUES (2)"])
(is (= (jdbc/query spec ["SELECT * FROM foo"]) [{:id 1} {:id 2}]))))
Expand All @@ -47,10 +45,12 @@
(deftest logging-test
(let [logs (atom [])
logger (->AtomLogger logs)
spec (ig/init-key ::sql/hikaricp {:jdbcUrl "jdbc:sqlite:" :logger logger})]
ds (ig/init-key ::sql/hikaricp
{:jdbcUrl "jdbc:sqlite:" :logger logger})
spec {:datasource ds}]
(jdbc/execute! spec ["CREATE TABLE foo (id INT, body TEXT)"])
(jdbc/db-do-commands spec ["INSERT INTO foo VALUES (1, 'a')"
"INSERT INTO foo VALUES (2, 'b')"])
"INSERT INTO foo VALUES (2, 'b')"])
(is (= (jdbc/query spec ["SELECT * FROM foo"])
[{:id 1, :body "a"} {:id 2, :body "b"}]))
(is (= (jdbc/query spec ["SELECT * FROM foo WHERE id = ?" 1])
Expand All @@ -66,6 +66,6 @@
[:info ::sql/query {:sql [["SELECT * FROM foo WHERE id = ?" 1]]}]
[:info ::sql/query
{:sql [["SELECT * FROM foo WHERE id = ? AND body = ?" 1 "a"]]}]]))
(is (not (.isClosed (unwrap-logger (:datasource spec)))))
(ig/halt-key! ::sql/hikaricp spec)
(is (closed? (:datasource spec)))))
(is (not (closed? ds)))
(ig/halt-key! ::sql/hikaricp ds)
(is (closed? ds))))

0 comments on commit d851b2d

Please sign in to comment.