funcool / funcool/clojure.jdbc

Close connections when using a datasource directly, or don't let it be used directly.

Offen
#38 0 Kommentare 4 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Clojure
Sterne
106
Forks
23
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

javax.sql.DataSource implements the proto/IConnection protocol, but it's difficult to see how directly using it like that is anything but a misfeature. This protocol implementation lets you do the following:

`(jdbc/fetch datasource "select whatever from whatever;")`

If you do this, the connection that gets created will never get closed. You need to wrap the whole thing in a with-open, jdbc/connection like this:

```
(with-open [conn (jdbc/connection datasource)]
(jdbc/fetch conn "select whatever from whatever;"))
```

Seeing as how the first snippet is always a bad idea, it shouldn't be possible to write the first and have it succeed at all. If we're supposed to go through the connection wrapper jdbc/connection, then the api should force us to do exactly that and not silently succeed when misused.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.