0
votes

I'm attempting to add an attribute to an existing datomic schema, with the new attribute being

  {:db/id #db/id[:db.part/db]
  :db/ident :user-deets/enriched
  :db/valueType :db.type/boolean
  :db/cardinality :db.cardinality/one
  :db.install/_attribute :db.part/db}

and when I try to submit it as a transaction (as described at http://docs.datomic.com/schema.html) with the following

(datomic/query '[{:db/id #db/id[:db.part/db]
      :db/ident :user-deets/enriched
      :db/valueType :db.type/boolean
      :db/cardinality :db.cardinality/one
      :db.install/_attribute :db.part/db}] (database/get-db))

I get an error that I don't have a :find clause in my query.

How should I be submitting this transaction in order to add the attribute to my datomic databases schema?

2

2 Answers

6
votes

Your code isn't working because you're using the wrong function.

You want to use transact See doc.

(datomic/transact connection [{:db/id #db/id[:db.part/db]
  :db/ident :user-deets/enriched
  :db/valueType :db.type/boolean
  :db/cardinality :db.cardinality/one
  :db.install/_attribute :db.part/db}])
-1
votes

For an even easier time creating attributes and using other Datomic features, you may wish to try the Tupelo Datomic library. It will allow you to create attributes like this:

(:require [tupelo.datomic :as td])

  ; Create some new attributes. Required args are the attribute name (an optionally namespaced
  ; keyword) and the attribute type (full listing at http://docs.datomic.com/schema.html). We wrap
  ; the new attribute definitions in a transaction and immediately commit them into the DB.
  (td/transact *conn* ;   required              required              zero-or-more
                      ;  <attr name>         <attr value type>       <optional specs ...>
    (td/new-attribute   :person/name         :db.type/string         :db.unique/value)      ; each name      is unique
    (td/new-attribute   :person/secret-id    :db.type/long           :db.unique/value)      ; each secret-id is unique
    (td/new-attribute   :weapon/type         :db.type/ref            :db.cardinality/many)  ; one may have many weapons
    (td/new-attribute   :location            :db.type/string)     ; all default values
    (td/new-attribute   :favorite-weapon     :db.type/keyword ))  ; all default values

In your case, this would simplify to

(td/transact (database/get-db)
  (td/new-attribute :user-deets/enriched :db.type/boolean))