Last active
December 18, 2015 00:09
-
-
Save rodnaph/5694439 to your computer and use it in GitHub Desktop.
Datomic attribute schema fn with sane defaults.
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
(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