Merge branch 'master' into symbolchecks

# Conflicts:
#	tests/test.nim
This commit is contained in:
benbierens 2024-05-20 14:02:41 +02:00
commit c8660925d3
No known key found for this signature in database
GPG Key ID: 877D2C2E09A22F3A
3 changed files with 24 additions and 1 deletions

View File

@ -77,9 +77,11 @@ type
LevelDbException* = object of CatchableError
IterNext* = proc(): (string, string) {.gcsafe, closure.}
IterDispose* = proc() {.gcsafe, closure.}
LevelDbQueryIter* = ref object
finished*: bool
next*: IterNext
dispose*: IterDispose
const
version* = block:
@ -477,8 +479,13 @@ proc queryIter*(self: LevelDb, prefix: string = "", keysOnly: bool = false, skip
else:
return (keyStr, valueStr)
proc dispose() {.gcsafe, closure.} =
if not iter.finished:
iter.closeIter(iterPtr)
iter.finished = false
iter.next = getNext
iter.dispose = dispose
return iter
proc removeDb*(name: string) =

View File

@ -1,6 +1,6 @@
# Package
version = "0.1.2"
version = "0.1.3"
author = "leveldbstatic authors"
description = "Statically linked LevelDB wrapper for Nim"
license = "MIT"

View File

@ -241,6 +241,22 @@ suite "leveldb queryIter":
iter.next() == empty
iter.finished
test "iterate until disposed":
let iter = db.queryIter()
check:
not iter.finished
iter.next() == (k1, v1)
not iter.finished
iter.next() == (k2, v2)
not iter.finished
iter.dispose()
check:
iter.finished
iter.next() == empty
iter.finished
test "skip":
let iter = db.queryIter(skip = 1)
check: