mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-01-04 22:53:08 +00:00
Merge 0beff39fbe702e58640244600f176bb84f1429a9 into ea917be824b9f2884955e45d0cb3aea9a8740dc6
This commit is contained in:
commit
426d251400
@ -34,23 +34,30 @@ method delete*(self: LevelDbDatastore, key: Key): Future[?!void] {.async.} =
|
||||
except LevelDbException as e:
|
||||
return failure("LevelDbDatastore.delete exception: " & e.msg)
|
||||
|
||||
method delete*(self: LevelDbDatastore, keys: seq[Key]): Future[?!void] {.async.} =
|
||||
for key in keys:
|
||||
if err =? (await self.delete(key)).errorOption:
|
||||
return failure(err.msg)
|
||||
return success()
|
||||
method delete*(self: LevelDbDatastore, keys: seq[Key]): Future[
|
||||
?!void] {.async.} =
|
||||
try:
|
||||
let b = newBatch()
|
||||
for key in keys:
|
||||
b.delete($key)
|
||||
self.db.write(b)
|
||||
return success()
|
||||
except LevelDbException as e:
|
||||
return failure("LevelDbDatastore.delete batch exception: " & e.msg)
|
||||
|
||||
method get*(self: LevelDbDatastore, key: Key): Future[?!seq[byte]] {.async.} =
|
||||
try:
|
||||
let str = self.db.get($key)
|
||||
if not str.isSome:
|
||||
return failure(newException(DatastoreKeyNotFound, "LevelDbDatastore.get: key not found " & $key))
|
||||
return failure(newException(DatastoreKeyNotFound,
|
||||
"LevelDbDatastore.get: key not found " & $key))
|
||||
let bytes = str.get().toBytes()
|
||||
return success(bytes)
|
||||
except LevelDbException as e:
|
||||
return failure("LevelDbDatastore.get exception: " & $e.msg)
|
||||
|
||||
method put*(self: LevelDbDatastore, key: Key, data: seq[byte]): Future[?!void] {.async.} =
|
||||
method put*(self: LevelDbDatastore, key: Key, data: seq[byte]): Future[
|
||||
?!void] {.async.} =
|
||||
try:
|
||||
let str = string.fromBytes(data)
|
||||
self.db.put($key, str)
|
||||
@ -58,7 +65,8 @@ method put*(self: LevelDbDatastore, key: Key, data: seq[byte]): Future[?!void] {
|
||||
except LevelDbException as e:
|
||||
return failure("LevelDbDatastore.put exception: " & $e.msg)
|
||||
|
||||
method put*(self: LevelDbDatastore, batch: seq[BatchEntry]): Future[?!void] {.async.} =
|
||||
method put*(self: LevelDbDatastore, batch: seq[BatchEntry]): Future[
|
||||
?!void] {.async.} =
|
||||
try:
|
||||
let b = newBatch()
|
||||
for entry in batch:
|
||||
@ -100,7 +108,8 @@ method query*(
|
||||
|
||||
proc next(): Future[?!QueryResponse] {.async.} =
|
||||
if iter.finished:
|
||||
return failure(newException(QueryEndedError, "Calling next on a finished query!"))
|
||||
return failure(newException(QueryEndedError,
|
||||
"Calling next on a finished query!"))
|
||||
|
||||
try:
|
||||
let (keyStr, valueStr) = dbIter.next()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user