From 1f2773bd16dbc5a7ead1e33d2166afb1ad7b076c Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Wed, 2 Feb 2022 22:04:44 -0800 Subject: [PATCH] address #352 by treating :'foo literally --- src/honey/sql.cljc | 11 ++++++++--- test/honey/sql_test.cljc | 11 ++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index b0268d1..2ca8b55 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -167,12 +167,17 @@ (defn sql-kw "Given a keyword, return a SQL representation of it as a string. - A `:kebab-case` keyword becomes a `KEBAB CASE` (uppercase) string - with hyphens replaced by spaces, e.g., `:insert-into` => `INSERT INTO`. + A keyword whose name begins with a single quote is left exactly as-is + (with the `:` and `'` removed), otherwise a `:kebab-case` keyword + becomes a `KEBAB CASE` (uppercase) string with hyphens replaced + by spaces, e.g., `:insert-into` => `INSERT INTO`. Any namespace qualifier is ignored." [k] - (-> k (name) (dehyphen) (upper-case))) + (let [n (name k)] + (if (= \' (first n)) + (subs n 1 (count n)) + (-> n (dehyphen) (upper-case))))) (defn- sym->kw "Given a symbol, produce a keyword, retaining the namespace diff --git a/test/honey/sql_test.cljc b/test/honey/sql_test.cljc index 0844ff1..012fbc8 100644 --- a/test/honey/sql_test.cljc +++ b/test/honey/sql_test.cljc @@ -794,7 +794,16 @@ ORDER BY id = ? DESC (format {:select (keyword "%mixed-kebab.yum-yum/bar-bar.a-b/c-d")} :dialect :mysql :quoted-snake true))) (is (= ["SELECT RANSOM(`NoTe`)"] (format {:select [[[:ransom :NoTe]]]} :dialect :mysql) - (format {:select :%ransom.NoTe} :dialect :mysql))))) + (format {:select :%ransom.NoTe} :dialect :mysql)))) + (testing "issue 352: literal function calls" + (is (= ["SELECT sysdate()"] + (format {:select [[[:'sysdate]]]}))) + (is (= ["SELECT count(*)"] + (format {:select [[[:'count :*]]]}))) + (is (= ["SELECT Mixed-Kebab(`yum-yum`)"] + (format {:select [[[:'Mixed-Kebab :yum-yum]]]} :dialect :mysql))) + (is (= ["SELECT other-project.other_dataset.other_function(?, ?)" 1 2] + (format {:select [[[:'other-project.other_dataset.other_function 1 2]]]}))))) (deftest join-without-on-using ;; essentially issue 326