mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-01-04 22:53:08 +00:00
key batch
This commit is contained in:
parent
8c71655593
commit
4d26f707e5
@ -40,7 +40,7 @@ proc has*(self: SQLiteDatastore, key: DbKey): ?!bool =
|
||||
return success exists
|
||||
|
||||
proc delete*(self: SQLiteDatastore, key: DbKey): ?!void =
|
||||
return self.db.deleteStmt.exec((key))
|
||||
return self.db.deleteStmt.exec(($key))
|
||||
|
||||
proc delete*(self: SQLiteDatastore, keys: openArray[DbKey]): ?!void =
|
||||
if err =? self.db.beginStmt.exec().errorOption:
|
||||
@ -69,7 +69,7 @@ proc get*(self: SQLiteDatastore, key: DbKey): ?!seq[byte] =
|
||||
proc onData(s: RawStmtPtr) =
|
||||
bytes = dataCol(self.db.getDataCol)
|
||||
|
||||
if err =? self.db.getStmt.query((key), onData).errorOption:
|
||||
if err =? self.db.getStmt.query(($key), onData).errorOption:
|
||||
return failure(err)
|
||||
|
||||
if bytes.len <= 0:
|
||||
|
||||
@ -35,7 +35,7 @@ proc isNil*(a: DataBuffer): bool = smartptrs.isNil(a)
|
||||
proc hash*(a: DataBuffer): Hash =
|
||||
a[].buf.toOpenArray(0, a[].size-1).hash()
|
||||
|
||||
proc `[]`*(db: DataBuffer, idx: int): byte =
|
||||
proc `[]`*(db: DataBuffer, idx: int): var byte =
|
||||
if idx >= db.len():
|
||||
raise newException(IndexDefect, "index out of bounds")
|
||||
db[].buf[idx]
|
||||
|
||||
@ -14,11 +14,12 @@ import pkg/datastore/key
|
||||
import ../dscommontests
|
||||
import ../querycommontests
|
||||
|
||||
proc testBasic[K, V](
|
||||
proc testBasic[K, V, B](
|
||||
ds: SQLiteDatastore,
|
||||
key: K,
|
||||
bytes: V,
|
||||
otherBytes: V,
|
||||
batches: B,
|
||||
) =
|
||||
|
||||
test "put":
|
||||
@ -80,19 +81,24 @@ suite "Test Basic SQLiteDatastore":
|
||||
bytes = "some bytes".toBytes
|
||||
otherBytes = "some other bytes".toBytes
|
||||
|
||||
suiteTeardown:
|
||||
ds.close().tryGet()
|
||||
|
||||
testBasic(ds, key, bytes, otherBytes)
|
||||
|
||||
suite "Test DataBuffer SQLiteDatastore":
|
||||
let
|
||||
ds = SQLiteDatastore.new(Memory).tryGet()
|
||||
key = KeyId.new Key.init("a:b/c/d:e").tryGet().id()
|
||||
bytes = DataBuffer.new "some bytes"
|
||||
otherBytes = DataBuffer.new "some other bytes"
|
||||
var batch: seq[tuple[key: string, data: seq[byte]]]
|
||||
for k in 0..<100:
|
||||
let kk = Key.init(key, $k).tryGet().id()
|
||||
batch.add( (kk, @[k.byte]) )
|
||||
|
||||
suiteTeardown:
|
||||
ds.close().tryGet()
|
||||
|
||||
testBasic(ds, key, bytes, otherBytes, batch)
|
||||
|
||||
# suite "Test DataBuffer SQLiteDatastore":
|
||||
# let
|
||||
# ds = SQLiteDatastore.new(Memory).tryGet()
|
||||
# key = KeyId.new Key.init("a:b/c/d:e").tryGet().id()
|
||||
# bytes = DataBuffer.new "some bytes"
|
||||
# otherBytes = DataBuffer.new "some other bytes"
|
||||
|
||||
# suiteTeardown:
|
||||
# ds.close().tryGet()
|
||||
|
||||
testBasic(ds, key, bytes, otherBytes)
|
||||
# testBasic(ds, key, bytes, otherBytes)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user