Back

datafiable-result-set (clj)

(source)

function

(datafiable-result-set rs) (datafiable-result-set rs conn-or-opts) (datafiable-result-set rs connectable opts)
Given a ResultSet, a connectable, and an options hash map, return a fully realized, datafiable result set per the `:builder-fn` option passed in. If no `:builder-fn` option is provided, `as-maps` is used as the default. The connectable and the options can both be omitted. If connectable is omitted, `nil` is used and no foreign key navigation will be available for any datafied result. If you want to pass a hash map as the connectable, you must also pass an options hash map. This can be used to process regular result sets or metadata result sets.

Examples

next-jdbc
  What's left to be tested:
  * ReadableColumn protocol extension point"
  (:require [clojure.core.protocols :as core-p]
            [clojure.datafy :as d]
            [clojure.string :as str]
            [clojure.test :refer [deftest is testing use-fixtures]]
            [next.jdbc.protocols :as p]
            [next.jdbc.result-set :as rs]
            [next.jdbc.specs :as specs]
            [next.jdbc.test-fixtures :refer [with-test-db ds column
                                              default-options
                                              derby? mssql? mysql? postgres?]])
  (:import (java.sql ResultSet ResultSetMetaData)))

(deftest metadata-result-set
  (let [metadata (with-open [con (p/get-connection (ds) {})]
                   (-> (.getMetaData con)
                       (.getTables nil nil nil (into-array ["TABLE" "VIEW"]))
                       (rs/datafiable-result-set (ds) {})))]
    (is (vector? metadata))
    (is (map? (first metadata)))
    ;; we should find :something/table_name with a value of "fruit"
    ;; may be upper/lower-case, could have any qualifier
    (is (some (fn [row]
                (some #(and (= "table_name" (-> % key name str/lower-case))
                            (= "fruit" (-> % val name str/lower-case)))
                      row))
              metadata))))
next-jdbc
(ns next.jdbc.datafy-test
  "Tests for the datafy extensions over JDBC types."
  (:require [clojure.datafy :as d]
            [clojure.set :as set]
            [clojure.test :refer [deftest is testing use-fixtures]]
            [next.jdbc :as jdbc]
            [next.jdbc.datafy]
            [next.jdbc.result-set :as rs]
            [next.jdbc.specs :as specs]
            [next.jdbc.test-fixtures
             :refer [with-test-db db ds
                      derby? jtds? mysql? postgres? sqlite?]]))

(comment
  (def con (jdbc/get-connection (ds)))
  (rs/datafiable-result-set (.getTables (.getMetaData con) nil nil nil nil) con {})
  (def ps (jdbc/prepare con ["SELECT * FROM fruit WHERE grade > ?"]))
  (require '[next.jdbc.prepare :as prep])
  (prep/set-parameters ps [30])
  (.execute ps)
  (.getResultSet ps)
  (.close ps)
  (.close con))
seancorfield/next-jdbc
(ns next.jdbc.datafy-test
  "Tests for the datafy extensions over JDBC types."
  (:require [clojure.datafy :as d]
            [clojure.set :as set]
            [clojure.test :refer [deftest is testing use-fixtures]]
            [next.jdbc :as jdbc]
            [next.jdbc.datafy]
            [next.jdbc.result-set :as rs]
            [next.jdbc.specs :as specs]
            [next.jdbc.test-fixtures
             :refer [with-test-db db ds
                      derby? jtds? mysql? postgres? sqlite?]]))

(comment
  (def con (jdbc/get-connection (ds)))
  (rs/datafiable-result-set (.getTables (.getMetaData con) nil nil nil nil) con {})
  (def ps (jdbc/prepare con ["SELECT * FROM fruit WHERE grade > ?"]))
  (require '[next.jdbc.prepare :as prep])
  (prep/set-parameters ps [30])
  (.execute ps)
  (.getResultSet ps)
  (.close ps)
  (.close con))
lambdaisland/plenish
(ns repl-sessions.jdbc-poke
  (:require [next.jdbc :as jdbc]
            [next.jdbc.result-set :as rs]
            [honey.sql :as honey]
            [honey.sql.helpers :as hh]))


(jdbc/on-connection
 [con ds]
 (-> (.getMetaData con) ; produces java.sql.DatabaseMetaData
     #_     (.getTables nil nil nil (into-array ["TABLE" "VIEW"]))
     (.getColumns nil nil "test" nil)
     (rs/datafiable-result-set ds nil)))