From 382d1bef1047c564292ba324e39a1c5dd1129ba3 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Wed, 29 May 2019 13:51:11 -0700 Subject: [PATCH] Fix #24 by adding type hints --- CHANGELOG.md | 1 + src/next/jdbc.clj | 40 ++++++++++++++++++++++--------------- src/next/jdbc/protocols.clj | 2 +- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 871aff8..d6c4767 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,4 +23,5 @@ Only accretive/fixative changes will be made from now on (Beta 1). The following changes have been committed to the **master** branch and will be in the next release: +* Fix #24 by adding return type hints to `next.jdbc` functions. * Fix #22 by adding `next.jdbc.optional` with four map builders that omit `NULL` columns from the row hash maps. diff --git a/src/next/jdbc.clj b/src/next/jdbc.clj index deef04c..7c31036 100644 --- a/src/next/jdbc.clj +++ b/src/next/jdbc.clj @@ -87,6 +87,7 @@ * `redshift` -- `com.amazon.redshift.jdbc.Driver` -- no default port * `sqlite` -- `org.sqlite.JDBC` * `sqlserver`, `mssql` -- `com.microsoft.sqlserver.jdbc.SQLServerDriver` -- `1433`" + ^javax.sql.DataSource [spec] (p/get-datasource spec)) @@ -105,10 +106,12 @@ If you call `get-connection` on anything else, it will call `get-datasource` first to try to get a `DataSource`, and then call `get-connection` on that." - ([spec] - (p/get-connection spec {})) - ([spec opts] - (p/get-connection spec opts))) + (^java.sql.Connection + [spec] + (p/get-connection spec {})) + (^java.sql.Connection + [spec opts] + (p/get-connection spec opts))) (defn prepare "Given a connection to a database, and a vector containing SQL and any @@ -123,10 +126,12 @@ See the list of options above (in the namespace docstring) for what can be passed to prepare." - ([connection sql-params] - (p/prepare connection sql-params {})) - ([connection sql-params opts] - (p/prepare connection sql-params opts))) + (^java.sql.PreparedStatement + [connection sql-params] + (p/prepare connection sql-params {})) + (^java.sql.PreparedStatement + [connection sql-params opts] + (p/prepare connection sql-params opts))) (defn plan "General SQL execution function. @@ -135,14 +140,17 @@ Can be called on a `PreparedStatement`, a `Connection`, or something that can produce a `Connection` via a `DataSource`." - ([stmt] - (p/-execute stmt [] {})) - ([connectable sql-params] - (p/-execute connectable sql-params - {:next.jdbc/sql-params sql-params})) - ([connectable sql-params opts] - (p/-execute connectable sql-params - (assoc opts :next.jdbc/sql-params sql-params)))) + (^clojure.lang.IReduceInit + [stmt] + (p/-execute stmt [] {})) + (^clojure.lang.IReduceInit + [connectable sql-params] + (p/-execute connectable sql-params + {:next.jdbc/sql-params sql-params})) + (^clojure.lang.IReduceInit + [connectable sql-params opts] + (p/-execute connectable sql-params + (assoc opts :next.jdbc/sql-params sql-params)))) (defn execute! "General SQL execution function. diff --git a/src/next/jdbc/protocols.clj b/src/next/jdbc/protocols.clj index 9286069..6847de3 100644 --- a/src/next/jdbc/protocols.clj +++ b/src/next/jdbc/protocols.clj @@ -27,7 +27,7 @@ Implementations are provided for `DataSource`, `PreparedStatement`, and `Object`, on the assumption that an `Object` can be turned into a `DataSource`." - (get-connection ^java.lang.AutoCloseable [this opts] + (get-connection ^java.sql.Connection [this opts] "Produce a new `java.sql.Connection` for use with `with-open`.")) (defprotocol Executable