2015-09-01 32 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))