This commit is contained in:
Bryce Covert
2018-04-05 18:17:45 -07:00
parent 7fc02c1d04
commit 33cfc395de
10 changed files with 230 additions and 4 deletions

View File

@@ -0,0 +1,22 @@
(ns auto-ap.db.vendors
(:require [clojure.java.jdbc :as j]
[auto-ap.db.utils :refer [clj->db db->clj get-conn]]
[clojure.edn :as edn]))
(defn merge-data [{:keys [data] :as x}]
(merge x (edn/read-string data)))
(defn parse [x]
(-> x
(db->clj)
merge-data
))
(defn get-all []
(->> (j/query (get-conn) "SELECT * FROM vendors")
(map parse)))
(defn upsert [id data]
(j/update! (get-conn) :vendors (clj->db data) ["id = ?" (Integer/parseInt id)] )
(merge-data (db->clj (first (j/query (get-conn) ["SELECT * FROM vendors WHERE id = ?" (Integer/parseInt id)])))))