Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

datomic attribute shorthands #1

Open
alidcast opened this issue Apr 12, 2020 · 0 comments
Open

datomic attribute shorthands #1

alidcast opened this issue Apr 12, 2020 · 0 comments
Labels

Comments

@alidcast
Copy link
Owner

alidcast commented Apr 12, 2020

currently we provide a vector shorthand that expands into datomic attribute map

namely, we have the #attr pattern: [ident type cardinality ?(unique | component) ?pred]
*if type is db.type/ref then third index is a db/isComponent boolean otherwise it is a db.unique value.

examples:
-#attr [:user/username :db.type/string :db.cardinality/one :db.unique/identity]
-#attr [:note/owner :db.type/ref :db.cardinality/one true]

This works great because the majority of attributes require an ident, type, and cardinality so it's easy to pick up on the pattern, and for other cases we provide other reader literal shorthands (i.e. #ent, and #spec.)

Note, I also considered providing shorthands for the :db value forms but every alternative considered loses semantic meaning. i.e. the keyword :one is less semantically meaningful than :cardinality/one and we can't just do :cardinality/one because that implies it is a non-namespaced attribute, which it's not.

Of the fourth alternatives below (fourth one being default datomic attribute map), the third variation offers succinctness without losing important meaning.
-#attr [:user/username :string]
-#attr [:user/username :type/string cardinality/one]
-#attr [:user/username :db.type/string :db.cardinality/one]
-{:db/ident :user/username :db/type :db.type/string :db/cardinality :db.cardinality/one}

One alternative that would have been great is if namespaced keywords were allowed in EDN files, i.e. ::type.one could be expanded into db.type/one but unfortunately that's not allowed so for now we'll stick with fully specifying datomic attribute values.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant