mirror of
https://github.com/status-im/nim-codex.git
synced 2025-02-19 14:14:40 +00:00
hacks in rocksdb for testing
This commit is contained in:
parent
4c31b7760e
commit
6224f5aa28
@ -10,17 +10,44 @@ import pkg/upraises
|
||||
|
||||
import pkg/datastore
|
||||
|
||||
import ./rocksdb
|
||||
|
||||
push: {.upraises: [].}
|
||||
|
||||
type
|
||||
RocksDbDatastore* = ref object of Datastore
|
||||
a: string
|
||||
db: RocksDbReadWriteRef
|
||||
|
||||
func toByteSeq(str: string): seq[byte] {.inline.} =
|
||||
@(str.toOpenArrayByte(0, str.high))
|
||||
|
||||
func toString(bytes: openArray[byte]): string {.inline.} =
|
||||
let length = bytes.len
|
||||
if length > 0:
|
||||
result = newString(length)
|
||||
copyMem(result.cstring, bytes[0].unsafeAddr, length)
|
||||
|
||||
method get*(self: RocksDbDatastore, key: Key): Future[?!seq[byte]] {.async, locks: "unknown".} =
|
||||
raiseAssert("a")
|
||||
let keyBytes = toByteSeq($key)
|
||||
|
||||
let res = self.db.get(keyBytes)
|
||||
if res.isErr():
|
||||
return failure(res.error())
|
||||
return success(res.value())
|
||||
|
||||
method put*(self: RocksDbDatastore, key: Key, data: seq[byte]): Future[?!void] {.async, locks: "unknown".} =
|
||||
raiseAssert("a")
|
||||
let keyBytes = toByteSeq($key)
|
||||
let res = self.db.put(keyBytes, data)
|
||||
if res.isErr():
|
||||
return failure("failed to put!")
|
||||
return success()
|
||||
|
||||
proc new*(T: type RocksDbDatastore, dbName: string): ?!T =
|
||||
raiseAssert("a")
|
||||
let res = openRocksDb(dbName)
|
||||
if res.isErr():
|
||||
return failure(res.error())
|
||||
let db = res.value()
|
||||
|
||||
success T(
|
||||
db: db
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user