Skip to content

Instantly share code, notes, and snippets.

@rodnaph
Last active December 18, 2015 00:09
Show Gist options
  • Save rodnaph/5694439 to your computer and use it in GitHub Desktop.
Save rodnaph/5694439 to your computer and use it in GitHub Desktop.
Datomic attribute schema fn with sane defaults.
(ns foo.schema
(:require [datomic.api :refer [tempid]]))
;; Datomic schema is wordy, so apply some sane defaults and allow overriding where needed.
(defn- attribute [ident & options]
(let [defaults {:db/id (tempid :db.part/db)
:db/ident ident
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db.install/_attribute :db.part/db}]
(merge defaults
(apply hash-map options))))
;; The minimum you can provide is just an attribute name...
(attribute :user/name)
;; Then you can customize other attributes as required, for
;; example setting a custom data type...
(attribute :user/age
:db/valueType :db.type/long)
;; And all other attributes as well of course...
(attribute :user/friends
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment