[wip] note some problems when using without

This commit is contained in:
Michael Bradley, Jr 2022-08-05 10:59:37 -05:00
parent ea4cfa954f
commit f3f3a06de9
No known key found for this signature in database
GPG Key ID: D0307DBCF21A9A58
5 changed files with 48 additions and 27 deletions

View File

@ -9,7 +9,7 @@ license = "Apache License 2.0 or MIT"
requires "nim >= 1.2.0",
"asynctest >= 0.3.1 & < 0.4.0",
"chronos",
"questionable >= 0.10.3 & < 0.11.0",
"questionable >= 0.10.4 & < 0.11.0",
"sqlite3_abi",
"stew",
"unittest2",

View File

@ -3,7 +3,6 @@ import std/os
import pkg/chronos
import pkg/questionable
import pkg/questionable/results
from pkg/stew/results as stewResults import get, isErr
import pkg/upraises
import ./datastore
@ -96,11 +95,11 @@ method get*(
let
path = self.path(key)
containsRes = await self.contains(key)
if containsRes.isErr: return failure containsRes.error.msg
without contain =? await self.contains(key), error:
return failure error
if containsRes.get:
if contain:
var
file: File

View File

@ -6,7 +6,10 @@ import std/strutils
import pkg/questionable
import pkg/questionable/results
# could be removed if problems with questionable are resolved
from pkg/stew/results as stewResults import get, isErr
import pkg/upraises
export hashes
@ -156,6 +159,21 @@ proc init*(
nss: seq[Namespace]
for s in namespaces:
# if `, error` is used instead of `, err` then compilation fails with:
# Error: cannot use symbol of kind 'func' as a 'template'
# maybe related to `from pkg/stew/results as stewResults` at top of module,
# which could be removed if other problems with questionable are resolved
# but when using `, err` then compilation fails with:
# SIGSEGV: Illegal storage access
# but strangely the last call in the stack trace pertains to L211 below
# without ns =? Namespace.init(s), err:
# return failure "namespaces contains an invalid Namespace: " & err.msg
#
# nss.add ns
let
nsRes = Namespace.init(s)
@ -184,14 +202,15 @@ proc init*(
return failure "id string must not contain only one or more separator " &
"\"" & separator & "\""
let
keyRes = Key.init(nsStrs)
if keyRes.isErr:
# if `, error` is used instead of `, err` then compilation fails with:
# Error: cannot use symbol of kind 'func' as a 'template'
# maybe related to `from pkg/stew/results as stewResults` at top of module,
# which could be removed if other problems with questionable are resolved
without key =? Key.init(nsStrs), err:
return failure "id string contains an invalid Namespace:" &
keyRes.error.msg.split(":")[1..^1].join("").replace("\"\"", "\":\"")
err.msg.split(":")[1..^1].join("").replace("\"\"", "\":\"")
keyRes
success key
proc namespaces*(self: Key): seq[Namespace] =
self.namespaces
@ -271,8 +290,8 @@ proc instance*(
self: Key,
id: string): ?!Key =
without key =? Key.init(id), e:
return failure e
without key =? Key.init(id), error:
return failure error
success self.instance(key)

View File

@ -294,9 +294,10 @@ method contains*(
let
queryRes = self.containsStmt.query((key.id), onData)
if queryRes.isErr: return queryRes
return success exists
if queryRes.isErr:
return queryRes
else:
return success exists
method delete*(
self: SQLiteDatastore,
@ -328,7 +329,7 @@ method get*(
queryRes = self.getStmt.query((key.id), onData)
if queryRes.isErr:
return failure queryRes.error.msg
return failure queryRes.error
else:
return success bytes

View File

@ -3,7 +3,7 @@ import std/sequtils
import pkg/chronos
import pkg/questionable
import pkg/questionable/results
from pkg/stew/results as stewResults import get, isErr
from pkg/stew/results as stewResults import isErr
import pkg/upraises
import ./datastore
@ -33,11 +33,10 @@ method contains*(
key: Key): Future[?!bool] {.async, locks: "unknown".} =
for store in self.stores:
let
containsRes = await store.contains(key)
without contain =? await store.contains(key), error:
return failure error
if containsRes.isErr: return containsRes
if containsRes.get == true: return success true
if contain: return success true
return success false
@ -61,12 +60,15 @@ method get*(
bytesOpt: ?seq[byte]
for store in self.stores:
let
getRes = await store.get(key)
# the following commented line does not produce the expected result at runtime:
# without bytesOpt =? await store.get(key), error:
if getRes.isErr: return getRes
# instead we use intermediate identifier `bopt`
without bOpt =? await store.get(key), error:
return failure error
bytesOpt = getRes.get
# and now assign `bopt` value to `bytesOpt`
bytesOpt = bOpt
# put found data into stores logically in front of the current store
if bytes =? bytesOpt:
@ -75,7 +77,7 @@ method get*(
let
putRes = await s.put(key, bytes)
if putRes.isErr: return failure putRes.error.msg
if putRes.isErr: return failure putRes.error
break