File tree Expand file tree Collapse file tree 2 files changed +35
-3
lines changed Expand file tree Collapse file tree 2 files changed +35
-3
lines changed Original file line number Diff line number Diff line change 4
4
[camel-snake-kebab.core :refer [->snake_case]]))
5
5
6
6
(def ^:dynamic *output-ident-style*
7
- #(->snake_case %1 :separator " -" ))
7
+ #(try
8
+ (->snake_case %1 :separator " -" )
9
+ (catch Exception _
10
+ %1 )))
8
11
9
12
(defmacro with-output-ident-style [f & body]
10
13
`(binding [*output-ident-style* ~f]
98
101
" and"
99
102
(as-ident higher opts)])))
100
103
104
+ (defn emit-in
105
+ ([v]
106
+ (emit-in v {}))
107
+ ([v opts]
108
+ (emit-infix-op v (assoc opts :separator " ," ))))
109
+
101
110
(defn emit-literal-identifier
102
111
([v]
103
112
(emit-literal-identifier v {}))
126
135
(def-ops #'emit-sql '[sql])
127
136
(def-ops #'emit-between '[between])
128
137
(def-ops #'emit-literal-identifier '[ident])
138
+ (def-ops #'emit-in '[in])
129
139
130
140
(defn emit-function
131
141
([v]
234
244
(fn [[k v]]
235
245
(if ((set (keys *remapped-idents*)) v)
236
246
[k v]
237
- (list '= k v)))))
247
+ (if (coll? v)
248
+ (list 'in k v)
249
+ (list '= k v))))))
238
250
expr (if (< (count expr) 1 )
239
251
(list* 'and expr)
240
252
(cons 'and expr))]
262
274
(str/join " " ))))
263
275
264
276
(defn emit-select [{:keys [select
277
+ distinct?
265
278
from
266
279
where
267
280
order-by
268
281
group-by
269
282
limit
270
283
join]}]
271
284
(when select
272
- (->> [[" select" select]
285
+ (->> [[( str " select" ( when distinct? " distinct " )) select]
273
286
[" from" from #'emit-from-clause]
274
287
[" where" where #'emit-where-clause]
275
288
[" group by" group-by]
Original file line number Diff line number Diff line change 371
371
{:select [:related_id :type :description ]
372
372
:from :b_events
373
373
:where {:related_id " {{related-id}}" }}]}))))
374
+
375
+ (deftest select-distinct-test
376
+ (is (= (canon
377
+ [" select distinct id1,id2,id3 from a_events" ])
378
+ (sql/sql
379
+ '{:select [:id1 :id2 :id3 ]
380
+ :distinct? true
381
+ :from :a_events }))))
382
+
383
+ (deftest where-in-test
384
+ (is (= (canon
385
+ [" select id,name from a_events"
386
+ " where (id in ('foo','bar'))"
387
+ " and (name = 'baz')" ])
388
+ (sql/sql
389
+ '{:select [:id :name ]
390
+ :from :a_events
391
+ :where {:id [" foo" " bar" ]
392
+ :name " baz" }}))))
You can’t perform that action at this time.
0 commit comments