;; 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-factory #?(:cljs (:require-macros [datomish.pair-chan :refer [go-pair !]]]) #?@(:cljs [[datomish.pair-chan] [cljs.core.async :as a :refer [chan !]]])) #?(:clj (:import [datomish.datom Datom]))) (defn (integer entid), like {:db/ident 0}." (go-pair (let [rows (> {:select [:ident :entid] :from [:idents]} (s/format) (s/all-rows sqlite-connection)))] (into {} (map (fn [row] [(sqlite-schema/<-SQLite :db.type/keyword (:ident row)) (:entid row)])) rows)))) (defn {:start integer :idx integer}, like {:db.part/user {start: 0x100 idx: 0x101}}." (go-pair (let [rows (> {:select [:part :start :idx] :from [:parts]} (s/format) (s/all-rows sqlite-connection)))] (into {} (map (fn [row] [(sqlite-schema/<-SQLite :db.type/keyword (:part row)) (select-keys row [:start :idx])])) rows)))) (defn (map (keyword attribute -> keyword value)), like {:db/ident {:db/cardinality :db.cardinality/one}}." (go-pair (->> (->> {:select [:ident :attr :value] :from [:schema]} (s/format) (s/all-rows sqlite-connection)) (vector (fn [[part {:keys [start idx]}]] [(sqlite-schema/->SQLite part) start idx])] ;; TODO: allow inserting new parts. ;; TODO: think more carefully about allocating new parts and bitmasking part ranges. ;; TODO: install these using bootstrap assertions. It's tricky because the part ranges are implicit. ;; TODO: chunk into 999/3 sections, for safety. (vector bootstrap/parts))))) (-> db ;; We use