我正在尝试将属性添加到现有的数据库模式,新属性为
{: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子句。
如何将此事务提交到我的数据库数据库模式?
答案 0 :(得分:6)
您的代码无效,因为您使用了错误的功能。
您想使用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 :(得分:-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))