Skip to content

Instantly share code, notes, and snippets.

@baritonehands
Last active January 21, 2016 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baritonehands/b75dc69242948308ff3d to your computer and use it in GitHub Desktop.
Save baritonehands/b75dc69242948308ff3d to your computer and use it in GitHub Desktop.
(defprotocol CRUD
(create [this entity])
(get [this id])
(save [this id updates])
(delete [this id]))
(defn create-db []
(let [db (ref {})]
(reify CRUD
(create [_ entity]
(let [id (str (java.util.UUID/randomUUID))]
(dosync (alter db assoc id (assoc entity :id id)))
entity))
(get [_ id]
(@db id))
(save [_ id updates]
(dosync (alter db update-in [id] merge updates)))
(delete [_ id]
(dosync (dissoc db id))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment