introduce methods close and query in the base API and refactor accordingly #27
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The goal of this PR is to make
Datastore
and derived types more flexible, e.g. in nim-libp2p-dht we want to specifyproviders: Datastore
instead ofproviders: SQLiteDatastore
and have the freedom to choose one implementation or another without having to change the type definition (see codex-storage/nim-codex-dht#41 (comment)).method close
is introduced in a similar manner as was done forBlockStore
in codex-storage/nim-codex#160.method query
required a bit more experimentation, but the end result seems viable. The challenge is that Nim'siterator
does not support the dynamic dispatch ofmethod
. However, we can specify a single return type (seetype QueryImpl
in this PR) for implementations ofmethod query
, and then in the returnedqueryImpl
iterator use object conversion to get back to the correct specific type derived fromDatastore
.I did a small amount of additional cleanup, e.g. it's not necessary to specify the
async
pragma in base methods ofDatastore
.In the tests for
SQLiteDatastore
, in some places I had to change the name of a variablekey
to something else (I choserkey
) otherwise I was getting compile-time errors from clang/gcc:I've seen similar previously, I believe it's owing to a bug/limitation in Nim's compiler.
Closes #28.