SWiss ARmy Knife - Your everyday clojure toolbelt!
This library contains functionality that you might need every single day as a happy clojure(script) developer.
The aim is to provide composable functions that you can use everyday, but are just not as trivial as (some (comp #{42} :answer) answers)
.
All functionality should work in both Clojure and Clojurescript.
Add this dependency to the :deps map in deps.edn:
org.clojars.stanv/swark {:mvn/version "0.1.4"}
Require swark.core in your ns form:
(:require [swark.core :as swark])
Then you can use the Swark utility functions:
(swark/key-by :id [{:id 1 :name "one"} {:id 2 :name "two"}])
Let's say you want to store a user record, some credentials and check their credentials. You can use swark.cedric for the persistence part, and swark.authom for the authentication part.
(ns my.ns
(:require [swark.authom :as authom]
[swark.cedric :as cedric]))
(def DB (cedric/Csv. "db.csv"))
(def PROPS (merge authom/CEDRIC-PROPS {:primary-key :user/id}))
cedric/upsert-items
:(def USER (-> DB (cedric/upsert-items PROPS [{:user/name "Readme User"}]) first))
authom/with-token
) by upserting the user with cedric/upsert-items
(let [user (authom/with-token USER :user/id "pass" "SECRET")]
(cedric/upsert-items DB PROPS [user]))
cedric/read-items
and check their credentials with authom/check
:(let [user (-> DB (cedric/read-items {::cedric/primary-key #{:user/id}}) first)]
(-> user (authom/check :user/id "pass" "SECRET") assert))
Run the tests with clojure -X:test/run
Start a repl with clojure -M:repl/reloaded
Install Swark locally with clj -X:install
Create an uberjar with clj -X:uberjar :jar swark-0.1.4.jar
Swark by Stan Verberkt is marked with CC0 1.0 Universal
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close