Skip to content

Commit

Permalink
Update readme to instruct about csv usage with async transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
verberktstan committed Feb 27, 2024
1 parent 453ba45 commit 264cb0e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ You can use swark.cedric for the persistence part, and swark.authom for the auth
```
(ns my.ns
(:require [swark.authom :as authom]
[swark.cedric :as cedric])
[swark.cedric :as cedric]
[swark.core :as swark])
(:import [swark.cedric Csv]))
(def DB (cedric/Csv. "db.csv"))
(def DB (cedric/Csv. "/tmp/db.csv"))
(def PROPS (merge authom/CEDRIC-PROPS {:primary-key :user/id}))
```

Expand All @@ -82,6 +83,15 @@ You can use swark.cedric for the persistence part, and swark.authom for the auth
(-> user (authom/check :user/id "pass" "SECRET") assert))
```

5. Since the csv file might change in the mean while, it is advised to execute all db actions as an asynchronous transaction. You can make use of `with-buffer` & `put!` like so:
```
(let [db-connection (swark/with-buffer! (cedric/Csv. "/tmp/db.csv"))
transact! (partial swark/put! db-connection)]
(transact! cedric/upsert-items {:primary-key :id} [{:test "data"} {:more "testdata" :something 123}]) ; Returns the upserted items.
(transact! cedric/read-items {}) ; Returns all items read.
(swark/close! db-connection)) ; Don't forget to close the async connection.
```

## Tests

Run the tests with `clojure -X:test/run`
Expand Down
2 changes: 1 addition & 1 deletion src/swark/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@

;; TODO: Add tests
(defn with-retries
{:added "0.1.41" ; NOTE: To be released!
{:added "0.1.41"
:arglist '([n f & args])
:doc "Returns the result of (apply f args) after running it n times. When
something is thrown on the last try, returns the throwable map."}
Expand Down

0 comments on commit 264cb0e

Please sign in to comment.