Skip to content

Commit 3f6c600

Browse files
committed
Snapshotting
1 parent 34fd08c commit 3f6c600

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/xitdb/snapshot.clj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
(ns xitdb.snapshot
2+
(:require [xitdb.db :as xdb])
3+
(:import [java.io File]))
4+
5+
(defn xit-db-existing [filename]
6+
(when-not (or (= filename :memory) (.exists (File. ^String filename)))
7+
(throw (IllegalArgumentException. "Database file does not exist")))
8+
(xdb/xit-db filename))
9+
10+
(defn snapshot-memory-db
11+
"Returns a memory database with the value of `keypath` in the database at `filename`
12+
When keypath is [], returns a memdb with all the data in the db `filename`.
13+
Useful for REPL-based investigation and testing."
14+
[filename keypath]
15+
(with-open [db (xit-db-existing filename)]
16+
(let [memdb (xdb/xit-db :memory)]
17+
(reset! memdb (get-in @db keypath))
18+
memdb)))

0 commit comments

Comments
 (0)