Extract datomish.db.debug from test code, in order to use it during development.
This commit is contained in:
parent
9aed24ae39
commit
4a46bdd1bd
2 changed files with 60 additions and 38 deletions
59
src/datomish/db/debug.cljc
Normal file
59
src/datomish/db/debug.cljc
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
(ns datomish.db.debug
|
||||||
|
#?(:cljs
|
||||||
|
(:require-macros
|
||||||
|
[datomish.pair-chan :refer [go-pair <?]]
|
||||||
|
[cljs.core.async.macros :refer [go]]))
|
||||||
|
(:require
|
||||||
|
[datomish.db :as db]
|
||||||
|
[datomish.datom :as dd :refer [datom datom? #?@(:cljs [Datom])]]
|
||||||
|
[datomish.util :as util #?(:cljs :refer-macros :clj :refer) [raise raise-str cond-let]]
|
||||||
|
[datomish.sqlite :as s]
|
||||||
|
#?@(:clj [[datomish.pair-chan :refer [go-pair <?]]
|
||||||
|
[clojure.core.async :as a :refer [chan go <! >!]]])
|
||||||
|
#?@(:cljs [[datomish.pair-chan]
|
||||||
|
[cljs.core.async :as a :refer [chan <! >!]]]))
|
||||||
|
#?(:clj
|
||||||
|
(:import
|
||||||
|
[datomish.datom Datom])))
|
||||||
|
|
||||||
|
(defn <datoms-after [db tx]
|
||||||
|
(go-pair
|
||||||
|
(->>
|
||||||
|
(s/all-rows (:sqlite-connection db) ["SELECT e, a, v, tx FROM datoms WHERE tx > ?" tx])
|
||||||
|
(<?)
|
||||||
|
(mapv #(vector (:e %) (db/ident db (:a %)) (:v %)))
|
||||||
|
(filter #(not (= :db/txInstant (second %))))
|
||||||
|
(set))))
|
||||||
|
|
||||||
|
(defn <datoms [db]
|
||||||
|
(<datoms-after db 0))
|
||||||
|
|
||||||
|
(defn <shallow-entity [db eid]
|
||||||
|
;; TODO: make this actually be <entity. Handle :db.cardinality/many and :db/isComponent.
|
||||||
|
(go-pair
|
||||||
|
(->>
|
||||||
|
(s/all-rows (:sqlite-connection db) ["SELECT a, v FROM datoms WHERE e = ?" eid])
|
||||||
|
(<?)
|
||||||
|
(mapv #(vector (db/ident db (:a %)) (:v %)))
|
||||||
|
(reduce conj {}))))
|
||||||
|
|
||||||
|
(defn <transactions-after [db tx]
|
||||||
|
(go-pair
|
||||||
|
(->>
|
||||||
|
(s/all-rows (:sqlite-connection db) ["SELECT e, a, v, tx, added FROM transactions WHERE tx > ? ORDER BY tx ASC, e, a, v, added" tx])
|
||||||
|
(<?)
|
||||||
|
(mapv #(vector (:e %) (db/ident db (:a %)) (:v %) (:tx %) (:added %))))))
|
||||||
|
|
||||||
|
(defn <transactions [db]
|
||||||
|
(<transactions-after db 0))
|
||||||
|
|
||||||
|
(defn <fulltext-values [db]
|
||||||
|
(go-pair
|
||||||
|
(->>
|
||||||
|
(s/all-rows (:sqlite-connection db) ["SELECT rowid, text FROM fulltext_values"])
|
||||||
|
(<?)
|
||||||
|
(mapv #(vector (:rowid %) (:text %))))))
|
|
@ -10,6 +10,7 @@
|
||||||
[cljs.core.async.macros :as a :refer [go]]))
|
[cljs.core.async.macros :as a :refer [go]]))
|
||||||
(:require
|
(:require
|
||||||
[datomish.api :as d]
|
[datomish.api :as d]
|
||||||
|
[datomish.db.debug :refer [<datoms-after <transactions-after <shallow-entity <fulltext-values]]
|
||||||
[datomish.util :as util #?(:cljs :refer-macros :clj :refer) [raise cond-let]]
|
[datomish.util :as util #?(:cljs :refer-macros :clj :refer) [raise cond-let]]
|
||||||
[datomish.sqlite :as s]
|
[datomish.sqlite :as s]
|
||||||
[datomish.sqlite-schema]
|
[datomish.sqlite-schema]
|
||||||
|
@ -35,44 +36,6 @@
|
||||||
(defn- tempids [tx]
|
(defn- tempids [tx]
|
||||||
(into {} (map (juxt (comp :idx first) second) (:tempids tx))))
|
(into {} (map (juxt (comp :idx first) second) (:tempids tx))))
|
||||||
|
|
||||||
(defn- <datoms-after [db tx]
|
|
||||||
(go-pair
|
|
||||||
(->>
|
|
||||||
(s/all-rows (:sqlite-connection db) ["SELECT e, a, v, tx FROM datoms WHERE tx > ?" tx])
|
|
||||||
(<?)
|
|
||||||
(mapv #(vector (:e %) (d/ident db (:a %)) (:v %)))
|
|
||||||
(filter #(not (= :db/txInstant (second %))))
|
|
||||||
(set))))
|
|
||||||
|
|
||||||
(defn- <datoms [db]
|
|
||||||
(<datoms-after db 0))
|
|
||||||
|
|
||||||
(defn- <shallow-entity [db eid]
|
|
||||||
;; TODO: make this actually be <entity. Handle :db.cardinality/many and :db/isComponent.
|
|
||||||
(go-pair
|
|
||||||
(->>
|
|
||||||
(s/all-rows (:sqlite-connection db) ["SELECT a, v FROM datoms WHERE e = ?" eid])
|
|
||||||
(<?)
|
|
||||||
(mapv #(vector (d/ident db (:a %)) (:v %)))
|
|
||||||
(reduce conj {}))))
|
|
||||||
|
|
||||||
(defn- <transactions-after [db tx]
|
|
||||||
(go-pair
|
|
||||||
(->>
|
|
||||||
(s/all-rows (:sqlite-connection db) ["SELECT e, a, v, tx, added FROM transactions WHERE tx > ? ORDER BY tx ASC, e, a, v, added" tx])
|
|
||||||
(<?)
|
|
||||||
(mapv #(vector (:e %) (d/ident db (:a %)) (:v %) (:tx %) (:added %))))))
|
|
||||||
|
|
||||||
(defn- <transactions [db]
|
|
||||||
(<transactions-after db 0))
|
|
||||||
|
|
||||||
(defn- <fulltext-values [db]
|
|
||||||
(go-pair
|
|
||||||
(->>
|
|
||||||
(s/all-rows (:sqlite-connection db) ["SELECT rowid, text FROM fulltext_values"])
|
|
||||||
(<?)
|
|
||||||
(mapv #(vector (:rowid %) (:text %))))))
|
|
||||||
|
|
||||||
(def test-schema
|
(def test-schema
|
||||||
[{:db/id (d/id-literal :db.part/user)
|
[{:db/id (d/id-literal :db.part/user)
|
||||||
:db/ident :x
|
:db/ident :x
|
||||||
|
|
Loading…
Reference in a new issue