Skip to content

Commit

Permalink
add email validity function and introduce ::validity-checks
Browse files Browse the repository at this point in the history
  • Loading branch information
WarFox committed Jul 7, 2023
1 parent 9dbb45b commit 4b17d11
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ Run =docker compose up= to have postgress running
bb test:watch
#+end_src

#+begin_src
#+begin_src shell
$ bin/koacha
#+end_src

#+begin_src
#+begin_src shell
$ bin/koacha --watch
#+end_src

Expand Down
8 changes: 6 additions & 2 deletions src/dqt/query_runner.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
[next.jdbc :as jdbc]
[next.jdbc.result-set :as rs]))

(defn ->sql
[q]
(honey/format q))

(defn execute!
"Execute query and builds result set with keys in kebab case"
([db query]
(execute! db query {}))
([db query opts]
(let [formatted-query (honey/format query)]
(let [formatted-query (->sql query)]
(println formatted-query)
(jdbc/execute! db formatted-query
(assoc opts
Expand All @@ -20,7 +24,7 @@
([db query]
(execute-one! db query {}))
([db query opts]
(let [formatted-query (honey/format query)]
(let [formatted-query (->sql query)]
(println formatted-query)
(jdbc/execute-one! db formatted-query
(assoc opts
Expand Down
7 changes: 7 additions & 0 deletions src/dqt/system.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
:columns-metadata (ig/ref ::columns-metadata-enriched))
::calculated-metrics {:columns (ig/ref ::columns-metadata-enriched)
:sql-metrics (ig/ref ::sql-metrics)}
::validity-checks {:columns (ig/ref ::columns-metadata-enriched)}
::test-results {:sql-metrics (ig/ref ::sql-metrics)
:calculated-metrics (ig/ref ::calculated-metrics)
:validity-checks (ig/ref ::validity-checks)
:tests (:tests options)}
::report (ig/ref ::test-results)})

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

(defmethod ig/init-key ::validity-checks
[_ {:keys [columns]}]
(println "validity checks")
(println columns))

(defmethod ig/init-key ::calculated-metrics
[_ {:keys [columns sql-metrics]}]
(into {} (map #(m/calculated-metrics % sql-metrics) columns)))
Expand Down
14 changes: 14 additions & 0 deletions src/dqt/validity_checks.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(ns dqt.validity-checks
(:require [dqt.query-runner :as q]))

;; select EmailAddress from FindInvalidEmailAddressDemo
;; -> where EmailAddress NOT LIKE '%_@_%._%';

(def email-regex #"%_@_%._%")

(defn email
"Returns list of invalid emails from the column"
[column table]
{:select [column]
:from table
:where [column :not :like email-regex]})

0 comments on commit 4b17d11

Please sign in to comment.