将多个常规属性/值插入到datomic db

时间:2015-03-03 19:14:40

标签: clojure insert datomic

到目前为止,我的add-post-to-datomic方法看起来像

(defn add-post-to-datomic [title, content, useremail]
  (d/transact conn [{:db/id (d/tempid :db.part/user),
                     :post/title title,
                     :post/content content,
                     :author/email useremail}]))

我真的想添加添加潜在可变数量标签的功能。

在我的awesome-schema.edn中我有

{:db/id #db/id[:db.part/db]
 :db/ident :post/tag
 :db/valueType :db.type/string
 :db/cardinality :db.cardinality/many
 :db/doc "tag applied to a post"
 :db.install/_attribute :db.part/db}

因为基数设置为很多,所以如果数据库中存在多个,那就没问题了。

如何编写上述方法以适用于可变数量的标签?

1 个答案:

答案 0 :(得分:2)

查看“Cardinality many transactions”下的Transactions Docs。只要你传递一组标签,这应该有效:

(defn add-post-to-datomic [title content user-email tag-set]
  (d/transact conn [{:db/id (d/tempid :db.part/user)
                     :post/title title
                     :post/content content
                     :post/tag tag-set
                     :author/email user-email}]))