mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-01-02 13:43:11 +00:00
* shorten lines * only return data when `query.value == true` * test `query.value = false` * close mounted ds * allow passing dispose to query iter constructor * fix fs querying * use currentSourcePath * remove `dsobj` extensions from directories * don't return error on missing key delete * return `DatastoreKeyNotFound` on empty `get` * return `DatastoreKeyNotFound` on missing sql key
55 lines
1.4 KiB
Nim
55 lines
1.4 KiB
Nim
import pkg/upraises
|
|
import pkg/chronos
|
|
import pkg/questionable
|
|
import pkg/questionable/results
|
|
|
|
import ./key
|
|
import ./types
|
|
|
|
type
|
|
SortOrder* {.pure.} = enum
|
|
Assending,
|
|
Descending
|
|
|
|
Query* = object
|
|
key*: Key # 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*: SortOrder # Sort order - not available in all backends
|
|
|
|
QueryResponse* = tuple[key: ?Key, data: seq[byte]]
|
|
QueryEndedError* = object of DatastoreError
|
|
|
|
GetNext* = proc(): Future[?!QueryResponse] {.upraises: [], gcsafe, closure.}
|
|
IterDispose* = proc(): Future[?!void] {.upraises: [], gcsafe.}
|
|
QueryIter* = ref object
|
|
finished*: bool
|
|
next*: GetNext
|
|
dispose*: IterDispose
|
|
|
|
iterator items*(q: QueryIter): Future[?!QueryResponse] =
|
|
while not q.finished:
|
|
yield q.next()
|
|
|
|
proc defaultDispose(): Future[?!void] {.upraises: [], gcsafe, async.} =
|
|
return success()
|
|
|
|
proc new*(T: type QueryIter, dispose = defaultDispose): T =
|
|
QueryIter(dispose: dispose)
|
|
|
|
proc init*(
|
|
T: type Query,
|
|
key: Key,
|
|
value = true,
|
|
sort = SortOrder.Assending,
|
|
offset = 0,
|
|
limit = -1): T =
|
|
|
|
T(
|
|
key: key,
|
|
value: value,
|
|
sort: sort,
|
|
offset: offset,
|
|
limit: limit)
|