Last active
June 4, 2016 21:14
-
-
Save dball/e56f4a9c374d2d46073403f30c07d055 to your computer and use it in GitHub Desktop.
Protocol Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defprotocol UserStore | |
(load [_ id]) | |
(save! [_ id user]) | |
(delete! [_ id])) | |
(defrecord Database [db] | |
UserStore | |
(load [_ id] | |
(first (jdbc/query db ["select * from users where id = ?" id]))) | |
...) | |
(defn build-memory-user-store | |
[] | |
(let [state (atom {})] | |
(reify UserStore | |
(load [_ id] (get @state id)) | |
...))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment