specing.
This commit is contained in:
@@ -1,29 +1,47 @@
|
||||
(ns auto-ap.db.vendors
|
||||
(:require [clojure.java.jdbc :as j]
|
||||
[auto-ap.db.utils :refer [clj->db db->clj get-conn]]
|
||||
[auto-ap.entities.vendors :as entities]
|
||||
[clojure.edn :as edn]))
|
||||
|
||||
(defn merge-data [{:keys [data] :as x}]
|
||||
(merge x (edn/read-string data)))
|
||||
|
||||
(defn assign-namespace [x n]
|
||||
(reduce-kv
|
||||
(fn [x k v]
|
||||
(assoc x (if (and (keyword? k)
|
||||
(not (qualified-keyword? k)))
|
||||
(keyword n (name k))
|
||||
k)
|
||||
v))
|
||||
{}
|
||||
x))
|
||||
|
||||
(defn parse [x]
|
||||
(-> x
|
||||
(db->clj)
|
||||
merge-data
|
||||
(assign-namespace "auto-ap.entities.vendors")
|
||||
))
|
||||
|
||||
(defn unparse [x]
|
||||
(-> x
|
||||
(select-keys entities/all-keys)
|
||||
clj->db))
|
||||
|
||||
(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)])))))
|
||||
(j/update! (get-conn) :vendors (unparse data) ["id = ?" (Integer/parseInt id)] )
|
||||
(parse (first (j/query (get-conn) ["SELECT * FROM vendors WHERE id = ?" (Integer/parseInt id)]))))
|
||||
|
||||
(defn insert [data]
|
||||
(parse (first (j/insert! (get-conn)
|
||||
:vendors
|
||||
(clj->db data)))))
|
||||
(unparse data)))))
|
||||
|
||||
(defn find-with-reminders []
|
||||
(map parse (j/query (get-conn) ["SELECT * FROM vendors WHERE invoice_reminder_schedule = ?" "Weekly"])))
|
||||
|
||||
Reference in New Issue
Block a user