mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-01-04 22:53:08 +00:00
implementing query type
This commit is contained in:
parent
f5f07a0c5d
commit
1594977abf
@ -64,6 +64,7 @@ proc toSeq*[T: byte | char](a: DataBuffer, tp: typedesc[T]): seq[T] =
|
||||
|
||||
proc toString*(data: DataBuffer): string =
|
||||
## convert buffer to string type using copy
|
||||
if data.isNil: return ""
|
||||
result = newString(data.len())
|
||||
if data.len() > 0:
|
||||
copyMem(addr result[0], unsafeAddr data[].buf[0], data.len)
|
||||
|
||||
@ -172,6 +172,8 @@ proc deleteTask*(
|
||||
|
||||
discard ret[].signal.fireSync()
|
||||
|
||||
import pretty
|
||||
|
||||
proc delete*(
|
||||
ret: TResult[void],
|
||||
tds: ThreadDatastorePtr,
|
||||
@ -191,7 +193,11 @@ proc queryTask*(
|
||||
ret.failure(err)
|
||||
|
||||
let qrb = res.toBuffer()
|
||||
print "queryTask: ", " res: ", res
|
||||
|
||||
ret.success(qrb)
|
||||
print "queryTask: ", " qrb:key: ", ret[].results.get().key.toString()
|
||||
print "queryTask: ", " qrb:data: ", ret[].results.get().data.toString()
|
||||
|
||||
except Exception as exc:
|
||||
ret.failure(exc)
|
||||
|
||||
@ -120,6 +120,8 @@ method put*(
|
||||
|
||||
return success()
|
||||
|
||||
import pretty
|
||||
|
||||
method query*(
|
||||
self: ThreadProxyDatastore,
|
||||
query: Query
|
||||
@ -138,9 +140,14 @@ method query*(
|
||||
## note that bypasses SharedPtr isolation - may need `protect` here?
|
||||
iter[].it = it
|
||||
|
||||
echo "\n\n=== Query Start === "
|
||||
while not iter[].it.finished:
|
||||
echo ""
|
||||
query(ret, self.tds, iter)
|
||||
await wait(ret[].signal)
|
||||
print "query:post: ", ret[].results
|
||||
print "query:post: ", " qrb:key: ", ret[].results.get().key.toString()
|
||||
print "query:post: ", " qrb:data: ", ret[].results.get().data.toString()
|
||||
|
||||
iter[].it = nil # ensure our sharedptr doesn't try and dealloc
|
||||
finally:
|
||||
|
||||
@ -69,11 +69,6 @@ suite "Test Basic ThreadProxyDatastore":
|
||||
basicStoreTests(ds, key, bytes, otherBytes)
|
||||
|
||||
suite "Test Query":
|
||||
let
|
||||
path = currentSourcePath() # get this file's name
|
||||
basePath = "tests_data"
|
||||
basePathAbs = path.parentDir / basePath
|
||||
|
||||
var
|
||||
mem: MemoryDatastore
|
||||
sds: ThreadProxyDatastore
|
||||
@ -83,3 +78,4 @@ suite "Test Query":
|
||||
sds = newThreadProxyDatastore(mem).expect("should work")
|
||||
|
||||
queryTests(sds, false)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user