Last active
July 22, 2018 08:20
-
-
Save cbillowes/b1ebd2fbc1acff1f3d7c7dbec09f7e12 to your computer and use it in GitHub Desktop.
Nifty Snippets
This file contains 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
; https://stackoverflow.com/questions/36032562/extract-values-from-vector-of-maps-conditionally-in-clojure | |
(map val (filter (comp #{:a} key) (apply concat vector-of-maps))) | |
; Grab URL from JavaScript window API | |
(ns awesome.stuff.to.learn | |
(:require [cemerick.url :as url])) | |
(defn [] (:anchor (url/url (-> js/window .-location .-href)))) | |
; (compare-and-swap) function takes four arguments: an entity id, an attribute, an old value, and a new value. | |
; htps://docs.datomic.com/on-prem/transactions.html#dbfn-cas | |
(defn update-entity | |
[params] | |
(let [conn awesome.db.datomic/conn | |
db (d/db conn) | |
entity-id (Long/parseLong (:entity-id params)) | |
entity (get-entity db entity-id)] | |
{:db-after @(d/transact conn | |
[[:db.fn/cas (:id entity) :entity/name (:name entity) (:entity-name params)] | |
[:db.fn/cas (:user-id entity) :user/email (:user-email entity) (:user-email params)]])})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment