首页 文章

将属性添加到现有的datomic架构

提问于
浏览
0

我正在尝试将属性添加到现有的数据库模式,新属性为

{: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子句 .

我应该如何提交此事务以将属性添加到我的数据库数据库模式?

2 回答

  • -1

    您的代码无效,因为您使用了错误的功能 .

    你想使用 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}])
    
  • 6

    为了更轻松地创建属性和使用其他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))
    

相关问题