2015-09-01 128 views
0

我試圖將屬性添加到現有datomic模式,用新的屬性是添加屬性到現有datomic架構

{: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} 

,當我嘗試提交它作爲一個交易(如在http://docs.datomic.com/schema.html描述)與以下

(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)) 

我得到一個錯誤,我沒有:在我的查詢find子句。

我應該如何提交此事務才能將屬性添加到我的數據庫數據庫模式?

回答

6

您的代碼無法正常工作,因爲您使用了錯誤的功能。

您想使用transactSee 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

爲了更容易地創建屬性並使用其他Datomic功能,您不妨嘗試the Tupelo Datomic library。它可以讓你創建這樣的屬性:

(: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 

在你的情況,這將簡化爲

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