We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 34fd08c commit 3f6c600Copy full SHA for 3f6c600
src/xitdb/snapshot.clj
@@ -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