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 diff --git a/src/next/jdbc/quoted.clj b/src/next/jdbc/quoted.clj index 1e5cdc7..598354a 100644 --- a/src/next/jdbc/quoted.clj +++ b/src/next/jdbc/quoted.clj @@ -6,6 +6,8 @@ from Clojure data." (:require [clojure.string :as str])) +(set! *warn-on-reflection* true) + (defn ansi "ANSI \"quoting\"" [s] (str \" s \")) (defn mysql "MySQL `quoting`" [s] (str \` s \`)) diff --git a/src/next/jdbc/specs.clj b/src/next/jdbc/specs.clj index 80cda5b..2c08ceb 100644 --- a/src/next/jdbc/specs.clj +++ b/src/next/jdbc/specs.clj @@ -19,6 +19,8 @@ (:import (java.sql Connection PreparedStatement) (javax.sql DataSource))) +(set! *warn-on-reflection* true) + (s/def ::dbtype string?) (s/def ::dbname string?) (s/def ::classname string?) diff --git a/src/next/jdbc/sql.clj b/src/next/jdbc/sql.clj index ba7deb9..7958bbb 100644 --- a/src/next/jdbc/sql.clj +++ b/src/next/jdbc/sql.clj @@ -22,6 +22,8 @@ (:require [clojure.string :as str] [next.jdbc :refer [execute! execute-one!]])) +(set! *warn-on-reflection* true) + (defn- by-keys "Given a hash map of column names and values and a clause type (`:set`, `:where`), return a vector of a SQL clause and its parameters. diff --git a/test/next/jdbc/connection_test.clj b/test/next/jdbc/connection_test.clj index e4809e6..4b36862 100644 --- a/test/next/jdbc/connection_test.clj +++ b/test/next/jdbc/connection_test.clj @@ -11,6 +11,8 @@ [next.jdbc.connection :as c] [next.jdbc.protocols :as p])) +(set! *warn-on-reflection* true) + (def ^:private db-name "clojure_test") (deftest test-aliases-and-defaults diff --git a/test/next/jdbc/optional_test.clj b/test/next/jdbc/optional_test.clj index 8ba85fa..6d218d1 100644 --- a/test/next/jdbc/optional_test.clj +++ b/test/next/jdbc/optional_test.clj @@ -8,6 +8,8 @@ [next.jdbc.protocols :as p] [next.jdbc.test-fixtures :refer [with-test-db ds]])) +(set! *warn-on-reflection* true) + (use-fixtures :once with-test-db) (deftest test-map-row-builder diff --git a/test/next/jdbc/prepare_test.clj b/test/next/jdbc/prepare_test.clj index daa6850..3703332 100644 --- a/test/next/jdbc/prepare_test.clj +++ b/test/next/jdbc/prepare_test.clj @@ -9,3 +9,5 @@ actually work they way they're supposed to!" (:require [clojure.test :refer [deftest is testing]] [next.jdbc.prepare :refer :all])) + +(set! *warn-on-reflection* true) diff --git a/test/next/jdbc/protocols_test.clj b/test/next/jdbc/protocols_test.clj index b177726..b5be805 100644 --- a/test/next/jdbc/protocols_test.clj +++ b/test/next/jdbc/protocols_test.clj @@ -5,3 +5,5 @@ at this level tho'..." (:require [clojure.test :refer [deftest is testing]] [next.jdbc.protocols :refer :all])) + +(set! *warn-on-reflection* true) diff --git a/test/next/jdbc/quoted_test.clj b/test/next/jdbc/quoted_test.clj index 0c52762..e62babb 100644 --- a/test/next/jdbc/quoted_test.clj +++ b/test/next/jdbc/quoted_test.clj @@ -7,6 +7,8 @@ [next.jdbc.quoted :refer [ansi mysql sql-server oracle postgres schema]])) +(set! *warn-on-reflection* true) + (deftest basic-quoting (are [quote-fn quoted] (= (quote-fn "x") quoted) ansi "\"x\"" diff --git a/test/next/jdbc/result_set_test.clj b/test/next/jdbc/result_set_test.clj index 802007f..a01b7ac 100644 --- a/test/next/jdbc/result_set_test.clj +++ b/test/next/jdbc/result_set_test.clj @@ -14,6 +14,8 @@ [next.jdbc.test-fixtures :refer [with-test-db ds]]) (:import (java.sql ResultSet ResultSetMetaData))) +(set! *warn-on-reflection* true) + (use-fixtures :once with-test-db) (deftest test-datafy-nav diff --git a/test/next/jdbc/specs_test.clj b/test/next/jdbc/specs_test.clj index 19cdee5..56d92f4 100644 --- a/test/next/jdbc/specs_test.clj +++ b/test/next/jdbc/specs_test.clj @@ -7,3 +7,5 @@ next.jdbc and next.jdbc.sql namespaces." (:require [clojure.test :refer [deftest is testing]] [next.jdbc.specs :refer :all])) + +(set! *warn-on-reflection* true) diff --git a/test/next/jdbc/sql_test.clj b/test/next/jdbc/sql_test.clj index fa43136..d211436 100644 --- a/test/next/jdbc/sql_test.clj +++ b/test/next/jdbc/sql_test.clj @@ -11,6 +11,8 @@ [next.jdbc.test-fixtures :refer [with-test-db ds derby? sqlite?]])) +(set! *warn-on-reflection* true) + (use-fixtures :once with-test-db) (specs/instrument) diff --git a/test/next/jdbc/test_fixtures.clj b/test/next/jdbc/test_fixtures.clj index a304114..d4e19f8 100644 --- a/test/next/jdbc/test_fixtures.clj +++ b/test/next/jdbc/test_fixtures.clj @@ -5,6 +5,8 @@ (:require [next.jdbc :as jdbc] [next.jdbc.sql :as sql])) +(set! *warn-on-reflection* true) + (def ^:private test-derby {:dbtype "derby" :dbname "clojure_test_derby" :create true}) (def ^:private test-h2-mem {:dbtype "h2:mem" :dbname "clojure_test_h2_mem"}) diff --git a/test/next/jdbc/transaction_test.clj b/test/next/jdbc/transaction_test.clj index 96b8395..c817ba3 100644 --- a/test/next/jdbc/transaction_test.clj +++ b/test/next/jdbc/transaction_test.clj @@ -4,3 +4,5 @@ "Stub test namespace for transaction handling." (:require [clojure.test :refer [deftest is testing]] [next.jdbc.transaction :refer :all])) + +(set! *warn-on-reflection* true) diff --git a/test/next/jdbc_test.clj b/test/next/jdbc_test.clj index dd39527..ac0baff 100644 --- a/test/next/jdbc_test.clj +++ b/test/next/jdbc_test.clj @@ -10,6 +10,8 @@ [next.jdbc.specs :as specs]) (:import (java.sql ResultSet ResultSetMetaData))) +(set! *warn-on-reflection* true) + (use-fixtures :once with-test-db) (specs/instrument)