本文介绍了“无读取器功能”光表中使用Datomic的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在lighttable中评估此代码时:

 (ns app.core 
(:require [datomic。 api:refer [q]:as d]
:reload-all))

(defn add-person
[conn id]
[{:db / id#db / id [:db.part / user -1000001]
:person / id id}]))

我得到:

  clojure.lang.ExceptionInfo: id 
core.clj:4327 clojure.core / ex-info

本教程归于和:

 (使用:reload'datomic.samples.repl)
(easy!)
(def conn(scratch-conn))
b $ b ;;在数据中,为温度使用数据文本
(def tx-data [{:db / id#db / id [:db.part / user]
:db / docExample 1}]
(transact conn tx-data)

;;在代码中,调用tempid创建tempids
(let [id(tempid:db.part / user)
docExample 2]
(transact conn [{:db / id id: db / doc doc}]))

;;相同的参数适用于函数:
;;在数据中使用#db / fn字面值
;;在代码中使用Peer.function或d / function

;;破坏,在代码中使用db / fn文本
(transact conn [{:db / id#db / id [:db.part / user]
:db / ident:hello
:db / fn#db / fn {:langclojure
:params []
:code'(println:hello)}}])

;修正:使用d /函数构造函数
(transact conn [{:db / id(d / tempid:db.part / user)
:db / ident:hello
:db / fn(d / function {:langclojure
:params []
:code'(println:hello)})}])
(d / invoke )


When I eval this code in lighttable:

(ns app.core
  (:require [datomic.api :refer [q] :as d]
            :reload-all))

(defn add-person
  [conn id]
  (d/transact conn [{:db/id #db/id[:db.part/user -1000001]
                     :person/id id}]))

I get:

clojure.lang.ExceptionInfo: No reader function for tag id
core.clj:4327 clojure.core/ex-info

Anyone knows what is going on?

解决方案

This tutorial is attributed to stuart halloway and Bobby Calderwood:

(use :reload 'datomic.samples.repl)
(easy!)
(def conn (scratch-conn))

;; in data, use data literals for tempids
(def tx-data [{:db/id #db/id[:db.part/user]
               :db/doc "Example 1"}])
(transact conn tx-data)

;; in code, call tempid to create tempids
(let [id (tempid :db.part/user)
      doc "Example 2"]
  (transact conn [{:db/id id :db/doc doc}]))

;; same argument applies to functions:
;; use #db/fn literals in data
;; use Peer.function or d/function in code

;; broken, uses db/fn literal in code
(transact conn [{:db/id #db/id [:db.part/user]
                 :db/ident :hello
                 :db/fn #db/fn {:lang "clojure"
                                :params []
                                :code '(println :hello)}}])

;; corrected: used d/function to construct function
(transact conn [{:db/id (d/tempid :db.part/user)
                 :db/ident :hello
                 :db/fn (d/function {:lang "clojure"
                                     :params []
                                     :code '(println :hello)})}])
(d/invoke (db conn) :hello)

Source: https://github.com/Datomic/day-of-datomic/blob/master/samples/literals_vs_code.clj

这篇关于“无读取器功能”光表中使用Datomic的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 11:14