                                          QueryLanguage/SPARQL
                                          sparql-string)]
       (.execute prepared-query))))
+
+(extend-protocol ToConnection
+  RepositoryConnection
+  (->connection
+    [^Repository repo]
+    (if (instance? RepositoryConnection repo)
+      repo
+      (let [c (.getConnection repo)]
+        c)))
+
+  SailRepository
+  (->connection
+    [^Repository repo]
+    (.getConnection repo))
+
+  SPARQLRepository
+  (->connection
+    [^Repository repo]
+    (.getConnection repo)))
 
 (defn make-restricted-dataset
   "Build a dataset to act as a graph restriction.  You can specify for

            [grafter.rdf.protocols :as pr]
            [grafter.rdf.io :refer :all]
            [clojure.tools.logging :as log])
  (:import (grafter.rdf.protocols IStatement Quad Triple)
           (java.io File)
           (java.net MalformedURLException URL)
           (java.util GregorianCalendar)

  (evaluate [this]
    (.execute this)))

(defn prepare-query
  "Low level function to prepare (parse, but not process) a sesame RDF
  query.  Takes a repository a query string and an optional sesame
