Prep 1.1.582 -- fixes #138

This commit is contained in:
Sean Corfield 2020-08-05 18:18:30 -07:00
parent 4a96165b0b
commit e9c75a7afd
5 changed files with 45 additions and 7 deletions

View file

@ -4,6 +4,9 @@ Only accretive/fixative changes will be made from now on.
## Stable Builds ## Stable Builds
* 2020-08-05 -- 1.1.582
* Fix #138 by exposing `next.jdbc.connection/jdbc-url` to build `:jdbcUrl` values that can be passed to `->pool` or `component`.
* 2020-08-03 -- 1.1.581 * 2020-08-03 -- 1.1.581
* Fix #137 by adding support for specifying username and password per-connection (if your datasource supports this). * Fix #137 by adding support for specifying username and password per-connection (if your datasource supports this).
* Document SQLite handling of `bool` and `bit` columns in a new **Tips & Tricks** section, inspired by #134. * Document SQLite handling of `bool` and `bit` columns in a new **Tips & Tricks** section, inspired by #134.

View file

@ -6,7 +6,7 @@ The next generation of `clojure.java.jdbc`: a new low-level Clojure wrapper for
The latest versions on Clojars and on cljdoc: The latest versions on Clojars and on cljdoc:
[![Clojars Project](https://clojars.org/seancorfield/next.jdbc/latest-version.svg)](https://clojars.org/seancorfield/next.jdbc) [![cljdoc badge](https://cljdoc.org/badge/seancorfield/next.jdbc?1.1.581)](https://cljdoc.org/d/seancorfield/next.jdbc/CURRENT) [![Clojars Project](https://clojars.org/seancorfield/next.jdbc/latest-version.svg)](https://clojars.org/seancorfield/next.jdbc) [![cljdoc badge](https://cljdoc.org/badge/seancorfield/next.jdbc?1.1.582)](https://cljdoc.org/d/seancorfield/next.jdbc/CURRENT)
The documentation on [cljdoc.org](https://cljdoc.org/d/seancorfield/next.jdbc/CURRENT) is for the current version of `next.jdbc`: The documentation on [cljdoc.org](https://cljdoc.org/d/seancorfield/next.jdbc/CURRENT) is for the current version of `next.jdbc`:
@ -14,7 +14,7 @@ The documentation on [cljdoc.org](https://cljdoc.org/d/seancorfield/next.jdbc/CU
* [Migrating from `clojure.java.jdbc`](https://cljdoc.org/d/seancorfield/next.jdbc/CURRENT/doc/migration-from-clojure-java-jdbc) * [Migrating from `clojure.java.jdbc`](https://cljdoc.org/d/seancorfield/next.jdbc/CURRENT/doc/migration-from-clojure-java-jdbc)
* Feedback via [issues](https://github.com/seancorfield/next-jdbc/issues) or in the [`#sql` channel on the Clojurians Slack](https://clojurians.slack.com/messages/C1Q164V29/details/) or the [`#sql` stream on the Clojurians Zulip](https://clojurians.zulipchat.com/#narrow/stream/152063-sql). * Feedback via [issues](https://github.com/seancorfield/next-jdbc/issues) or in the [`#sql` channel on the Clojurians Slack](https://clojurians.slack.com/messages/C1Q164V29/details/) or the [`#sql` stream on the Clojurians Zulip](https://clojurians.zulipchat.com/#narrow/stream/152063-sql).
The documentation on GitHub is for **develop** since the 1.1.581 release -- [see the CHANGELOG](https://github.com/seancorfield/next-jdbc/blob/develop/CHANGELOG.md) and then read the [corresponding updated documentation](https://github.com/seancorfield/next-jdbc/tree/develop/doc) on GitHub if you want. The documentation on GitHub is for **develop** since the 1.1.582 release -- [see the CHANGELOG](https://github.com/seancorfield/next-jdbc/blob/develop/CHANGELOG.md) and then read the [corresponding updated documentation](https://github.com/seancorfield/next-jdbc/tree/develop/doc) on GitHub if you want.
This project follows the version scheme MAJOR.MINOR.COMMITS where MAJOR and MINOR provide some relative indication of the size of the change, but do not follow semantic versioning. In general, all changes endeavor to be non-breaking (by moving to new names rather than by breaking existing names). COMMITS is an ever-increasing counter of commits since the beginning of this repository. This project follows the version scheme MAJOR.MINOR.COMMITS where MAJOR and MINOR provide some relative indication of the size of the change, but do not follow semantic versioning. In general, all changes endeavor to be non-breaking (by moving to new names rather than by breaking existing names). COMMITS is an ever-increasing counter of commits since the beginning of this repository.

View file

@ -9,12 +9,12 @@ It is designed to work with Clojure 1.10 or later, supports `datafy`/`nav`, and
You can add `next.jdbc` to your project with either: You can add `next.jdbc` to your project with either:
```clojure ```clojure
seancorfield/next.jdbc {:mvn/version "1.1.581"} seancorfield/next.jdbc {:mvn/version "1.1.582"}
``` ```
for `deps.edn` or: for `deps.edn` or:
```clojure ```clojure
[seancorfield/next.jdbc "1.1.581"] [seancorfield/next.jdbc "1.1.582"]
``` ```
for `project.clj` or `build.boot`. for `project.clj` or `build.boot`.
@ -29,7 +29,7 @@ For the examples in this documentation, we will use a local H2 database on disk,
```clojure ```clojure
;; deps.edn ;; deps.edn
{:deps {org.clojure/clojure {:mvn/version "1.10.1"} {:deps {org.clojure/clojure {:mvn/version "1.10.1"}
seancorfield/next.jdbc {:mvn/version "1.1.581"} seancorfield/next.jdbc {:mvn/version "1.1.582"}
com.h2database/h2 {:mvn/version "1.4.199"}}} com.h2database/h2 {:mvn/version "1.4.199"}}}
``` ```

View file

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>seancorfield</groupId> <groupId>seancorfield</groupId>
<artifactId>next.jdbc</artifactId> <artifactId>next.jdbc</artifactId>
<version>1.1.581</version> <version>1.1.582</version>
<name>next.jdbc</name> <name>next.jdbc</name>
<description>The next generation of clojure.java.jdbc: a new low-level Clojure wrapper for JDBC-based access to databases.</description> <description>The next generation of clojure.java.jdbc: a new low-level Clojure wrapper for JDBC-based access to databases.</description>
<url>https://github.com/seancorfield/next-jdbc</url> <url>https://github.com/seancorfield/next-jdbc</url>
@ -22,7 +22,7 @@
<url>https://github.com/seancorfield/next-jdbc</url> <url>https://github.com/seancorfield/next-jdbc</url>
<connection>scm:git:git://github.com/seancorfield/next-jdbc.git</connection> <connection>scm:git:git://github.com/seancorfield/next-jdbc.git</connection>
<developerConnection>scm:git:ssh://git@github.com/seancorfield/next-jdbc.git</developerConnection> <developerConnection>scm:git:ssh://git@github.com/seancorfield/next-jdbc.git</developerConnection>
<tag>v1.1.581</tag> <tag>v1.1.582</tag>
</scm> </scm>
<dependencies> <dependencies>
<dependency> <dependency>

View file

@ -7,6 +7,7 @@
the `->pool` and `component` functions for creating pooled datasource the `->pool` and `component` functions for creating pooled datasource
objects." objects."
(:require [clojure.java.data :as j] (:require [clojure.java.data :as j]
[clojure.string :as str]
[next.jdbc.protocols :as p]) [next.jdbc.protocols :as p])
(:import (java.sql Connection DriverManager) (:import (java.sql Connection DriverManager)
(javax.sql DataSource) (javax.sql DataSource)
@ -207,6 +208,40 @@
db-spec))) db-spec)))
[url etc])))) [url etc]))))
(defn jdbc-url
"Given a database spec (as a hash map), return a JDBC URL with all the
attributes added to the query string. The result is suitable for use in
calls to `->pool` and `component` as the `:jdbcUrl` key in the parameter
map for the connection pooling library.
This allows you to build a connection-pooled datasource that needs
additional settings that the pooling library does not support, such as
`:serverTimezone`:
```clojure
(def db-spec {:dbtype .. :dbname .. :user .. :password ..
:serverTimezone \"UTC\"})
(def ds (next.jdbc.connection/->pool
HikariCP {:jdbcUrl (next.jdbc.connection/jdbc-url db-spec)
:maximumPoolSize 15}))
```
This also clearly separates the attributes that should be part of the
JDBC URL from the attributes that should be configured on the pool.
Since JDBC drivers can handle URL encoding differently, if you are
trying to pass attributes that might need encoding, you should make
sure they are properly URL-encoded as values in the database spec hash map.
This function does **not** attempt to URL-encode values for you!"
[db-spec]
(let [[url etc] (spec->url+etc db-spec)
url-and (if (str/index-of url "?") "&" "?")]
(str url url-and (str/join "&"
(reduce-kv (fn [pairs k v]
(conj pairs (str (name k) "=" v)))
[]
etc)))))
(defn ->pool (defn ->pool
"Given a (connection pooled datasource) class and a database spec, return a "Given a (connection pooled datasource) class and a database spec, return a
connection pool object built from that class and the database spec. connection pool object built from that class and the database spec.