From 70a5db8b297163769f31f21633e5e9ae2abde597 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Sun, 12 Mar 2023 16:59:24 -0700 Subject: [PATCH] fix #243 by producing keywords (from properties) --- CHANGELOG.md | 3 +++ src/next/jdbc/connection.clj | 3 ++- test/next/jdbc/connection_test.clj | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79dbc2b..6973ce0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ Only accretive/fixative changes will be made from now on. +* 1.3.next in progress + * Fix [#243](https://github.com/seancorfield/next-jdbc/issues/243) by ensure URI properties become keywords. + * 1.3.858 -- 2023-03-05 * Address [#241](https://github.com/seancorfield/next-jdbc/issues/241) by correcting link to PostgreSQL docs. * Address [clj-kondo#1685](https://github.com/clj-kondo/clj-kondo/issues/1685) by using `.clj_kondo` extension for hook files. diff --git a/src/next/jdbc/connection.clj b/src/next/jdbc/connection.clj index 8efd593..674b738 100644 --- a/src/next/jdbc/connection.clj +++ b/src/next/jdbc/connection.clj @@ -365,7 +365,8 @@ [user password] (when (seq userInfo) (str/split userInfo #":")) properties (when (seq query) (into {} - (map #(str/split % #"=")) + (map #(let [[k v] (str/split % #"=")] + [(keyword k) v])) (str/split query #"\&")))] (cond-> (assoc properties :dbtype scheme diff --git a/test/next/jdbc/connection_test.clj b/test/next/jdbc/connection_test.clj index 9f6cf6f..3365ac9 100644 --- a/test/next/jdbc/connection_test.clj +++ b/test/next/jdbc/connection_test.clj @@ -188,3 +188,13 @@ (testing "connection via map (Object)" (with-open [con (p/get-connection db {})] (is (instance? java.sql.Connection con)))))) + +(deftest issue-243-uri->db-spec + (is (= {:dbtype "mysql" :dbname "mydb" + :host "myserver" :port 1234 + :user "foo" :password "bar"} + (c/uri->db-spec "mysql://foo:bar@myserver:1234/mydb"))) + (is (= {:dbtype "mysql" :dbname "mydb" + :host "myserver" :port 1234 + :user "foo" :password "bar"} + (c/uri->db-spec "jdbc:mysql://myserver:1234/mydb?user=foo&password=bar")))) \ No newline at end of file