diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fdb1b7..e398779 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 [#248](https://github.com/seancorfield/next-jdbc/issues/248) by allowing `:port` to be `:none`. + * 1.3.865 -- 2023-03-31 * Fix [#246](https://github.com/seancorfield/next-jdbc/issues/246) by adopting the `strop` function from HoneySQL. * Address [#245](https://github.com/seancorfield/next-jdbc/issues/245) by not `locking` the `Connection` when `*nested-tx*` is bound to `:ignore` -- improving `clojure.java.jdbc` compatibility. diff --git a/doc/all-the-options.md b/doc/all-the-options.md index 8eef0dc..5c09480 100644 --- a/doc/all-the-options.md +++ b/doc/all-the-options.md @@ -13,7 +13,7 @@ Although `get-datasource` does not accept options, the "db spec" hash map passed * `:dbname-separator` -- an optional string that can be used to override the `/` or `:` that is normally placed in front of the database name in the JDBC URL, * `:host` -- an optional string that identifies the IP address or hostname of the server on which the database is running; the default is `"127.0.0.1"`; if `:none` is specified, `next.jdbc` will assume this is for a local database and will omit the host/port segment of the JDBC URL, * `:host-prefix` -- an optional string that can be used to override the `//` that is normally placed in front of the IP address or hostname in the JDBC URL, -* `:port` -- an optional integer that identifies the port on which the database is running; for common database types, `next.jdbc` knows the default so this should only be needed for non-standard setups or "exotic" database types, +* `:port` -- an optional integer that identifies the port on which the database is running; for common database types, `next.jdbc` knows the default so this should only be needed for non-standard setups or "exotic" database types; if `:none` is specified, `next.jdbc` will omit the port segment of the JDBC URL, * `:property-separator` -- an optional string that can be used to override the separators used in `next.jdbc.connection/jdbc-url` for the properties (after the initial JDBC URL portion); by default `?` and `&` are used to build JDBC URLs with properties; for SQL Server drivers (both MS and jTDS) `:property-separator ";"` is used, so this option should only be necessary when you are specifying "unusual" databases that `next.jdbc` does not already know about, * `:classname` -- an optional string that identifies the name of the JDBC driver class to be used for the connection; for common database types, `next.jdbc` knows the default so this should only be needed for "exotic" database types, * `:user` -- an optional string that identifies the database username to be used when authenticating, diff --git a/src/next/jdbc.clj b/src/next/jdbc.clj index 7288021..9f002b5 100644 --- a/src/next/jdbc.clj +++ b/src/next/jdbc.clj @@ -92,7 +92,8 @@ can be `:none` which means the host/port segment of the JDBC URL should be omitted entirely (for 'local' databases) * `:port` -- the port for the database connection (the default is database- - specific -- see below) + specific -- see below); can be `:none` which means the port segment of + the JDBC URL should be omitted entirely * `:classname` -- if you need to override the default for the `:dbtype` (or you want to use a database that next.jdbc does not know about!) diff --git a/src/next/jdbc/connection.clj b/src/next/jdbc/connection.clj index db21c15..05891d4 100644 --- a/src/next/jdbc/connection.clj +++ b/src/next/jdbc/connection.clj @@ -176,7 +176,7 @@ (str "jdbc:" subprotocol ":" (or host-prefix (-> dbtype dbtypes :host-prefix (or "//"))) host - (when port (str ":" port)) + (when (and port (not= :none port)) (str ":" port)) db-sep dbname))] ;; verify the datasource is loadable (if-let [class-name (or classname (-> dbtype dbtypes :classname))] diff --git a/src/next/jdbc/specs.clj b/src/next/jdbc/specs.clj index beea4c7..5ed6a19 100644 --- a/src/next/jdbc/specs.clj +++ b/src/next/jdbc/specs.clj @@ -35,7 +35,8 @@ (s/def ::host (s/or :name string? :none #{:none})) (s/def ::host-prefix string?) -(s/def ::port pos-int?) +(s/def ::port (s/or :port pos-int? + :none #{:none})) (s/def ::db-spec-map (s/keys :req-un [::dbtype ::dbname] :opt-un [::classname ::user ::password diff --git a/test/next/jdbc/connection_test.clj b/test/next/jdbc/connection_test.clj index 3365ac9..a867616 100644 --- a/test/next/jdbc/connection_test.clj +++ b/test/next/jdbc/connection_test.clj @@ -74,6 +74,10 @@ (is (= ["jdbc:acme:(*)12.34.56.70:1234/my-db" {} nil] (#'c/spec->url+etc {:dbtype "acme" :classname "java.lang.String" :dbname "my-db" :host "12.34.56.70" :port 1234 + :host-prefix "(*)"}))) + (is (= ["jdbc:acme:(*)12.34.56.70/my-db" {} nil] + (#'c/spec->url+etc {:dbtype "acme" :classname "java.lang.String" + :dbname "my-db" :host "12.34.56.70" :port :none :host-prefix "(*)"})))) (deftest jdbc-url-tests @@ -197,4 +201,4 @@ (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 + (c/uri->db-spec "jdbc:mysql://myserver:1234/mydb?user=foo&password=bar"))))