|
55 | 55 | do-nothing)) |
56 | 56 | sql/format))))) |
57 | 57 |
|
58 | | - |
59 | 58 | (deftest upsert-where-test |
60 | 59 | (is (= ["INSERT INTO user (phone, name) VALUES (?, ?) ON CONFLICT (phone) WHERE phone IS NOT NULL DO UPDATE SET phone = EXCLUDED.phone, name = EXCLUDED.name WHERE user.active = FALSE" "5555555" "John"] |
61 | 60 | (sql/format |
62 | | - {:insert-into :user |
63 | | - :values [{:phone "5555555" :name "John"}] |
64 | | - :upsert {:on-conflict [:phone] |
65 | | - :where [:<> :phone nil] |
66 | | - :do-update-set {:fields [:phone :name] |
67 | | - :where [:= :user.active false]}}})))) |
68 | | - |
| 61 | + {:insert-into :user |
| 62 | + :values [{:phone "5555555" :name "John"}] |
| 63 | + :upsert {:on-conflict [:phone] |
| 64 | + :where [:<> :phone nil] |
| 65 | + :do-update-set {:fields [:phone :name] |
| 66 | + :where [:= :user.active false]}}})))) |
69 | 67 |
|
70 | 68 | (deftest returning-test |
71 | 69 | (testing "returning clause in sql generation for postgresql" |
72 | 70 | (is (= ["DELETE FROM distributors WHERE did > 10 RETURNING *"] |
73 | 71 | (sql/format {:delete-from :distributors |
74 | 72 | :where [:> :did :10] |
75 | | - :returning [:*] }))) |
| 73 | + :returning [:*]}))) |
76 | 74 | (is (= ["UPDATE distributors SET dname = ? WHERE did = 2 RETURNING did dname" "Foo Bar Designs"] |
77 | 75 | (-> (update :distributors) |
78 | 76 | (sset {:dname "Foo Bar Designs"}) |
|
209 | 207 | (testing "select from table with ILIKE operator" |
210 | 208 | (is (= ["SELECT * FROM products WHERE name ILIKE ?" "%name%"] |
211 | 209 | (-> (select :*) |
212 | | - (from :products) |
213 | | - (where [:ilike :name "%name%"]) |
214 | | - sql/format))))) |
| 210 | + (from :products) |
| 211 | + (where [:ilike :name "%name%"]) |
| 212 | + sql/format))))) |
215 | 213 |
|
216 | 214 | (deftest select-where-not-ilike |
217 | 215 | (testing "select from table with NOT ILIKE operator" |
218 | 216 | (is (= ["SELECT * FROM products WHERE name NOT ILIKE ?" "%name%"] |
219 | 217 | (-> (select :*) |
220 | | - (from :products) |
221 | | - (where [:not-ilike :name "%name%"]) |
222 | | - sql/format))))) |
| 218 | + (from :products) |
| 219 | + (where [:not-ilike :name "%name%"]) |
| 220 | + sql/format))))) |
223 | 221 |
|
224 | 222 | (deftest values-except-select |
225 | 223 | (testing "select which values are not not present in a table" |
226 | 224 | (is (= ["VALUES (?), (?), (?) EXCEPT SELECT id FROM images" 4 5 6] |
227 | 225 | (sql/format |
228 | | - {:except |
229 | | - [{:values [[4] [5] [6]]} |
230 | | - {:select [:id] :from [:images]}]}))))) |
231 | | - |
| 226 | + {:except |
| 227 | + [{:values [[4] [5] [6]]} |
| 228 | + {:select [:id] :from [:images]}]}))))) |
232 | 229 |
|
233 | 230 | (deftest select-except-select |
234 | 231 | (testing "select which rows are not present in another table" |
|
238 | 235 | [{:select [:ip]} |
239 | 236 | {:select [:ip] :from [:ip_location]}]}))))) |
240 | 237 |
|
241 | | - |
242 | 238 | (deftest values-except-all-select |
243 | 239 | (testing "select which values are not not present in a table" |
244 | 240 | (is (= ["VALUES (?), (?), (?) EXCEPT ALL SELECT id FROM images" 4 5 6] |
|
247 | 243 | [{:values [[4] [5] [6]]} |
248 | 244 | {:select [:id] :from [:images]}]}))))) |
249 | 245 |
|
250 | | - |
251 | 246 | (deftest select-except-all-select |
252 | 247 | (testing "select which rows are not present in another table" |
253 | 248 | (is (= ["SELECT ip EXCEPT ALL SELECT ip FROM ip_location"] |
|
260 | 255 | (testing "select distinct on" |
261 | 256 | (is (= ["SELECT DISTINCT ON(\"a\", \"b\") \"c\" FROM \"products\" "] |
262 | 257 | (-> (select :c) |
263 | | - (from :products) |
264 | | - (modifiers :distinct-on :a :b) |
265 | | - (sql/format :quoting :ansi)))))) |
| 258 | + (from :products) |
| 259 | + (modifiers :distinct-on :a :b) |
| 260 | + (sql/format :quoting :ansi)))))) |
0 commit comments