Skip to content

Commit 4b17d11

Browse files
committed
add email validity function and introduce ::validity-checks
1 parent 9dbb45b commit 4b17d11

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

README.org

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,11 @@ Run =docker compose up= to have postgress running
166166
bb test:watch
167167
#+end_src
168168

169-
#+begin_src
169+
#+begin_src shell
170170
$ bin/koacha
171171
#+end_src
172172

173-
#+begin_src
173+
#+begin_src shell
174174
$ bin/koacha --watch
175175
#+end_src
176176

src/dqt/query_runner.clj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
[next.jdbc :as jdbc]
55
[next.jdbc.result-set :as rs]))
66

7+
(defn ->sql
8+
[q]
9+
(honey/format q))
10+
711
(defn execute!
812
"Execute query and builds result set with keys in kebab case"
913
([db query]
1014
(execute! db query {}))
1115
([db query opts]
12-
(let [formatted-query (honey/format query)]
16+
(let [formatted-query (->sql query)]
1317
(println formatted-query)
1418
(jdbc/execute! db formatted-query
1519
(assoc opts
@@ -20,7 +24,7 @@
2024
([db query]
2125
(execute-one! db query {}))
2226
([db query opts]
23-
(let [formatted-query (honey/format query)]
27+
(let [formatted-query (->sql query)]
2428
(println formatted-query)
2529
(jdbc/execute-one! db formatted-query
2630
(assoc opts

src/dqt/system.clj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
:columns-metadata (ig/ref ::columns-metadata-enriched))
1919
::calculated-metrics {:columns (ig/ref ::columns-metadata-enriched)
2020
:sql-metrics (ig/ref ::sql-metrics)}
21+
::validity-checks {:columns (ig/ref ::columns-metadata-enriched)}
2122
::test-results {:sql-metrics (ig/ref ::sql-metrics)
2223
:calculated-metrics (ig/ref ::calculated-metrics)
24+
:validity-checks (ig/ref ::validity-checks)
2325
:tests (:tests options)}
2426
::report (ig/ref ::test-results)})
2527

@@ -39,6 +41,11 @@
3941
[_ {:keys [db table-name columns-metadata]}]
4042
(m/get-metrics db table-name columns-metadata))
4143

44+
(defmethod ig/init-key ::validity-checks
45+
[_ {:keys [columns]}]
46+
(println "validity checks")
47+
(println columns))
48+
4249
(defmethod ig/init-key ::calculated-metrics
4350
[_ {:keys [columns sql-metrics]}]
4451
(into {} (map #(m/calculated-metrics % sql-metrics) columns)))

src/dqt/validity_checks.clj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
(ns dqt.validity-checks
2+
(:require [dqt.query-runner :as q]))
3+
4+
;; select EmailAddress from FindInvalidEmailAddressDemo
5+
;; -> where EmailAddress NOT LIKE '%_@_%._%';
6+
7+
(def email-regex #"%_@_%._%")
8+
9+
(defn email
10+
"Returns list of invalid emails from the column"
11+
[column table]
12+
{:select [column]
13+
:from table
14+
:where [column :not :like email-regex]})

0 commit comments

Comments
 (0)