diff --git a/src-browser/datomish/js_sqlite.cljs b/src-browser/datomish/js_sqlite.cljs new file mode 100644 index 00000000..095652e3 --- /dev/null +++ b/src-browser/datomish/js_sqlite.cljs @@ -0,0 +1,20 @@ +;; 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.js-sqlite + (:require + [datomish.sqlite :as s] + [datomish.js-util :refer [is-node?]] + [datomish.sqlitejsm-sqlite :as sqlitejsm-sqlite])) + +(def open sqlitejsm-sqlite/open) + +(extend-protocol s/ISQLiteConnectionFactory + string + (js (name k)))) + not-found))) + +(defrecord SQLite3Connection [db] + s/ISQLiteConnection + (-execute! + [db sql bindings] + (cljs-promises.async/pair-port + (.execute (.-db db) sql (or (clj->js bindings) #js [])))) + + (-each + [db sql bindings row-cb] + (let [cb (fn [row] + (row-cb (StorageRow. row)))] + (cljs-promises.async/pair-port + (.execute (.-db db) sql (or (clj->js bindings) #js []) (when row-cb cb))))) + + (close + [db] + (cljs-promises.async/pair-port + (.close (.-db db))))) + +(defn open + [path & {:keys [mode] :or {mode 6}}] + (cljs-promises.async/pair-port + (-> + (.openConnection (aget sqlite "Sqlite") (clj->js {:path path :sharedMemoryCache false})) + (.then ->SQLite3Connection))))