Skip to content

Commit 2c6bbac

Browse files
committed
Cursors on cursors
1 parent 34f3fa2 commit 2c6bbac

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/xitdb/db.clj

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@
180180
(->XITDBDatabase tldb rwdb (ReentrantLock.)))))
181181

182182

183-
184183
(deftype XITDBCursor [xdb keypath]
185184

186185
java.io.Closeable
@@ -194,7 +193,7 @@
194193
clojure.lang.IAtom
195194

196195
(reset [this new-value]
197-
(swap! xdb update-in keypath (constantly new-value)))
196+
(xitdb-swap-with-lock! xdb keypath (constantly new-value)))
198197

199198
(swap [this f]
200199
(xitdb-swap-with-lock! xdb keypath f))
@@ -208,5 +207,15 @@
208207
(swap [this f x y args]
209208
(apply xitdb-swap-with-lock! (concat [xdb keypath f x y] args))))
210209

211-
(defn xdb-cursor [^XITDBDatabase xdb keypath]
212-
(XITDBCursor. xdb keypath))
210+
(defn xdb-cursor [xdb keypath]
211+
(cond
212+
(instance? XITDBCursor xdb)
213+
(XITDBCursor. (.-xdb xdb) (vec (concat (.-keypath xdb) keypath)))
214+
215+
(instance? XITDBDatabase xdb)
216+
(XITDBCursor. xdb keypath)
217+
218+
:else
219+
(throw (IllegalArgumentException. (str "xdb must be an instance of XITDBCursor or XITDBDatabase, got: " (type xdb))))))
220+
221+

0 commit comments

Comments
 (0)