automated imports.
This commit is contained in:
@@ -68,9 +68,10 @@
|
||||
:else
|
||||
q)))
|
||||
|
||||
(defn base-graphql [{:keys [company-id]}]
|
||||
(defn base-graphql [{:keys [company-id vendor-id]}]
|
||||
(cond-> base-query
|
||||
(not (nil? company-id)) (helpers/merge-where [:= :company-id company-id])))
|
||||
(not (nil? company-id)) (helpers/merge-where [:= :company-id company-id])
|
||||
(not (nil? vendor-id)) (helpers/merge-where [:= :vendor-id vendor-id])))
|
||||
|
||||
(defn get-graphql [{:keys [start sort-by asc] :as args}]
|
||||
(query
|
||||
|
||||
32
src/clj/auto_ap/db/transactions.clj
Normal file
32
src/clj/auto_ap/db/transactions.clj
Normal file
@@ -0,0 +1,32 @@
|
||||
(ns auto-ap.db.transactions
|
||||
(:require [clojure.java.jdbc :as j]
|
||||
[honeysql.core :as sql]
|
||||
[honeysql.helpers :as helpers]
|
||||
[honeysql-postgres.format :as postgres-format]
|
||||
[honeysql-postgres.helpers :as postgres-helpers]
|
||||
[auto-ap.db.utils :refer [clj->db kebab->snake db->clj get-conn query] :as utils]))
|
||||
|
||||
(defn upsert! [row]
|
||||
(j/db-do-prepared (get-conn)
|
||||
(sql/format (-> (helpers/insert-into :transactions)
|
||||
(helpers/values [row])
|
||||
(postgres-helpers/upsert (-> (postgres-helpers/on-conflict :id)
|
||||
(postgres-helpers/do-update-set :post_date :status)))))))
|
||||
|
||||
(def base-query (sql/build :select :*
|
||||
:from :transactions))
|
||||
|
||||
(defn base-graphql [{:keys [company-id]}]
|
||||
(cond-> base-query
|
||||
(not (nil? company-id)) (helpers/merge-where [:= :company-id company-id])))
|
||||
|
||||
(defn get-graphql [{:keys [start sort-by asc] :as args}]
|
||||
(query
|
||||
(cond-> (base-graphql args)
|
||||
#_#_(not (nil? sort-by) ) (add-sort-by sort-by asc)
|
||||
true (assoc :limit 20)
|
||||
start (assoc :offset start))))
|
||||
|
||||
(defn count-graphql [args]
|
||||
(:count (first (query
|
||||
(assoc (base-graphql args) :select [:%count.*])))))
|
||||
@@ -1,14 +0,0 @@
|
||||
(ns auto-ap.db.yodlee-imports
|
||||
(:require [clojure.java.jdbc :as j]
|
||||
[honeysql.core :as sql]
|
||||
[honeysql.helpers :as helpers]
|
||||
[honeysql-postgres.format :as postgres-format]
|
||||
[honeysql-postgres.helpers :as postgres-helpers]
|
||||
[auto-ap.db.utils :refer [clj->db kebab->snake db->clj get-conn query] :as utils]))
|
||||
|
||||
(defn upsert! [row]
|
||||
(j/db-do-prepared (get-conn)
|
||||
(sql/format (-> (helpers/insert-into :yodlee-imports)
|
||||
(helpers/values [row])
|
||||
(postgres-helpers/upsert (-> (postgres-helpers/on-conflict :id)
|
||||
(postgres-helpers/do-update-set :amount :status)))))))
|
||||
Reference in New Issue
Block a user