Review comment: use datomish.api where possible.

This commit is contained in:
Richard Newman 2016-10-05 14:06:36 -07:00
parent ce67644fd5
commit 61757e271c

View file

@ -12,6 +12,7 @@
[cljs.reader]
[cljs-promises.core :refer [promise]]
[datomish.cljify :refer [cljify]]
[datomish.api :as d]
[datomish.db :as db]
[datomish.db-factory :as db-factory]
[datomish.pair-chan]
@ -24,14 +25,13 @@
;; Public API.
(defn ^:export db [conn]
(transact/db conn))
(def ^:export db d/db)
(defn ^:export q [db find options]
(let [find (cljs.reader/read-string find)
opts (cljify options)]
(take-pair-as-promise!
(db/<?q db find opts)
(d/<q db find opts)
clj->js)))
(defn ^:export ensure-schema [conn simple-schema]
@ -39,7 +39,7 @@
datoms (simple-schema/simple-schema->schema simple-schema)]
(println "Transacting schema datoms" (pr-str datoms))
(take-pair-as-promise!
(transact/<transact!
(d/<transact!
conn
datoms)
clj->js)))
@ -52,9 +52,8 @@
;; Expects a JS array as input.
(try
(let [tx-data (js->tx-data tx-data)]
(println "Transacting:" (pr-str tx-data))
(go-promise clj->js
(let [tx-result (<? (transact/<transact! conn tx-data))]
(let [tx-result (<? (d/<transact! conn tx-data))]
(select-keys tx-result
[:tempids
:added-idents
@ -73,13 +72,13 @@
;; We pickle the connection as a thunk here so it roundtrips through JS
;; without incident.
{:conn (fn [] c)
:db (fn [] (transact/db c))
:db (fn [] (d/db c))
:path path
;; Primary API.
:ensureSchema (fn [simple-schema] (ensure-schema c simple-schema))
:transact (fn [tx-data] (transact c tx-data))
:q (fn [find opts] (q (transact/db c) find opts))
:q (fn [find opts] (q (d/db c) find opts))
:close (fn [] (db/close-db db))
;; Some helpers for testing the bridge.