Skip to content

Instantly share code, notes, and snippets.

@jcromartie
Created December 20, 2010 21:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jcromartie/e79f096508ef51b20459 to your computer and use it in GitHub Desktop.
(defn d-mask-col!
[table col rule]
(let [colfn (rule table col)]
(when (fn? colfn)
(let [raw-vals (db/distinct-values table col)
non-nil-vals (remove nil? raw-vals)
old-new-vals (map (juxt identity colfn) non-nil-vals)
c-path (db/path col)
execute #(apply sql/do-prepared % old-new-vals)
using-comparison #(format "update %s set %s = ? where %s %s ?" (db/path table) c-path c-path %)]
(println "Masking" (count non-nil-vals) "value(s) of" (db/path table col))
(try
(execute (using-comparison "="))
(catch Exception e
(if (text-type-fail? e)
(execute (using-comparison "like"))
(throw e))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment