Back
with-column (clj)
(source)protocol
(with-column _ row i)
Called with the row and the index of the column to be added;
this is expected to read the column value from the `ResultSet`!
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)))
(defn fruit-builder [^ResultSet rs ^ResultSetMetaData rsmeta]
(reify
rs/RowBuilder
(->row [_] (->Fruit (.getObject rs "id")
(.getObject rs "name")
(.getObject rs "appearance")
(.getObject rs "cost")
(.getObject rs "grade")))
(column-count [_] 0) ; no need to iterate over columns
(with-column [_ row i] row)
(with-column-value [_ row col v] row)
(row! [_ row] row)
rs/ResultSetBuilder
(->rs [_] (transient []))
(with-row [_ rs row] (conj! rs row))
(rs! [_ rs] (persistent! rs))
clojure.lang.ILookup ; only supports :cols and :rsmeta
(valAt [this k] (get this k nil))
(valAt [this k not-found]
(case k
:cols [:id :name :appearance :cost :grade]
:rsmeta rsmeta
not-found))))
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/execute!
ds
(honey/format
(-> (hh/create-table "foo" :if-not-exists)
(hh/with-columns [[:db__id :bigint [:primary-key]]]))))
jimmyhmiller/PlayGround
(ns sql-playground.core
(:require [next.jdbc :as jdbc]
[honey.sql :as sql]
[dotenv :as env]
[next.jdbc.result-set :as rs])
(:import [org.postgresql Driver]))
(jdbc/execute!
db
(sql/format {:create-table [:calories]
:with-columns [[:name :string]
[:calories :int]
[:timestamp :timestamptz]]}))