;; 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]))) ;; TODO: implement support for DB parts? (def tx0 0x2000000) (defn (integer entid), like {:db/ident 0}." (let [<-SQLite (get-in ds/value-type-map [:db.type/keyword :<-SQLite])] ;; TODO: make this a protocol. (go-pair (let [rows (> {:select [:ident :entid] :from [:idents]} (s/format) (s/all-rows sqlite-connection)))] (into {} (map (fn [row] [(<-SQLite (:ident row)) (:entid row)])) rows))))) (defn (map (keyword attribute -> keyword value)), like {:db/ident {:db/cardinality :db.cardinality/one}}." (let [<-SQLite (get-in ds/value-type-map [:db.type/keyword :<-SQLite])] ;; TODO: make this a protocol. (go-pair (->> (->> {:select [:ident :attr :value] :from [:schema]} (s/format) (s/all-rows sqlite-connection)) (= current-tx 0) current-tx (max current-tx tx0)] (when-not bootstrapped ;; We need to bootstrap the DB. (let [fail-alter-ident (fn [old new] (if-not (= old new) (raise "Altering idents is not yet supported, got " new " altering existing ident " old {:error :schema/alter-idents :old old :new new}) new)) fail-alter-attr (fn [old new] (if-not (= old new) (raise "Altering schema attributes is not yet supported, got " new " altering existing schema attribute " old {:error :schema/alter-schema :old old :new new}) new))] (-> (db/map->DB {:sqlite-connection sqlite-connection :idents bootstrap/idents :symbolic-schema bootstrap/symbolic-schema :schema (ds/schema (into {} (map (fn [[k v]] [(k bootstrap/idents) v]) bootstrap/symbolic-schema))) ;; TODO: fail if ident missing. :current-tx current-tx}) ;; We use DB {:sqlite-connection sqlite-connection :idents idents :symbolic-schema symbolic-schema :schema (ds/schema (into {} (map (fn [[k v]] [(k idents) v]) symbolic-schema))) ;; TODO: fail if ident missing. :current-tx (inc current-tx)})))))