fix #248 by supporting :port :none

This commit is contained in:
Sean Corfield 2023-04-13 23:53:45 -07:00
parent 6e09de7604
commit 3d512a8f04
6 changed files with 14 additions and 5 deletions

View file

@ -2,6 +2,9 @@
Only accretive/fixative changes will be made from now on. 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 * 1.3.865 -- 2023-03-31
* Fix [#246](https://github.com/seancorfield/next-jdbc/issues/246) by adopting the `strop` function from HoneySQL. * 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. * 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.

View file

@ -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, * `: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` -- 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, * `: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, * `: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, * `: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, * `:user` -- an optional string that identifies the database username to be used when authenticating,

View file

@ -92,7 +92,8 @@
can be `:none` which means the host/port segment of the JDBC URL should can be `:none` which means the host/port segment of the JDBC URL should
be omitted entirely (for 'local' databases) be omitted entirely (for 'local' databases)
* `:port` -- the port for the database connection (the default is database- * `: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` * `: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!) (or you want to use a database that next.jdbc does not know about!)

View file

@ -176,7 +176,7 @@
(str "jdbc:" subprotocol ":" (str "jdbc:" subprotocol ":"
(or host-prefix (-> dbtype dbtypes :host-prefix (or "//"))) (or host-prefix (-> dbtype dbtypes :host-prefix (or "//")))
host host
(when port (str ":" port)) (when (and port (not= :none port)) (str ":" port))
db-sep dbname))] db-sep dbname))]
;; verify the datasource is loadable ;; verify the datasource is loadable
(if-let [class-name (or classname (-> dbtype dbtypes :classname))] (if-let [class-name (or classname (-> dbtype dbtypes :classname))]

View file

@ -35,7 +35,8 @@
(s/def ::host (s/or :name string? (s/def ::host (s/or :name string?
:none #{:none})) :none #{:none}))
(s/def ::host-prefix string?) (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] (s/def ::db-spec-map (s/keys :req-un [::dbtype ::dbname]
:opt-un [::classname :opt-un [::classname
::user ::password ::user ::password

View file

@ -74,6 +74,10 @@
(is (= ["jdbc:acme:(*)12.34.56.70:1234/my-db" {} nil] (is (= ["jdbc:acme:(*)12.34.56.70:1234/my-db" {} nil]
(#'c/spec->url+etc {:dbtype "acme" :classname "java.lang.String" (#'c/spec->url+etc {:dbtype "acme" :classname "java.lang.String"
:dbname "my-db" :host "12.34.56.70" :port 1234 :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 "(*)"})))) :host-prefix "(*)"}))))
(deftest jdbc-url-tests (deftest jdbc-url-tests