adding invoice db layer

This commit is contained in:
Bryce Covert
2017-12-08 07:48:04 -08:00
parent 252a6c5f9b
commit ef4dd52a42
3 changed files with 63 additions and 41 deletions

View File

@@ -0,0 +1,12 @@
(ns auto-ap.db.invoices
(:require [clojure.java.jdbc :as j]
[auto-ap.db.utils :use [clj->db db->clj conn]]))
(defn insert-multi! [rows]
(j/insert-multi! conn
:invoices
(map clj->db rows)))
(defn get-all []
(map db->clj (j/query conn "SELECT * FROM invoices")))

View File

@@ -0,0 +1,32 @@
(ns auto-ap.db.utils
(:require [clojure.string :as str]))
(defn snake->kebab [s]
(str/replace s #"_" "-"))
(defn kebab->snake [s]
(str/replace s #"-" "_"))
(defn db->clj [x]
(into {}
(map
(fn [[k v]]
[(keyword (snake->kebab (name k))) v])
x)))
(defn clj->db [x]
(into {}
(map
(fn [[k v]]
[(keyword (kebab->snake (name k))) v])
x)))
(def conn {:classname "org.postgresql.Driver" ; must be in classpath
:ssl true
:sslfactory "org.postgresql.ssl.NonValidatingFactory"
:subprotocol "postgresql"
:subname (str "//ec2-54-235-123-153.compute-1.amazonaws.com:5342/dbfemhppkdksfp")
; Any additional keys are passed to the driver
; as driver-specific properties.
:user "tkilrhrhzlumol"
:password "de6117f8551364ac84ed31c1231941f53ab0b5470c9956f478b2025ab5a0fb8b"})