refactor - tests

This commit is contained in:
Jaremy Creechley 2023-09-27 19:08:58 -07:00
parent 534555015b
commit e778fdbb8e
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300

View File

@ -202,29 +202,35 @@ proc query*[K,V](
path.changeFileExt("") path.changeFileExt("")
let env = FsQueryEnv[K,V](self: self, basePath: DataBuffer.new(basePath)) let env = FsQueryEnv[K,V](self: self, basePath: DataBuffer.new(basePath))
success DbQueryHandle[KeyId, V, FsQueryEnv[K,V]](env: env) success DbQueryHandle[KeyId, V, FsQueryEnv[K,V]](query: query, env: env)
iterator iter*[K, V](handle: var DbQueryHandle[K, V, V]): ?!DbQueryResponse[K, V] = iterator iter*[K, V](handle: var DbQueryHandle[K, V, FsQueryEnv[K,V]]): ?!DbQueryResponse[K, V] =
let root = $(handle.env) let root = $(handle.env)
for path in root.dirIter(): for path in root.dirIter():
if handle.cancel: if handle.cancel:
return break
var keyPath = handle.basePath var
basePath = $handle.env.basePath
keyPath = basePath
keyPath.removePrefix(root) keyPath.removePrefix(root)
keyPath = keyPath / path.changeFileExt("") keyPath = keyPath / path.changeFileExt("")
keyPath = keyPath.replace("\\", "/") keyPath = keyPath.replace("\\", "/")
let let
fl = (handle.env.basePath / path).absolutePath() flres = (basePath / path).absolutePath().catch
key = Key.init(keyPath).expect("should not fail") if flres.isErr():
yield DbQueryResponse[K,V].failure flres.error()
let
key = K.toKey(keyPath)
data = data =
if query.value: if handle.query.value:
let res = readFile[V](handle.env.self, fl) let res = readFile[V](handle.env.self, flres.get)
if res.isErr(): if res.isErr():
yield failure res.error() yield DbQueryResponse[K,V].failure res.error()
res.get() res.get()
else: else:
V.new() V.new()