Clojure Datomic教程“重温过去”部分的问题
在重温过去一节中,我对datomic教程有问题 对于以下两个查询:Clojure Datomic教程“重温过去”部分的问题,clojure,datomic,Clojure,Datomic,在重温过去一节中,我对datomic教程有问题 对于以下两个查询: query = "[:find ?c :where [?c :community/name]]"; db_asOf_schema = conn.db().asOf(schema_tx_date); System.out.println(Peer.q(query, db_asOf_schema).size()); // 0 db_since_data = conn.db().since(data_tx_date); System
query = "[:find ?c :where [?c :community/name]]";
db_asOf_schema = conn.db().asOf(schema_tx_date);
System.out.println(Peer.q(query, db_asOf_schema).size()); // 0
db_since_data = conn.db().since(data_tx_date);
System.out.println(Peer.q(query, db_since_data).size()); // 0
我曾在clojure中尝试过这些命令,但无法使它们按照教程中所述工作:
(since (db conn) (java.util.Date.) )
;; It should return 0 but returns the whole database instead
(def ts (q '[:find ?when :where [?tx :db/txInstant ?when]] (db conn)))
(count (since (db conn) (ffirst (reverse (sort ts))))))
;; returns 13, but should return 0
(count (as-of (db conn) (ffirst (sort ts)))))
;; returns 13, but should return 0
我不太确定这是不是正确的行为,我有什么做错了吗?如果您正在学习Clojure的西雅图教程,可能需要知道的最重要的一件事是,Clojure代码包含在Datomic发行版中。文件名是samples/seattle/getting-started.clj,您只需在REPL上查看即可 在您的问题中,对Clojure代码的两个观察结果: 因为函数被记录为返回一个数据库值,而不是一个数字,所以您看到的行为与预期的一样。为了查看数据库中的内容,需要发出查询 数据库没有Clojure count函数的任何文档化语义,因此不应该对其调用count。同样,如果您想查看数据库中的内容,则需要发出查询,例如
;; Find all transaction times, sort them in reverse order
(def tx-instants (reverse (sort (q '[:find ?when :where [_ :db/txInstant ?when]]
(db conn)))))
;; pull out two most recent transactions, most recent loaded
;; seed data, second most recent loaded schema
(def data-tx-date (ffirst tx-instants))
(def schema-tx-date (first (second tx-instants)))
;; make query to find all communities
(def communities-query '[:find ?c :where [?c :community/name]])
;; find all communities as of schema transaction
(let [db-asof-schema (-> conn db (d/as-of schema-tx-date))]
(println (count (seq (q communities-query db-asof-schema)))))
;; find all communities as of seed data transaction
(let [db-asof-data (-> conn db (d/as-of data-tx-date))]
(println (count (seq (q communities-query db-asof-data)))))
;; find all communities since seed data transaction
(let [db-since-data (-> conn db (d/since data-tx-date))]
(println (count (seq (q communities-query db-since-data)))))
希望这有帮助。如果您有更多问题,还有一个问题 如果您正在学习Clojure的西雅图教程,可能需要知道的最重要的一件事是,Clojure代码包含在Datomic发行版中。文件名是samples/seattle/getting-started.clj,您只需在REPL上查看即可 在您的问题中,对Clojure代码的两个观察结果: 因为函数被记录为返回一个数据库值,而不是一个数字,所以您看到的行为与预期的一样。为了查看数据库中的内容,需要发出查询 数据库没有Clojure count函数的任何文档化语义,因此不应该对其调用count。同样,如果您想查看数据库中的内容,则需要发出查询,例如
;; Find all transaction times, sort them in reverse order
(def tx-instants (reverse (sort (q '[:find ?when :where [_ :db/txInstant ?when]]
(db conn)))))
;; pull out two most recent transactions, most recent loaded
;; seed data, second most recent loaded schema
(def data-tx-date (ffirst tx-instants))
(def schema-tx-date (first (second tx-instants)))
;; make query to find all communities
(def communities-query '[:find ?c :where [?c :community/name]])
;; find all communities as of schema transaction
(let [db-asof-schema (-> conn db (d/as-of schema-tx-date))]
(println (count (seq (q communities-query db-asof-schema)))))
;; find all communities as of seed data transaction
(let [db-asof-data (-> conn db (d/as-of data-tx-date))]
(println (count (seq (q communities-query db-asof-data)))))
;; find all communities since seed data transaction
(let [db-since-data (-> conn db (d/since data-tx-date))]
(println (count (seq (q communities-query db-since-data)))))
希望这有帮助。如果您有更多问题,还有一个问题 我试着加入!但那是一个封闭的团体,我没有被允许进去。。因此,我在stack overflow上发布了3个问题。感谢您的指导!我想知道为什么该网站是面向java用户的,但却只有很少的clojure编码示例。在clojure API部分的某个地方应该有一个链接或一个非常大的标题。。。很抱歉加入这个团体遇到了麻烦-我没有看到我这方面的记录。如果你在datomic.com上直接给我发邮件,我会直接给你发一个团体邀请。我试着加入了!但那是一个封闭的团体,我没有被允许进去。。因此,我在stack overflow上发布了3个问题。感谢您的指导!我想知道为什么该网站是面向java用户的,但却只有很少的clojure编码示例。在clojure API部分的某个地方应该有一个链接或一个非常大的标题。。。很抱歉加入这个团体遇到了麻烦-我没有看到我这方面的记录。如果你直接在datomic.com上用你的电子邮件地址给我打电话,我会直接给你发送一个团体邀请。