mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-01-03 06:03:06 +00:00
Define raises for async pragma
This commit is contained in:
parent
ea917be824
commit
13c0a0cdb1
@ -16,22 +16,22 @@ type
|
||||
Modify* = Function[?seq[byte], Future[?seq[byte]]]
|
||||
ModifyGet* = Function[?seq[byte], Future[(?seq[byte], seq[byte])]]
|
||||
|
||||
method has*(self: Datastore, key: Key): Future[?!bool] {.base, gcsafe, locks: "unknown".} =
|
||||
method has*(self: Datastore, key: Key): Future[?!bool] {.base, gcsafe, async: (raises: [CancelledError]), locks: "unknown".} =
|
||||
raiseAssert("Not implemented!")
|
||||
|
||||
method delete*(self: Datastore, key: Key): Future[?!void] {.base, gcsafe, locks: "unknown".} =
|
||||
method delete*(self: Datastore, key: Key): Future[?!void] {.base, gcsafe, async: (raises: [CancelledError]), locks: "unknown".} =
|
||||
raiseAssert("Not implemented!")
|
||||
|
||||
method delete*(self: Datastore, keys: seq[Key]): Future[?!void] {.base, gcsafe, locks: "unknown".} =
|
||||
method delete*(self: Datastore, keys: seq[Key]): Future[?!void] {.base, gcsafe, async: (raises: [CancelledError]), locks: "unknown".} =
|
||||
raiseAssert("Not implemented!")
|
||||
|
||||
method get*(self: Datastore, key: Key): Future[?!seq[byte]] {.base, gcsafe, locks: "unknown".} =
|
||||
method get*(self: Datastore, key: Key): Future[?!seq[byte]] {.base, gcsafe, async: (raises: [CancelledError]), locks: "unknown".} =
|
||||
raiseAssert("Not implemented!")
|
||||
|
||||
method put*(self: Datastore, key: Key, data: seq[byte]): Future[?!void] {.base, gcsafe, locks: "unknown".} =
|
||||
method put*(self: Datastore, key: Key, data: seq[byte]): Future[?!void] {.base, gcsafe, async: (raises: [CancelledError]), locks: "unknown".} =
|
||||
raiseAssert("Not implemented!")
|
||||
|
||||
method put*(self: Datastore, batch: seq[BatchEntry]): Future[?!void] {.base, gcsafe, locks: "unknown".} =
|
||||
method put*(self: Datastore, batch: seq[BatchEntry]): Future[?!void] {.base, gcsafe, async: (raises: [CancelledError]), locks: "unknown".} =
|
||||
raiseAssert("Not implemented!")
|
||||
|
||||
method close*(self: Datastore): Future[?!void] {.base, async, locks: "unknown".} =
|
||||
@ -43,7 +43,7 @@ method query*(
|
||||
|
||||
raiseAssert("Not implemented!")
|
||||
|
||||
proc contains*(self: Datastore, key: Key): Future[bool] {.async.} =
|
||||
proc contains*(self: Datastore, key: Key): Future[bool] {.async: (raises: [CancelledError]).} =
|
||||
return (await self.has(key)) |? false
|
||||
|
||||
method modify*(self: Datastore, key: Key, fn: Modify): Future[?!void] {.base, gcsafe, locks: "unknown".} =
|
||||
|
||||
@ -65,10 +65,10 @@ proc path*(self: FSDatastore, key: Key): ?!string =
|
||||
|
||||
return success fullname
|
||||
|
||||
method has*(self: FSDatastore, key: Key): Future[?!bool] {.async.} =
|
||||
method has*(self: FSDatastore, key: Key): Future[?!bool] {.async: (raises: [CancelledError]).} =
|
||||
return self.path(key).?fileExists()
|
||||
|
||||
method delete*(self: FSDatastore, key: Key): Future[?!void] {.async.} =
|
||||
method delete*(self: FSDatastore, key: Key): Future[?!void] {.async: (raises: [CancelledError]).} =
|
||||
without path =? self.path(key), error:
|
||||
return failure error
|
||||
|
||||
@ -82,7 +82,7 @@ method delete*(self: FSDatastore, key: Key): Future[?!void] {.async.} =
|
||||
|
||||
return success()
|
||||
|
||||
method delete*(self: FSDatastore, keys: seq[Key]): Future[?!void] {.async.} =
|
||||
method delete*(self: FSDatastore, keys: seq[Key]): Future[?!void] {.async: (raises: [CancelledError]).} =
|
||||
for key in keys:
|
||||
if err =? (await self.delete(key)).errorOption:
|
||||
return failure err
|
||||
@ -119,7 +119,7 @@ proc readFile*(self: FSDatastore, path: string): ?!seq[byte] =
|
||||
except CatchableError as e:
|
||||
return failure e
|
||||
|
||||
method get*(self: FSDatastore, key: Key): Future[?!seq[byte]] {.async.} =
|
||||
method get*(self: FSDatastore, key: Key): Future[?!seq[byte]] {.async: (raises: [CancelledError]).} =
|
||||
without path =? self.path(key), error:
|
||||
return failure error
|
||||
|
||||
@ -132,7 +132,7 @@ method get*(self: FSDatastore, key: Key): Future[?!seq[byte]] {.async.} =
|
||||
method put*(
|
||||
self: FSDatastore,
|
||||
key: Key,
|
||||
data: seq[byte]): Future[?!void] {.async.} =
|
||||
data: seq[byte]): Future[?!void] {.async: (raises: [CancelledError]).} =
|
||||
|
||||
without path =? self.path(key), error:
|
||||
return failure error
|
||||
@ -147,7 +147,7 @@ method put*(
|
||||
|
||||
method put*(
|
||||
self: FSDatastore,
|
||||
batch: seq[BatchEntry]): Future[?!void] {.async.} =
|
||||
batch: seq[BatchEntry]): Future[?!void] {.async: (raises: [CancelledError]).} =
|
||||
|
||||
for entry in batch:
|
||||
if err =? (await self.put(entry.key, entry.data)).errorOption:
|
||||
|
||||
@ -20,27 +20,27 @@ type
|
||||
db: LevelDb
|
||||
locks: TableRef[Key, AsyncLock]
|
||||
|
||||
method has*(self: LevelDbDatastore, key: Key): Future[?!bool] {.async.} =
|
||||
method has*(self: LevelDbDatastore, key: Key): Future[?!bool] {.async: (raises: [CancelledError]).} =
|
||||
try:
|
||||
let str = self.db.get($key)
|
||||
return success(str.isSome)
|
||||
except LevelDbException as e:
|
||||
return failure("LevelDbDatastore.has exception: " & e.msg)
|
||||
|
||||
method delete*(self: LevelDbDatastore, key: Key): Future[?!void] {.async.} =
|
||||
method delete*(self: LevelDbDatastore, key: Key): Future[?!void] {.async: (raises: [CancelledError]).} =
|
||||
try:
|
||||
self.db.delete($key, sync = true)
|
||||
return success()
|
||||
except LevelDbException as e:
|
||||
return failure("LevelDbDatastore.delete exception: " & e.msg)
|
||||
|
||||
method delete*(self: LevelDbDatastore, keys: seq[Key]): Future[?!void] {.async.} =
|
||||
method delete*(self: LevelDbDatastore, keys: seq[Key]): Future[?!void] {.async: (raises: [CancelledError]).} =
|
||||
for key in keys:
|
||||
if err =? (await self.delete(key)).errorOption:
|
||||
return failure(err.msg)
|
||||
return success()
|
||||
|
||||
method get*(self: LevelDbDatastore, key: Key): Future[?!seq[byte]] {.async.} =
|
||||
method get*(self: LevelDbDatastore, key: Key): Future[?!seq[byte]] {.async: (raises: [CancelledError]).} =
|
||||
try:
|
||||
let str = self.db.get($key)
|
||||
if not str.isSome:
|
||||
@ -50,7 +50,7 @@ method get*(self: LevelDbDatastore, key: Key): Future[?!seq[byte]] {.async.} =
|
||||
except LevelDbException as e:
|
||||
return failure("LevelDbDatastore.get exception: " & $e.msg)
|
||||
|
||||
method put*(self: LevelDbDatastore, key: Key, data: seq[byte]): Future[?!void] {.async.} =
|
||||
method put*(self: LevelDbDatastore, key: Key, data: seq[byte]): Future[?!void] {.async: (raises: [CancelledError]).} =
|
||||
try:
|
||||
let str = string.fromBytes(data)
|
||||
self.db.put($key, str)
|
||||
@ -58,7 +58,7 @@ method put*(self: LevelDbDatastore, key: Key, data: seq[byte]): Future[?!void] {
|
||||
except LevelDbException as e:
|
||||
return failure("LevelDbDatastore.put exception: " & $e.msg)
|
||||
|
||||
method put*(self: LevelDbDatastore, batch: seq[BatchEntry]): Future[?!void] {.async.} =
|
||||
method put*(self: LevelDbDatastore, batch: seq[BatchEntry]): Future[?!void] {.async: (raises: [CancelledError]).} =
|
||||
try:
|
||||
let b = newBatch()
|
||||
for entry in batch:
|
||||
|
||||
@ -63,7 +63,7 @@ proc dispatch(
|
||||
|
||||
method has*(
|
||||
self: MountedDatastore,
|
||||
key: Key): Future[?!bool] {.async.} =
|
||||
key: Key): Future[?!bool] {.async: (raises: [CancelledError]).} =
|
||||
|
||||
without mounted =? self.dispatch(key):
|
||||
return failure "No mounted datastore found"
|
||||
@ -72,7 +72,7 @@ method has*(
|
||||
|
||||
method delete*(
|
||||
self: MountedDatastore,
|
||||
key: Key): Future[?!void] {.async.} =
|
||||
key: Key): Future[?!void] {.async: (raises: [CancelledError]).} =
|
||||
|
||||
without mounted =? self.dispatch(key), error:
|
||||
return failure(error)
|
||||
@ -81,7 +81,7 @@ method delete*(
|
||||
|
||||
method delete*(
|
||||
self: MountedDatastore,
|
||||
keys: seq[Key]): Future[?!void] {.async.} =
|
||||
keys: seq[Key]): Future[?!void] {.async: (raises: [CancelledError]).} =
|
||||
|
||||
for key in keys:
|
||||
if err =? (await self.delete(key)).errorOption:
|
||||
@ -91,7 +91,7 @@ method delete*(
|
||||
|
||||
method get*(
|
||||
self: MountedDatastore,
|
||||
key: Key): Future[?!seq[byte]] {.async.} =
|
||||
key: Key): Future[?!seq[byte]] {.async: (raises: [CancelledError]).} =
|
||||
|
||||
without mounted =? self.dispatch(key), error:
|
||||
return failure(error)
|
||||
@ -101,7 +101,7 @@ method get*(
|
||||
method put*(
|
||||
self: MountedDatastore,
|
||||
key: Key,
|
||||
data: seq[byte]): Future[?!void] {.async.} =
|
||||
data: seq[byte]): Future[?!void] {.async: (raises: [CancelledError]).} =
|
||||
|
||||
without mounted =? self.dispatch(key), error:
|
||||
return failure(error)
|
||||
@ -110,7 +110,7 @@ method put*(
|
||||
|
||||
method put*(
|
||||
self: MountedDatastore,
|
||||
batch: seq[BatchEntry]): Future[?!void] {.async.} =
|
||||
batch: seq[BatchEntry]): Future[?!void] {.async: (raises: [CancelledError]).} =
|
||||
|
||||
for entry in batch:
|
||||
if err =? (await self.put(entry.key, entry.data)).errorOption:
|
||||
|
||||
@ -146,7 +146,7 @@ method modify*(self: SQLiteDatastore, key: Key, fn: Modify): Future[?!void] {.as
|
||||
else:
|
||||
return success()
|
||||
|
||||
method has*(self: SQLiteDatastore, key: Key): Future[?!bool] {.async.} =
|
||||
method has*(self: SQLiteDatastore, key: Key): Future[?!bool] {.async: (raises: [CancelledError]).} =
|
||||
var
|
||||
exists = false
|
||||
|
||||
@ -158,10 +158,10 @@ method has*(self: SQLiteDatastore, key: Key): Future[?!bool] {.async.} =
|
||||
|
||||
return success exists
|
||||
|
||||
method delete*(self: SQLiteDatastore, key: Key): Future[?!void] {.async.} =
|
||||
method delete*(self: SQLiteDatastore, key: Key): Future[?!void] {.async: (raises: [CancelledError]).} =
|
||||
return self.db.deleteStmt.exec((key.id))
|
||||
|
||||
method delete*(self: SQLiteDatastore, keys: seq[Key]): Future[?!void] {.async.} =
|
||||
method delete*(self: SQLiteDatastore, keys: seq[Key]): Future[?!void] {.async: (raises: [CancelledError]).} =
|
||||
if err =? self.db.beginStmt.exec().errorOption:
|
||||
return failure(err)
|
||||
|
||||
@ -177,7 +177,7 @@ method delete*(self: SQLiteDatastore, keys: seq[Key]): Future[?!void] {.async.}
|
||||
|
||||
return success()
|
||||
|
||||
method get*(self: SQLiteDatastore, key: Key): Future[?!seq[byte]] {.async.} =
|
||||
method get*(self: SQLiteDatastore, key: Key): Future[?!seq[byte]] {.async: (raises: [CancelledError]).} =
|
||||
# see comment in ./filesystem_datastore re: finer control of memory
|
||||
# allocation in `method get`, could apply here as well if bytes were read
|
||||
# incrementally with `sqlite3_blob_read`
|
||||
@ -197,10 +197,10 @@ method get*(self: SQLiteDatastore, key: Key): Future[?!seq[byte]] {.async.} =
|
||||
|
||||
return success bytes
|
||||
|
||||
method put*(self: SQLiteDatastore, key: Key, data: seq[byte]): Future[?!void] {.async.} =
|
||||
method put*(self: SQLiteDatastore, key: Key, data: seq[byte]): Future[?!void] {.async: (raises: [CancelledError]).} =
|
||||
return self.db.putStmt.exec((key.id, data, initVersion, timestamp()))
|
||||
|
||||
method put*(self: SQLiteDatastore, batch: seq[BatchEntry]): Future[?!void] {.async.} =
|
||||
method put*(self: SQLiteDatastore, batch: seq[BatchEntry]): Future[?!void] {.async: (raises: [CancelledError]).} =
|
||||
if err =? self.db.beginStmt.exec().errorOption:
|
||||
return failure err
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@ proc stores*(self: TieredDatastore): seq[Datastore] =
|
||||
|
||||
method has*(
|
||||
self: TieredDatastore,
|
||||
key: Key): Future[?!bool] {.async.} =
|
||||
key: Key): Future[?!bool] {.async: (raises: [CancelledError]).} =
|
||||
|
||||
for store in self.stores:
|
||||
without res =? (await store.has(key)), err:
|
||||
@ -41,32 +41,34 @@ method has*(
|
||||
|
||||
method delete*(
|
||||
self: TieredDatastore,
|
||||
key: Key): Future[?!void] {.async.} =
|
||||
key: Key): Future[?!void] {.async: (raises: [CancelledError]).} =
|
||||
|
||||
let
|
||||
pending = await allFinished(self.stores.mapIt(it.delete(key)))
|
||||
|
||||
for fut in pending:
|
||||
if fut.read().isErr: return fut.read()
|
||||
without res =? fut.read().catch, error:
|
||||
return failure error
|
||||
|
||||
return success()
|
||||
|
||||
method delete*(
|
||||
self: TieredDatastore,
|
||||
keys: seq[Key]): Future[?!void] {.async.} =
|
||||
keys: seq[Key]): Future[?!void] {.async: (raises: [CancelledError]).} =
|
||||
|
||||
for key in keys:
|
||||
let
|
||||
pending = await allFinished(self.stores.mapIt(it.delete(key)))
|
||||
|
||||
for fut in pending:
|
||||
if fut.read().isErr: return fut.read()
|
||||
without res =? fut.read().catch, error:
|
||||
return failure error
|
||||
|
||||
return success()
|
||||
|
||||
method get*(
|
||||
self: TieredDatastore,
|
||||
key: Key): Future[?!seq[byte]] {.async.} =
|
||||
key: Key): Future[?!seq[byte]] {.async: (raises: [CancelledError]).} =
|
||||
|
||||
var
|
||||
bytes: seq[byte]
|
||||
@ -91,26 +93,28 @@ method get*(
|
||||
method put*(
|
||||
self: TieredDatastore,
|
||||
key: Key,
|
||||
data: seq[byte]): Future[?!void] {.async.} =
|
||||
data: seq[byte]): Future[?!void] {.async: (raises: [CancelledError]).} =
|
||||
|
||||
let
|
||||
pending = await allFinished(self.stores.mapIt(it.put(key, data)))
|
||||
|
||||
for fut in pending:
|
||||
if fut.read().isErr: return fut.read()
|
||||
without res =? fut.read().catch, error:
|
||||
return failure error
|
||||
|
||||
return success()
|
||||
|
||||
method put*(
|
||||
self: TieredDatastore,
|
||||
batch: seq[BatchEntry]): Future[?!void] {.async.} =
|
||||
batch: seq[BatchEntry]): Future[?!void] {.async: (raises: [CancelledError]).} =
|
||||
|
||||
for entry in batch:
|
||||
let
|
||||
pending = await allFinished(self.stores.mapIt(it.put(entry.key, entry.data)))
|
||||
|
||||
for fut in pending:
|
||||
if fut.read().isErr: return fut.read()
|
||||
without res =? fut.read().catch, error:
|
||||
return failure error
|
||||
|
||||
return success()
|
||||
|
||||
|
||||
@ -71,16 +71,16 @@ template requireEncoder*(T: typedesc): untyped =
|
||||
{.error: "provide an encoder: `proc encode(a: " & $T & "): seq[byte]`".}
|
||||
|
||||
# Original Datastore API
|
||||
proc has*(self: TypedDatastore, key: Key): Future[?!bool] {.async.} =
|
||||
proc has*(self: TypedDatastore, key: Key): Future[?!bool] {.async: (raises: [CancelledError]).} =
|
||||
await self.ds.has(key)
|
||||
|
||||
proc contains*(self: TypedDatastore, key: Key): Future[bool] {.async.} =
|
||||
proc contains*(self: TypedDatastore, key: Key): Future[bool] {.async: (raises: [CancelledError]).} =
|
||||
return (await self.ds.has(key)) |? false
|
||||
|
||||
proc delete*(self: TypedDatastore, key: Key): Future[?!void] {.async.} =
|
||||
proc delete*(self: TypedDatastore, key: Key): Future[?!void] {.async: (raises: [CancelledError]).} =
|
||||
await self.ds.delete(key)
|
||||
|
||||
proc delete*(self: TypedDatastore, keys: seq[Key]): Future[?!void] {.async.} =
|
||||
proc delete*(self: TypedDatastore, keys: seq[Key]): Future[?!void] {.async: (raises: [CancelledError]).} =
|
||||
await self.ds.delete(keys)
|
||||
|
||||
proc close*(self: TypedDatastore): Future[?!void] {.async.} =
|
||||
@ -90,12 +90,12 @@ proc close*(self: TypedDatastore): Future[?!void] {.async.} =
|
||||
proc init*(T: type TypedDatastore, ds: Datastore): T =
|
||||
TypedDatastore(ds: ds)
|
||||
|
||||
proc put*[T](self: TypedDatastore, key: Key, t: T): Future[?!void] {.async.} =
|
||||
proc put*[T](self: TypedDatastore, key: Key, t: T): Future[?!void] {.async: (raises: [CancelledError]).} =
|
||||
requireEncoder(T)
|
||||
|
||||
await self.ds.put(key, t.encode)
|
||||
|
||||
proc get*[T](self: TypedDatastore, key: Key): Future[?!T] {.async.} =
|
||||
proc get*[T](self: TypedDatastore, key: Key): Future[?!T] {.async: (raises: [CancelledError]).} =
|
||||
requireDecoder(T)
|
||||
|
||||
without bytes =? await self.ds.get(key), error:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user