Created
May 2, 2014 08:35
-
-
Save ekroon/9f9c52f69d708b8e5f5f to your computer and use it in GitHub Desktop.
Datomic db functions
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
{:db/id #db/id [:db.part/user] | |
:db/ident :generate-number | |
:db/fn #db/fn {:lang "clojure" | |
:params [db | |
counter-e counter-a | |
prefix | |
target-e target-a] | |
:code (let [current (or (ffirst (q '[:find ?v | |
:in $ ?e ?a | |
:where [?e ?a ?v]] | |
db counter-e counter-a)) | |
1)] | |
[[:db/add counter-e counter-a (inc current)] | |
[:db/add target-e target-a | |
(str prefix | |
(format "%07d" current))]])}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment