Skip to content

Commit

Permalink
Enable cedric/Csv only in clj
Browse files Browse the repository at this point in the history
  • Loading branch information
verberktstan committed Feb 13, 2024
1 parent bf32f0e commit cfd3a69
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/swark/cedric.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -243,20 +243,21 @@
(with-open [reader (open-or-create! filename)]
(-> reader (csv/read-csv :separator \;) doall)))

(defrecord Csv [filename]
Cedric
(upsert-items [this {:keys [primary-key] :as props} items]
(let [rows (read-csv filename)
new-rows (apply upsert rows props items)
updated-pvals (seq (keep #(get % primary-key) items))]
(write-csv! filename new-rows)
(merge-rows
(cond-> {::primary-key #{primary-key}} updated-pvals (assoc ::primary-value (set updated-pvals)))
new-rows)))
(read-items [this props] (merge-rows props (read-csv filename)))
(archive-items [this props items]
(let [rows (read-csv filename)
new-rows (apply archive rows props items)]
(write-csv! filename new-rows)
{::archived (count new-rows)})))
#?(:clj
(defrecord Csv [filename]
Cedric
(upsert-items [this {:keys [primary-key] :as props} items]
(let [rows (read-csv filename)
new-rows (apply upsert rows props items)
updated-pvals (seq (keep #(get % primary-key) items))]
(write-csv! filename new-rows)
(merge-rows
(cond-> {::primary-key #{primary-key}} updated-pvals (assoc ::primary-value (set updated-pvals)))
new-rows)))
(read-items [this props] (merge-rows props (read-csv filename)))
(archive-items [this props items]
(let [rows (read-csv filename)
new-rows (apply archive rows props items)]
(write-csv! filename new-rows)
{::archived (count new-rows)}))))

0 comments on commit cfd3a69

Please sign in to comment.