implementing query type

This commit is contained in:
Jaremy Creechley 2023-08-29 17:00:11 -07:00
parent f5f07a0c5d
commit 1594977abf
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
4 changed files with 15 additions and 5 deletions

View File

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

View File

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

View File

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

View File

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