add helper for #567 and helper-based tests
Signed-off-by: Sean Corfield <sean@corfield.org>
This commit is contained in:
parent
4d1f5f83b7
commit
f0eb68f151
2 changed files with 25 additions and 8 deletions
|
|
@ -1,4 +1,4 @@
|
|||
;; copyright (c) 2020-2024 sean corfield, all rights reserved
|
||||
;; copyright (c) 2020-2025 sean corfield, all rights reserved
|
||||
|
||||
(ns honey.sql.helpers
|
||||
"Helper functions for the built-in clauses in honey.sql.
|
||||
|
|
@ -58,7 +58,7 @@
|
|||
bulk-collect-info [& args]
|
||||
|
||||
(as they are for all helper functions)."
|
||||
(:refer-clojure :exclude [distinct filter for group-by into partition-by set update])
|
||||
(:refer-clojure :exclude [assert distinct filter for group-by into partition-by set update])
|
||||
(:require [clojure.core :as c]
|
||||
[honey.sql :as h]))
|
||||
|
||||
|
|
@ -452,6 +452,14 @@
|
|||
[& clauses]
|
||||
(generic :except-all (cons {} clauses)))
|
||||
|
||||
(defn assert
|
||||
"Accepts an expression (predicate).
|
||||
|
||||
Produces: ASSERT expression"
|
||||
{:arglists '([expr])}
|
||||
[& args]
|
||||
(generic-1 :assert args))
|
||||
|
||||
(defn select
|
||||
"Accepts any number of column names, or column/alias
|
||||
pairs, or SQL expressions (optionally aliased):
|
||||
|
|
|
|||
|
|
@ -131,9 +131,18 @@
|
|||
(sql/format '{select (((get-in (. (object {_id 1 b "thing"}) b) c (lift 1) d)))}))))
|
||||
|
||||
(deftest assert-statement
|
||||
(testing "quoted sql"
|
||||
(is (= ["ASSERT NOT EXISTS (SELECT 1 FROM users WHERE email = 'james @example.com')"]
|
||||
(sql/format '{assert (not-exists {select 1 from users where (= email "james @example.com")})}
|
||||
:inline true)))
|
||||
(is (= ["ASSERT TRUE"]
|
||||
(sql/format '{assert true}
|
||||
:inline true))))
|
||||
(testing "helper"
|
||||
(is (= ["ASSERT NOT EXISTS (SELECT 1 FROM users WHERE email = 'james @example.com')"]
|
||||
(-> (h/assert [:not-exists {:select 1 :from :users :where [:= :email "james @example.com"]}])
|
||||
(sql/format {:inline true}))))
|
||||
(is (= ["ASSERT NOT EXISTS (SELECT 1 FROM users WHERE email = 'james @example.com')"]
|
||||
(-> {}
|
||||
(h/assert [:not-exists {:select 1 :from :users :where [:= :email "james @example.com"]}])
|
||||
(sql/format {:inline true}))))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue