Skip to content

Instantly share code, notes, and snippets.

View robert-stuttaford's full-sized avatar
💭
Clojure!

Robert Stuttaford robert-stuttaford

💭
Clojure!
View GitHub Profile
Check out README.md to get started editing Clojure with Emacs.
@robert-stuttaford
robert-stuttaford / web-session-tx-fn.clj
Created July 3, 2013 11:33
using database functions to avoid race conditions between multiple webservers
(defn start-session!
[]
;; put-value! talks to ring's sessions dsl
(put-value! :session-uuid (db/new-uuid)))
(defn uuid
[]
;; get-value talks to ring's sessions dsl
(get-value :session-uuid))
@robert-stuttaford
robert-stuttaford / with.clj
Last active December 19, 2015 07:09
Using Datomic's d/with to query a database as though some transaction had been committed, before actually committing it!
(def conn (d/conn some-uri))
(def some-id 12345)
(defn get-v [db] (ffirst (d/q '[:find ?v :in $ ?e :where [?e :some/attribute ?v]] db some-id)))
(get-v (d/db conn))
;; => :some-value
(def tx [[:db/retract some-id :some/attribute :some-value]
@robert-stuttaford
robert-stuttaford / README.md
Last active December 16, 2015 05:08
Cognician's new architecture with Clojure and Datomic: Notes