hacks in rocksdb for testing

This commit is contained in:
Ben 2024-05-01 09:47:29 +02:00
parent 4c31b7760e
commit 6224f5aa28
No known key found for this signature in database
GPG Key ID: 541B9D8C9F1426A1
1 changed files with 31 additions and 4 deletions

View File

@ -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
)