mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-01-10 09:33:08 +00:00
implementing query type
This commit is contained in:
parent
934686a4ee
commit
d08c63c6be
@ -62,6 +62,8 @@ proc convert*[T, S](ret: TResult[T], tp: typedesc[S]): Result[S, ref CatchableEr
|
|||||||
result.ok(ret[].results.get().toString())
|
result.ok(ret[].results.get().toString())
|
||||||
elif S is void:
|
elif S is void:
|
||||||
result.ok()
|
result.ok()
|
||||||
|
elif S is QueryResponse:
|
||||||
|
result.ok(ret[].results.get().toQueryResponse())
|
||||||
else:
|
else:
|
||||||
result.ok(ret[].results.get())
|
result.ok(ret[].results.get())
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -130,30 +130,38 @@ method query*(
|
|||||||
without ret =? newThreadResult(QueryResponseBuffer), err:
|
without ret =? newThreadResult(QueryResponseBuffer), err:
|
||||||
return failure(err)
|
return failure(err)
|
||||||
|
|
||||||
try:
|
## we need to setup the query iter on the main thread
|
||||||
## we need to setup the query iter on the main thread
|
## to keep it's lifetime associated with this async Future
|
||||||
## to keep it's lifetime associated with this async Future
|
without it =? await self.tds[].ds.query(query), err:
|
||||||
without it =? await self.tds[].ds.query(query), err:
|
ret.failure(err)
|
||||||
ret.failure(err)
|
|
||||||
|
|
||||||
var iter = newSharedPtr(QueryIterStore)
|
var iter = newSharedPtr(QueryIterStore)
|
||||||
## note that bypasses SharedPtr isolation - may need `protect` here?
|
## note that bypasses SharedPtr isolation - may need `protect` here?
|
||||||
iter[].it = it
|
iter[].it = it
|
||||||
|
|
||||||
|
var iterWrapper = QueryIter.new()
|
||||||
|
|
||||||
|
proc next(): Future[?!QueryResponse] {.async.} =
|
||||||
echo "\n\n=== Query Start === "
|
echo "\n\n=== Query Start === "
|
||||||
while not iter[].it.finished:
|
if not iter[].it.finished:
|
||||||
echo ""
|
echo ""
|
||||||
query(ret, self.tds, iter)
|
query(ret, self.tds, iter)
|
||||||
await wait(ret[].signal)
|
await wait(ret[].signal)
|
||||||
print "query:post: ", ret[].results
|
print "query:post: ", ret[].results
|
||||||
print "query:post: ", " qrb:key: ", ret[].results.get().key.toString()
|
print "query:post: ", " qrb:key: ", ret[].results.get().key.toString()
|
||||||
print "query:post: ", " qrb:data: ", ret[].results.get().data.toString()
|
print "query:post: ", " qrb:data: ", ret[].results.get().data.toString()
|
||||||
|
return ret.convert(QueryResponse)
|
||||||
|
else:
|
||||||
|
iterWrapper.finished = true
|
||||||
|
|
||||||
|
proc dispose(): Future[?!void] {.async.} =
|
||||||
iter[].it = nil # ensure our sharedptr doesn't try and dealloc
|
iter[].it = nil # ensure our sharedptr doesn't try and dealloc
|
||||||
finally:
|
|
||||||
ret[].signal.close()
|
ret[].signal.close()
|
||||||
|
return success()
|
||||||
|
|
||||||
# return ret.convert(void)
|
iterWrapper.next = next
|
||||||
|
iterWrapper.dispose = dispose
|
||||||
|
return success iterWrapper
|
||||||
|
|
||||||
method close*(
|
method close*(
|
||||||
self: ThreadProxyDatastore
|
self: ThreadProxyDatastore
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user