Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. (defn get-columns
  2. [_]
  3. #{"part_id" "name" "image_paths"})
  4.  
  5. (defn update
  6. [_ _ _]
  7. "UPDATED!!")
  8.  
  9. (defmacro UPDATER
  10. [table]
  11. (let [column-names (vec (get-columns table))
  12. column-symbols (map symbol column-names)
  13. column-names-and-symbols (zipmap column-names column-symbols)]
  14. `(fn [& {:keys [~@column-symbols ~'where]
  15. :or ~(zipmap column-symbols
  16. (repeat (count column-names) nil))}]
  17. (let [#_~@(reduce into [] (for [col column-symbols] [col col]))
  18. provided-columns# (for [col-name# ~column-names
  19. :let [col-sym# (get ~column-names-and-symbols col-name#)]
  20. :when col-sym#]
  21. col-name#)
  22. provided-columns-and-values# (zipmap (map keyword provided-columns#)
  23. (map ~column-names-and-symbols provided-columns#))]
  24. (println (pr-str provided-columns#))
  25. (println (pr-str provided-columns-and-values#))
  26. ;; don't forget to wrap `where` with `build-where-clause`
  27. (update ~(eval `(keyword '~table)) provided-columns-and-values# ~'where)
  28. #_(zipmap ~column-symbols provided-columns#)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement