aboutsummaryrefslogtreecommitdiff
path: root/src/clojure
diff options
context:
space:
mode:
authorscgilardi <scgilardi@gmail.com>2009-01-19 23:05:21 +0000
committerscgilardi <scgilardi@gmail.com>2009-01-19 23:05:21 +0000
commit871691588879b665fe4f73303695e5ab6bad4f21 (patch)
tree91f9dc8ce0e2261567ad35f39692f1020728f6a6 /src/clojure
parent936ca26a3f7e9b72a8752ba2ce8dbf0a7173e98a (diff)
sql: provide find-connection, returns current connection or nil
Diffstat (limited to 'src/clojure')
-rw-r--r--src/clojure/contrib/sql.clj3
-rw-r--r--src/clojure/contrib/sql/internal.clj7
2 files changed, 8 insertions, 2 deletions
diff --git a/src/clojure/contrib/sql.clj b/src/clojure/contrib/sql.clj
index f4e1ac3f..75242b5c 100644
--- a/src/clojure/contrib/sql.clj
+++ b/src/clojure/contrib/sql.clj
@@ -19,8 +19,9 @@
(:use [clojure.contrib.def :only (defalias)])
(:use clojure.contrib.sql.internal))
+(defalias find-connection find-connection*)
(defalias connection connection*)
-
+
(defmacro with-connection
"Evaluates body in the context of a new connection to a database then
closes the connection. db-spec is a map containing string values for
diff --git a/src/clojure/contrib/sql/internal.clj b/src/clojure/contrib/sql/internal.clj
index 1c75ee65..9f1aca7e 100644
--- a/src/clojure/contrib/sql/internal.clj
+++ b/src/clojure/contrib/sql/internal.clj
@@ -32,10 +32,15 @@
(.setProperty p (the-str key) (the-str val)))
p))
+(defn find-connection*
+ "Returns the current database connection (or nil if there is none)"
+ []
+ (:connection *db*))
+
(defn connection*
"Returns the current database connection (or throws if there is none)"
[]
- (or (:connection *db*)
+ (or (find-connection*)
(throw (Exception. "no current database connection"))))
(defn rollback-only