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

cleanup results import and some warnings #64

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ coverage
datastore.nims
nimcache
TODO
nimble.develop
nimble.paths
4 changes: 4 additions & 0 deletions config.nims
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ when (NimMajor, NimMinor) == (1, 2):

when (NimMajor, NimMinor) > (1, 2):
switch("hint", "XCannotRaiseY:off")
# begin Nimble config (version 2)
when withDir(thisDir(), system.fileExists("nimble.paths")):
include "nimble.paths"
# end Nimble config
3 changes: 1 addition & 2 deletions datastore.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ requires "nim >= 1.2.0",
"sqlite3_abi",
"leveldbstatic >= 0.1.2",
"stew",
"unittest2",
"upraises >= 0.1.0 & < 0.2.0"
"unittest2"

task coverage, "generates code coverage report":
var (output, exitCode) = gorgeEx("which lcov")
Expand Down
7 changes: 3 additions & 4 deletions datastore/datastore.nim
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
{.push raises: [].}

import pkg/chronos
import pkg/questionable
import pkg/questionable/results
import pkg/upraises

import ./key
import ./query
import ./types

export key, query, types

push: {.upraises: [].}

type
BatchEntry* = tuple[key: Key, data: seq[byte]]
Function*[T, U] = proc(value: T): U {.raises: [CatchableError], gcsafe, closure.}
Expand Down Expand Up @@ -76,4 +75,4 @@ method modifyGet*(self: Datastore, key: Key, fn: ModifyGet): Future[?!seq[byte]]
## only the last auxillary value is returned.
##

raiseAssert("Not implemented!")
raiseAssert("Not implemented!")
2 changes: 2 additions & 0 deletions datastore/defaultimpl.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{.push raises: [].}

import pkg/chronos
import pkg/questionable
import pkg/questionable/results
Expand Down
6 changes: 2 additions & 4 deletions datastore/fsds.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{.push raises: [].}

import std/os
import std/options
import std/tables
Expand All @@ -6,16 +8,12 @@ import std/strutils
import pkg/chronos
import pkg/questionable
import pkg/questionable/results
from pkg/stew/results as stewResults import get, isErr
import pkg/upraises

import ./defaultimpl
import ./datastore

export datastore

push: {.upraises: [].}

type
FSDatastore* = ref object of Datastore
root*: string
Expand Down
6 changes: 2 additions & 4 deletions datastore/key/key.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{.push raises: [].}

import std/algorithm
import std/hashes
import std/oids
Expand All @@ -7,15 +9,11 @@ import std/strformat

import pkg/questionable
import pkg/questionable/results
from pkg/stew/results as stewResults import get, isErr
import pkg/upraises

import ./namespace

export hashes, namespace

push: {.upraises: [].}

type
Key* = object
namespaces*: seq[Namespace]
Expand Down
4 changes: 1 addition & 3 deletions datastore/key/namespace.nim
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
{.push raises: [].}

import std/hashes

import pkg/questionable
import pkg/questionable/results
import pkg/upraises

push: {.upraises: [].}

const
Delimiter* = ":"
Expand Down
6 changes: 2 additions & 4 deletions datastore/leveldb/leveldbds.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{.push raises: [].}

import std/options
import std/tables
import std/os
Expand All @@ -8,14 +10,10 @@ import pkg/chronos
import pkg/questionable
import pkg/questionable/results
import pkg/stew/byteutils
from pkg/stew/results as stewResults import isErr
import pkg/upraises

import ../datastore
import ../defaultimpl

push: {.upraises: [].}

type
LevelDbDatastore* = ref object of Datastore
db: LevelDb
Expand Down
7 changes: 3 additions & 4 deletions datastore/mountedds.nim
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
{.push raises: [].}

import std/tables

import pkg/chronos
import pkg/questionable
import pkg/questionable/results
import pkg/upraises

import ./key
import ./query
import ./datastore

export key, query

push: {.upraises: [].}

type
MountedStore* = object
store*: Datastore
Expand All @@ -28,7 +27,7 @@ method mount*(self: MountedDatastore, key: Key, store: Datastore): ?!void {.base
if key in self.stores:
return failure("Key already has store mounted!")

self.stores.add(key, MountedStore(store: store, key: key))
self.stores[key] = MountedStore(store: store, key: key)

return success()

Expand Down
10 changes: 6 additions & 4 deletions datastore/query.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import pkg/upraises

{.push raises: [].}

import pkg/chronos
import pkg/questionable
import pkg/questionable/results
Expand All @@ -21,8 +23,8 @@ type
QueryResponse* = tuple[key: ?Key, data: seq[byte]]
QueryEndedError* = object of DatastoreError

GetNext* = proc(): Future[?!QueryResponse] {.upraises: [], gcsafe, closure.}
IterDispose* = proc(): Future[?!void] {.upraises: [], gcsafe.}
GetNext* = proc(): Future[?!QueryResponse] {.raises: [], gcsafe, closure.}
IterDispose* = proc(): Future[?!void] {.raises: [], gcsafe.}
QueryIter* = ref object
finished*: bool
next*: GetNext
Expand All @@ -32,7 +34,7 @@ iterator items*(q: QueryIter): Future[?!QueryResponse] =
while not q.finished:
yield q.next()

proc defaultDispose(): Future[?!void] {.upraises: [], gcsafe, async.} =
proc defaultDispose(): Future[?!void] {.gcsafe, async.} =
return success()

proc new*(T: type QueryIter, dispose = defaultDispose): T =
Expand Down
6 changes: 2 additions & 4 deletions datastore/sql/sqliteds.nim
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
{.push raises: [].}

import std/times
import std/options

import pkg/chronos
import pkg/questionable
import pkg/questionable/results
import pkg/sqlite3_abi
from pkg/stew/results as stewResults import isErr
import pkg/upraises

import ../datastore
import ./sqlitedsdb
import ./sqliteutils

export datastore, sqlitedsdb

push: {.upraises: [].}

type
SQLiteDatastore* = ref object of Datastore
readOnly: bool
Expand Down
11 changes: 6 additions & 5 deletions datastore/sql/sqlitedsdb.nim
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{.push raises: [].}

import std/os
import std/strformat

import pkg/questionable
import pkg/questionable/results
import pkg/upraises

import ./sqliteutils

type
BoundIdCol* = proc (): string {.closure, gcsafe, upraises: [].}
BoundVersionCol* = proc (): int64 {.closure, gcsafe, upraises: [].}
BoundDataCol* = proc (): seq[byte] {.closure, gcsafe, upraises: [].}
BoundTimestampCol* = proc (): int64 {.closure, gcsafe, upraises: [].}
BoundIdCol* = proc (): string {.closure, gcsafe, raises: [].}
BoundVersionCol* = proc (): int64 {.closure, gcsafe, raises: [].}
BoundDataCol* = proc (): seq[byte] {.closure, gcsafe, raises: [].}
BoundTimestampCol* = proc (): int64 {.closure, gcsafe, raises: [].}

# feels odd to use `void` for prepared statements corresponding to SELECT
# queries but it fits with the rest of the SQLite wrapper adapted from
Expand Down
7 changes: 3 additions & 4 deletions datastore/sql/sqliteutils.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{.push raises: [].}

import pkg/questionable
import pkg/questionable/results
import pkg/sqlite3_abi
import pkg/upraises

export sqlite3_abi

Expand All @@ -14,8 +15,6 @@ export sqlite3_abi
# e.g. `nimble test --forceBuild:on`
{.passc: "-DSQLITE_ENABLE_COLUMN_METADATA".}

push: {.upraises: [].}

type
AutoDisposed*[T: ptr|ref] = object
val*: T
Expand All @@ -34,7 +33,7 @@ type

# see https://github.com/arnetheduck/nim-sqlite3-abi/issues/4
sqlite3_destructor_type_gcsafe =
proc (a1: pointer) {.cdecl, gcsafe, upraises: [].}
proc (a1: pointer) {.cdecl, gcsafe, raises: [].}

const
SQLITE_TRANSIENT_GCSAFE* = cast[sqlite3_destructor_type_gcsafe](-1)
Expand Down
6 changes: 2 additions & 4 deletions datastore/tieredds.nim
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
{.push raises: [].}

import std/sequtils

import pkg/chronos
import pkg/questionable
import pkg/questionable/results
from pkg/stew/results as stewResults import get, isErr
import pkg/upraises

import ./datastore

export datastore

push: {.upraises: [].}

type
TieredDatastore* = ref object of Datastore
stores: seq[Datastore]
Expand Down
2 changes: 2 additions & 0 deletions datastore/typedds.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{.push raises: [].}

import std/options
import std/macros

Expand Down
3 changes: 0 additions & 3 deletions tests/datastore/dscommontests.nim
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import std/options

import pkg/asynctest
import pkg/chronos
import pkg/stew/results

import pkg/datastore

Expand Down
1 change: 0 additions & 1 deletion tests/datastore/leveldb/testleveldbds.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ from std/algorithm import sort, reversed

import pkg/asynctest
import pkg/chronos
import pkg/stew/results
import pkg/stew/byteutils

import pkg/datastore
Expand Down
1 change: 0 additions & 1 deletion tests/datastore/modifycommontests.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import std/options
import std/sugar
import std/random
import std/sequtils
import std/strutils

import pkg/asynctest
import pkg/chronos
Expand Down
9 changes: 0 additions & 9 deletions tests/datastore/querycommontests.nim
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
import std/options
import std/sequtils
from std/algorithm import sort, reversed

import pkg/asynctest
import pkg/chronos
import pkg/stew/results
import pkg/stew/byteutils

import pkg/datastore

template queryTests*(ds: Datastore, testLimitsAndOffsets = true, testSortOrder = true) {.dirty.} =
Expand Down
1 change: 0 additions & 1 deletion tests/datastore/sql/testsqliteds.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ from std/algorithm import sort, reversed

import pkg/asynctest
import pkg/chronos
import pkg/stew/results
import pkg/stew/byteutils

import pkg/datastore/sql/sqliteds
Expand Down
1 change: 0 additions & 1 deletion tests/datastore/testdatastore.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import std/options

import pkg/asynctest/unittest2
import pkg/chronos
import pkg/stew/results

import pkg/datastore

Expand Down
1 change: 0 additions & 1 deletion tests/datastore/testfsds.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ from std/algorithm import sort, reversed

import pkg/asynctest
import pkg/chronos
import pkg/stew/results
import pkg/stew/byteutils

import pkg/datastore/fsds
Expand Down
3 changes: 0 additions & 3 deletions tests/datastore/testkey.nim
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,6 @@ suite "Key":
key.reverse.field == "a"

test "key root":
let
key = Key.init("/a:b/c/d:e").tryGet()

check:
Key.init(":b").tryGet().root
not Key.init(":b/c").tryGet().root
Expand Down
1 change: 0 additions & 1 deletion tests/datastore/testmountedds.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import std/tables

import pkg/asynctest
import pkg/chronos
import pkg/stew/results
import pkg/stew/byteutils

import pkg/datastore/mountedds
Expand Down
1 change: 0 additions & 1 deletion tests/datastore/testtieredds.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import std/os

import pkg/asynctest
import pkg/chronos
import pkg/stew/results
import pkg/stew/byteutils

import pkg/datastore/fsds
Expand Down
Loading