mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-01-02 13:43:11 +00:00
add querybuffer type
This commit is contained in:
parent
9d6e6ae220
commit
e52f7949b9
@ -21,6 +21,18 @@ type
|
||||
CatchableErrorBuffer* = object
|
||||
msg: StringBuffer
|
||||
|
||||
QSortOrder* {.pure.} = enum
|
||||
Ascending,
|
||||
Descending
|
||||
|
||||
QueryBuffer* = object
|
||||
key*: KeyBuffer # Key to be queried
|
||||
value*: bool # Flag to indicate if data should be returned
|
||||
limit*: int # Max items to return - not available in all backends
|
||||
offset*: int # Offset from which to start querying - not available in all backends
|
||||
sort*: QSortOrder # Sort order - not available in all backends
|
||||
|
||||
|
||||
proc `=destroy`*(x: var DataBufferHolder) =
|
||||
## copy pointer implementation
|
||||
if x.buf != nil:
|
||||
|
||||
@ -5,6 +5,7 @@ import pkg/questionable/results
|
||||
|
||||
import ./key
|
||||
import ./types
|
||||
import ./databuffer
|
||||
|
||||
type
|
||||
SortOrder* {.pure.} = enum
|
||||
@ -52,3 +53,15 @@ proc init*(
|
||||
sort: sort,
|
||||
offset: offset,
|
||||
limit: limit)
|
||||
|
||||
proc toBuffer*(q: Query): QueryBuffer =
|
||||
## convert Query to thread-safe QueryBuffer
|
||||
return QueryBuffer(
|
||||
key: KeyBuffer.new(q.key),
|
||||
value: q.value,
|
||||
offset: q.offset,
|
||||
sort:
|
||||
case q.sort:
|
||||
of SortOrder.Assending: QSortOrder.Ascending
|
||||
of SortOrder.Descending: QSortOrder.Descending
|
||||
)
|
||||
|
||||
@ -175,3 +175,32 @@ proc delete*(
|
||||
) =
|
||||
let bkey = StringBuffer.new(key.id())
|
||||
tds[].tp.spawn deleteTask(ret, tds, bkey)
|
||||
|
||||
# proc keyIterator(self: ThreadProxyDatastore,
|
||||
# queryKey: string
|
||||
# ): iterator: KeyBuffer {.gcsafe.} =
|
||||
# return iterator(): KeyBuffer {.closure.} =
|
||||
# var keys = self.store.keys().toSeq()
|
||||
# keys.sort(proc (x, y: KeyBuffer): int = cmp(x.toString, y.toString))
|
||||
# for key in keys:
|
||||
# if key.toString().startsWith(queryKey):
|
||||
# yield key
|
||||
|
||||
method queryTask*(
|
||||
ret: TResult[void],
|
||||
tds: ThreadDatastorePtr,
|
||||
query: Query,
|
||||
): Future[?!QueryIter] {.async.} =
|
||||
|
||||
without key =? kb.toKey(), err:
|
||||
ret.failure(err)
|
||||
|
||||
let q = Query.init(key1)
|
||||
|
||||
for entry in batch:
|
||||
if err =? (await self.put(entry.key, entry.data)).errorOption:
|
||||
return failure err
|
||||
|
||||
|
||||
iter.next = next
|
||||
return success iter
|
||||
|
||||
@ -134,6 +134,7 @@ method close*(
|
||||
## this can block... how to handle? maybe just leak?
|
||||
self.tds[].tp.shutdown()
|
||||
|
||||
|
||||
proc newThreadProxyDatastore*(
|
||||
ds: Datastore,
|
||||
): ?!ThreadProxyDatastore =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user