mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-01-07 16:13:07 +00:00
refactor - tests
This commit is contained in:
parent
534555015b
commit
e778fdbb8e
@ -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()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user