Skip to content
Snippets Groups Projects
Commit 7ce16a34 authored by Cam Saül's avatar Cam Saül
Browse files

Minor code cleanup for #3858

parent dfe3e963
No related branches found
No related tags found
No related merge requests found
......@@ -60,17 +60,17 @@
(defn- describe-table-fields
[database, driver, {:keys [schema name]}]
(let [columns (jdbc/query
(sql/db->jdbc-connection-spec database)
[(format "select column_name, data_type as type_name
(sql/db->jdbc-connection-spec database)
[(format "select column_name, data_type as type_name
from information_schema.columns
where table_name like '%s' and table_schema like '%s'
and data_type != 'object_array'" name schema)])] ; clojure jdbc can't handle fields of type "object_array" atm
(set (for [{:keys [column_name type_name]} columns]
(merge {:name column_name
:custom {:column-type type_name}
:base-type (or (column->base-type (keyword type_name))
(do (log/warn (format "Don't know how to map column type '%s' to a Field base_type, falling back to :type/*." type_name))
:type/*))})))))
{:name column_name
:custom {:column-type type_name}
:base-type (or (column->base-type (keyword type_name))
(do (log/warn (format "Don't know how to map column type '%s' to a Field base_type, falling back to :type/*." type_name))
:type/*))}))))
(defn- add-table-pks
[^DatabaseMetaData metadata, table]
......
......@@ -21,8 +21,10 @@
(intern 'honeysql.format 'quote-fns
(assoc quote-fns :h2 (comp s/upper-case ansi-quote-fn))))
;; `:crate` quote style that correctly quotes nested column identifiers
(defn- str-insert
"Insert c in string s at index i."
"Insert C in string S at index I."
[s c i]
(str c (subs s 0 i) c (subs s i)))
......@@ -33,10 +35,10 @@
(str \" s \")
(str-insert s "\"" idx))))
;; `:crate` quote style that correctly quotes nested column identifiers
(let [quote-fns @(resolve 'honeysql.format/quote-fns)]
(->> (assoc quote-fns :crate crate-column-identifier)
(intern 'honeysql.format 'quote-fns)))
(let [quote-fns @(resolve 'honeysql.format/quote-fns)]
(intern 'honeysql.format 'quote-fns
(assoc quote-fns :crate crate-column-identifier)))
;; register the `extract` function with HoneySQL
;; (hsql/format (hsql/call :extract :a :b)) -> "extract(a from b)"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment