Skip to content

Instantly share code, notes, and snippets.

@ekroon
Created May 2, 2014 08:35
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 ekroon/9f9c52f69d708b8e5f5f to your computer and use it in GitHub Desktop.
Save ekroon/9f9c52f69d708b8e5f5f to your computer and use it in GitHub Desktop.
Datomic db functions
{: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