611d44fcce
This uses a common table expression and multiple SQL calls rather than a temporary table, since transactions with huge numbers of distinct lookup-refs are likely to be very rare. We mark lookup-refs with `lookup-ref`, which is a little awkward because binding `(let [[a v] lookup-ref] ...)` doesn't directly work, but avoids some ambiguity present in Datomic and DataScript around interpreting lookup-refs as multiple value lists. (Which bit the tests in an earlier version of this patch!)
45 lines
1.3 KiB
Clojure
45 lines
1.3 KiB
Clojure
;; 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.api
|
|
#?(:cljs
|
|
(:require-macros
|
|
[datomish.pair-chan :refer [go-pair <?]]
|
|
[cljs.core.async.macros :as a :refer [go]]))
|
|
(:require
|
|
[datomish.db :as db]
|
|
[datomish.db-factory :as db-factory]
|
|
[datomish.sqlite :as sqlite]
|
|
[datomish.transact :as transact]
|
|
#?@(:clj [[datomish.pair-chan :refer [go-pair <?]]
|
|
[clojure.core.async :refer [go <! >!]]])
|
|
#?@(:cljs [[datomish.pair-chan]
|
|
[cljs.core.async :as a :refer [<! >!]]])))
|
|
|
|
(defn <connect [uri]
|
|
;; Eventually, URI. For now, just a plain path (no file://).
|
|
(go-pair
|
|
(let [conn (<? (sqlite/<sqlite-connection uri))
|
|
db (<? (db-factory/<db-with-sqlite-connection conn))]
|
|
(transact/connection-with-db db))))
|
|
|
|
(def <transact! transact/<transact!)
|
|
|
|
;; TODO: use Potemkin, or a subset of Potemkin that is CLJS friendly (like
|
|
;; https://github.com/ztellman/potemkin/issues/31) to improve this re-exporting process.
|
|
(def <close transact/close)
|
|
|
|
(def id-literal db/id-literal)
|
|
|
|
(def lookup-ref db/lookup-ref)
|
|
|
|
(def db transact/db)
|
|
|
|
(def entid db/entid)
|
|
|
|
(def ident db/ident)
|
|
|
|
(def <q db/<?q)
|
|
|
|
(def schema db/schema)
|