From 5b197f975629e161c7099b177c775d2e7b5ff410 Mon Sep 17 00:00:00 2001 From: Jon Doane Date: Sat, 9 Jul 2016 10:37:33 -0400 Subject: [PATCH] Solve an issue where namespaced keywords and symbols where only taking the name portion of the identifier. - This now checks if there is a namespace and prepends it to the name if it exists. --- CHANGES.md | 2 ++ src/honeysql/format.clj | 5 ++++- test/honeysql/format_test.clj | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index d234883..84080a9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,7 @@ ## 0.7.1 In development +* Allow namespaced keywords and symbols for queries. (@jrdoane) + ## 0.7.0 * Parameterize numbers, properly handle NaN, Infinity, -Infinity (@akhudek) diff --git a/src/honeysql/format.clj b/src/honeysql/format.clj index 974819d..15dfe20 100644 --- a/src/honeysql/format.clj +++ b/src/honeysql/format.clj @@ -62,7 +62,10 @@ (quote-fns style) *quote-identifier-fn*) s (cond - (or (keyword? x) (symbol? x)) (name-transform-fn (name x)) + (or (keyword? x) (symbol? x)) + (name-transform-fn + (str (when-let [n (namespace x)] + (str n "/")) (name x))) (string? x) (if qf x (name-transform-fn x)) :else (str x))] (if-not qf diff --git a/test/honeysql/format_test.clj b/test/honeysql/format_test.clj index d35df79..13fbcc2 100644 --- a/test/honeysql/format_test.clj +++ b/test/honeysql/format_test.clj @@ -29,6 +29,10 @@ (is (= (quote-identifier :foo-bar.moo-bar :style :ansi) "\"foo-bar\".\"moo-bar\"")))) +(deftest test-namespaced-identifier + (is (= (quote-identifier :foo/bar) "foo/bar")) + (is (= (quote-identifier :foo/bar :style :ansi) "\"foo/bar\""))) + (deftest test-cte (is (= (format-clause (first {:with [[:query {:select [:foo] :from [:bar]}]]}) nil)