|
393 | 393 | (declare hash-db hash-fdb equiv-db empty-db resolve-datom validate-attr components->pattern indexing?) |
394 | 394 | #?(:cljs (declare pr-db)) |
395 | 395 |
|
| 396 | +(defn db-transient [db] |
| 397 | + (-> db |
| 398 | + (update :eavt transient) |
| 399 | + (update :aevt transient) |
| 400 | + (update :avet transient))) |
| 401 | + |
| 402 | +(defn db-persistent! [db] |
| 403 | + (-> db |
| 404 | + (update :eavt persistent!) |
| 405 | + (update :aevt persistent!) |
| 406 | + (update :avet persistent!))) |
| 407 | + |
396 | 408 | (defrecord-updatable DB [schema eavt aevt avet max-eid max-tx rschema hash] |
397 | 409 | #?@(:cljs |
398 | 410 | [IHash (-hash [db] (hash-db db)) |
|
401 | 413 | IReversible (-rseq [db] (-rseq (.-eavt db))) |
402 | 414 | ICounted (-count [db] (count (.-eavt db))) |
403 | 415 | IEmptyableCollection (-empty [db] (empty-db (.-schema db))) |
404 | | - IPrintWithWriter (-pr-writer [db w opts] (pr-db db w opts))] |
| 416 | + IPrintWithWriter (-pr-writer [db w opts] (pr-db db w opts)) |
| 417 | + IEditableCollection (-as-transient [db] (db-transient db)) |
| 418 | + ITransientCollection (-conj! [db key] (throw (ex-info "datascript.DB/conj! is not supported" {}))) |
| 419 | + (-persistent! [db] (db-persistent! db))] |
405 | 420 |
|
406 | 421 | :clj |
407 | 422 | [Object (hashCode [db] (hash-db db)) |
|
410 | 425 | clojure.lang.IPersistentCollection |
411 | 426 | (count [db] (count eavt)) |
412 | 427 | (equiv [db other] (equiv-db db other)) |
413 | | - (empty [db] (empty-db schema))]) |
| 428 | + (empty [db] (empty-db schema)) |
| 429 | + clojure.lang.IEditableCollection |
| 430 | + (asTransient [db] (db-transient db)) |
| 431 | + clojure.lang.ITransientCollection |
| 432 | + (conj [db key] (throw (ex-info "datascript.DB/conj! is not supported" {}))) |
| 433 | + (persistent [db] (db-persistent! db))]) |
414 | 434 |
|
415 | 435 | IDB |
416 | 436 | (-schema [db] (.-schema db)) |
|
1106 | 1126 | (sequential? initial-es)) |
1107 | 1127 | (raise "Bad transaction data " initial-es ", expected sequential collection" |
1108 | 1128 | {:error :transact/syntax, :tx-data initial-es})) |
1109 | | - (loop [report initial-report |
| 1129 | + (loop [report (-> initial-report |
| 1130 | + (update :db-after transient)) |
1110 | 1131 | es initial-es] |
1111 | 1132 | (let [[entity & entities] es |
1112 | | - db (:db-after report) |
1113 | | - {:keys [tempids]} report] |
| 1133 | + db (:db-after report) |
| 1134 | + {:keys [tempids]} report] |
1114 | 1135 | (cond |
1115 | 1136 | (empty? es) |
1116 | 1137 | (-> report |
1117 | 1138 | (assoc-in [:tempids :db/current-tx] (current-tx report)) |
1118 | | - (update-in [:db-after :max-tx] inc)) |
| 1139 | + (update-in [:db-after :max-tx] inc) |
| 1140 | + (update :db-after persistent!)) |
1119 | 1141 |
|
1120 | 1142 | (nil? entity) |
1121 | 1143 | (recur report entities) |
|
0 commit comments