-
Notifications
You must be signed in to change notification settings - Fork 8
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 filesystem datastore to async/await #13
Changes from 3 commits
f5cc6c2
0c2cbb3
e80a1d7
5cb05be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,46 @@ | ||
__version__ = '0.3.6' | ||
__author__ = 'Juan Batiz-Benet' | ||
__email__ = 'juan@benet.ai' | ||
""" | ||
Datastore is a generic layer of abstraction for data store and database access. | ||
It is a **simple** API with the aim to enable application development in a | ||
datastore-agnostic way, allowing datastores to be swapped seamlessly without | ||
changing application code. Thus, one can leverage different datastores with | ||
different strengths without committing the application to one datastore | ||
throughout its lifetime. | ||
""" | ||
|
||
from .core import * | ||
from .filesystem import * | ||
__version__ = "0.3.6" | ||
__author__ = "Juan Batiz-Benet, Alexander Schlarb" | ||
__email__ = "juan@benet.ai, alexander@ninetailed.ninja" | ||
__all__ = ( | ||
"Key", "Namespace", | ||
"BinaryNullDatastore", "BinaryDictDatastore", | ||
"ObjectNullDatastore", "ObjectDictDatastore", | ||
"Query", "Cursor", | ||
"SerializerAdapter", | ||
|
||
"abc", "typing", "util" | ||
) | ||
|
||
|
||
# import core.key | ||
from .core.key import Key | ||
from .core.key import Namespace | ||
|
||
# import core.binarystore, core.objectstore | ||
from .core.binarystore import NullDatastore as BinaryNullDatastore | ||
from .core.binarystore import DictDatastore as BinaryDictDatastore | ||
|
||
from .core.objectstore import NullDatastore as ObjectNullDatastore | ||
from .core.objectstore import DictDatastore as ObjectDictDatastore | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will also have to expose FileSystemDatastore and FileReader There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My thought was that the filesystem datastore has to be explicitly imported using
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay 👍 |
||
# import core.query | ||
from .core.query import Query | ||
from .core.query import Cursor | ||
|
||
# import core.serialize | ||
from .core.serialize import SerializerAdapter | ||
|
||
|
||
### Exposed submodules ### | ||
from . import abc | ||
from . import typing | ||
from . import util |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,11 +35,11 @@ def encode(self, value): | |
|
||
|
||
def check_length(self, length: int) -> None: | ||
try: | ||
for sn in self.stores: | ||
assert len(sn) == length | ||
except TypeError: | ||
pass | ||
for sn in self.stores: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
try: | ||
assert len(sn) == length # type: ignore[arg-type] | ||
except TypeError: | ||
pass | ||
|
||
|
||
async def subtest_remove_nonexistent(self) -> None: | ||
|
@@ -60,11 +60,12 @@ async def subtest_remove_nonexistent(self) -> None: | |
|
||
async def subtest_insert_elems(self) -> None: | ||
sn: DS | ||
key: datastore.Key | ||
value: int | ||
|
||
# insert numelems elems | ||
for value in range(0, self.numelems): | ||
key: datastore.Key = self.pkey.child(value) | ||
key = self.pkey.child(value) | ||
for sn in self.stores: | ||
assert not await sn.contains(key) | ||
await sn.put(key, self.encode(value)) | ||
|
@@ -75,19 +76,20 @@ async def subtest_insert_elems(self) -> None: | |
self.check_length(self.numelems) | ||
|
||
for value in range(0, self.numelems): | ||
key: datastore.Key = self.pkey.child(value) | ||
key = self.pkey.child(value) | ||
for sn in self.stores: | ||
assert await sn.contains(key) | ||
assert await sn.get_all(key) == self.encode(value) | ||
|
||
self.check_length(self.numelems) | ||
|
||
|
||
@typing.no_type_check #FIXME: This method is broken | ||
async def check_query(self, query, total, slice) -> datastore.Cursor: | ||
assert not self.is_binary # Queries are only supported for object stores | ||
|
||
allitems: List[int] = list(range(0, total)) | ||
sn: datastore.ObjectDatastore | ||
allitems: typing.List[int] = list(range(0, total)) | ||
sn: datastore.abc.ObjectDatastore | ||
resultset: datastore.Cursor | ||
|
||
for sn in self.stores: | ||
|
@@ -110,11 +112,12 @@ async def check_query(self, query, total, slice) -> datastore.Cursor: | |
return resultset | ||
|
||
|
||
@typing.no_type_check #FIXME: This method is broken | ||
async def subtest_queries(self) -> None: | ||
if self.is_binary: | ||
return # Not supported on binary datastores | ||
|
||
sn: datastore.ObjectDatastore | ||
sn: datastore.abc.ObjectDatastore | ||
value: int | ||
|
||
for value in range(0, self.numelems): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work exposing those Classes directly.