Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to nim 2 x #75

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
os: windows,
shell: msys2
}
nim: [1.6.18]
nim: [1.6.18, 2.0.14]
name: ${{ matrix.platform.icon }} ${{ matrix.platform.label }} - Nim v${{ matrix.nim }}
runs-on: ${{ matrix.platform.os }}-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ nimcache
TODO
nimble.develop
nimble.paths
nimbledeps
4 changes: 4 additions & 0 deletions config.nims
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ when (NimMajor, NimMinor) > (1, 2):
when withDir(thisDir(), system.fileExists("nimble.paths")):
include "nimble.paths"
# end Nimble config

when (NimMajor, NimMinor) >= (2, 0):
--mm:refc

10 changes: 5 additions & 5 deletions datastore.nimble
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mode = ScriptMode.Verbose

packageName = "datastore"
version = "0.1.1"
version = "0.2.0"
author = "Status Research & Development GmbH"
description = "Simple, unified API for multiple data stores"
license = "Apache License 2.0 or MIT"
Expand All @@ -10,10 +10,10 @@ requires "nim >= 1.2.0",
"asynctest >= 0.5.2 & < 0.6.0",
"chronos >= 4.0.3 & < 5.0.0",
"questionable >= 0.10.15 & < 0.11.0",
"sqlite3_abi",
"leveldbstatic >= 0.1.6",
"stew",
"unittest2"
"sqlite3_abi == 3.47.0.0",
"leveldbstatic#0bd875d2b76c5b02c771fc1de136826dae6802c6",
"stew >= 0.2.0",
"unittest2 >= 0.2.3"

task coverage, "generates code coverage report":
var (output, exitCode) = gorgeEx("which lcov")
Expand Down
16 changes: 8 additions & 8 deletions datastore/datastore.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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, locks: "unknown".} =
method has*(self: Datastore, key: Key): Future[?!bool] {.base, gcsafe, locks: "unknown".} =
raiseAssert("Not implemented!")

method delete*(self: Datastore, key: Key): Future[?!void] {.base, locks: "unknown".} =
method delete*(self: Datastore, key: Key): Future[?!void] {.base, gcsafe, locks: "unknown".} =
raiseAssert("Not implemented!")

method delete*(self: Datastore, keys: seq[Key]): Future[?!void] {.base, locks: "unknown".} =
method delete*(self: Datastore, keys: seq[Key]): Future[?!void] {.base, gcsafe, locks: "unknown".} =
raiseAssert("Not implemented!")

method get*(self: Datastore, key: Key): Future[?!seq[byte]] {.base, locks: "unknown".} =
method get*(self: Datastore, key: Key): Future[?!seq[byte]] {.base, gcsafe, locks: "unknown".} =
raiseAssert("Not implemented!")

method put*(self: Datastore, key: Key, data: seq[byte]): Future[?!void] {.base, locks: "unknown".} =
method put*(self: Datastore, key: Key, data: seq[byte]): Future[?!void] {.base, gcsafe, locks: "unknown".} =
raiseAssert("Not implemented!")

method put*(self: Datastore, batch: seq[BatchEntry]): Future[?!void] {.base, locks: "unknown".} =
method put*(self: Datastore, batch: seq[BatchEntry]): Future[?!void] {.base, gcsafe, locks: "unknown".} =
raiseAssert("Not implemented!")

method close*(self: Datastore): Future[?!void] {.base, async, locks: "unknown".} =
Expand All @@ -46,15 +46,15 @@ method query*(
proc contains*(self: Datastore, key: Key): Future[bool] {.async.} =
return (await self.has(key)) |? false

method modify*(self: Datastore, key: Key, fn: Modify): Future[?!void] {.base, locks: "unknown".} =
method modify*(self: Datastore, key: Key, fn: Modify): Future[?!void] {.base, gcsafe, locks: "unknown".} =
## Concurrently safe way of modifying the value associated with the `key`.
##
## Same as `modifyGet`, but this takes `fn` that doesn't produce any auxillary value.
##

raiseAssert("Not implemented!")

method modifyGet*(self: Datastore, key: Key, fn: ModifyGet): Future[?!seq[byte]] {.base, locks: "unknown".} =
method modifyGet*(self: Datastore, key: Key, fn: ModifyGet): Future[?!seq[byte]] {.base, gcsafe, locks: "unknown".} =
## Concurrently safe way of updating value associated with the `key`. Returns auxillary value on
## successful update.
##
Expand Down
2 changes: 1 addition & 1 deletion datastore/leveldb/leveldbds.nim
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ proc getQueryString(query: Query): string =
result = $(query.key)
let toTrim = ["/*", "\\*"]
for trim in toTrim:
if result.endswith(trim):
if result.endsWith(trim):
result = result[0 ..< ^(trim.len)]

method query*(
Expand Down
2 changes: 1 addition & 1 deletion datastore/mountedds.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type
MountedDatastore* = ref object of Datastore
stores*: Table[Key, MountedStore]

method mount*(self: MountedDatastore, key: Key, store: Datastore): ?!void {.base.} =
method mount*(self: MountedDatastore, key: Key, store: Datastore): ?!void {.base, gcsafe.} =
## Mount a store on a namespace - namespaces are only `/`
##

Expand Down
26 changes: 18 additions & 8 deletions datastore/sql/sqliteutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ template dispose*(db: SQLite) =

template dispose*(sqliteStmt: SQLiteStmt) =
doAssert SQLITE_OK == sqlite3_finalize(RawStmtPtr(sqliteStmt))
sqliteStmt = nil
# nil literals can no longer be directly assigned to variables or fields of distinct pointer types.
# They must be converted instead.
# See https://nim-lang.org/blog/2022/12/21/version-20-rc.html#:~:text=nil%20literals%20can%20no%20longer%20be%20directly%20assigned%20to%20variables%20or%20fields%20of%20distinct%20pointer%20types.%20They%20must%20be%20converted%20instead.
# SQLiteStmt(nil) is generating a SIGSEGV, so we need to cast it
sqliteStmt = cast[typeof sqliteStmt](nil)

proc release*[T](x: var AutoDisposed[T]): T =
result = x.val
Expand Down Expand Up @@ -237,7 +241,10 @@ proc query*[P](

case v
of SQLITE_ROW:
onData(s)
try:
onData(s)
except Exception as err:
return failure("sqliteutils.query (stmt) exception: " & $err.msg)
res = success true
of SQLITE_DONE:
break
Expand All @@ -256,11 +263,14 @@ proc query*(
query: string,
onData: DataProc): ?!bool =

var
s = ? NoParamsStmt.prepare(env, query)
res = s.query((), onData)
var s = ? NoParamsStmt.prepare(env, query)

# NB: dispose of the prepared query statement and free associated memory
s.dispose
try:
var res = s.query((), onData)
return res
except Exception as err:
return failure("sqliteutils.query (env) exception: " & $err.msg)
finally:
# NB: dispose of the prepared query statement and free associated memory
s.dispose

res
8 changes: 4 additions & 4 deletions tests/datastore/leveldb/testleveldbds.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ suite "Test Basic LevelDbDatastore":
otherBytes = "some other bytes".toBytes

setupAll:
createdir(tempDir)
createDir(tempDir)

teardownAll:
(await ds.close()).tryGet()
Expand All @@ -40,7 +40,7 @@ suite "Test LevelDB Query":
var ds: LevelDbDatastore

setup:
createdir(tempDir)
createDir(tempDir)
ds = LevelDbDatastore.new(tempDir).tryGet()

teardown:
Expand All @@ -57,7 +57,7 @@ suite "Test LevelDB Typed Query":
var ds: LevelDbDatastore

setup:
createdir(tempDir)
createDir(tempDir)
ds = LevelDbDatastore.new(tempDir).tryGet()

teardown:
Expand Down Expand Up @@ -87,7 +87,7 @@ suite "LevelDB Query: keys should disregard trailing wildcards":
val3 = "value for 3".toBytes

setup:
createdir(tempDir)
createDir(tempDir)
ds = LevelDbDatastore.new(tempDir).tryGet()
(await ds.put(key1, val1)).tryGet
(await ds.put(key2, val2)).tryGet
Expand Down
Loading