-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: initial skeleton for Client and Backend
- Loading branch information
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
""" | ||
Base superscore data storage backend interface | ||
""" | ||
from typing import Any, Generator | ||
from uuid import UUID | ||
|
||
from ..model import Entry | ||
|
||
|
||
class _Backend: | ||
""" | ||
Base class for data storage backend. | ||
""" | ||
def get_entry(self, meta_id: UUID) -> Entry: | ||
"""Get entry with ``meta_id``.""" | ||
raise NotImplementedError | ||
|
||
def save_entry(self, entry: Entry): | ||
"""Save ``entry`` into the database""" | ||
raise NotImplementedError | ||
|
||
def delete_entry(self, entry: Entry) -> None: | ||
""" | ||
Delete ``entry`` from the system (all instances) | ||
""" | ||
raise NotImplementedError | ||
|
||
def update_entry(self, entry: Entry) -> None: | ||
""" | ||
Update ``entry`` in the backend. | ||
Throws BackendError if ``entry`` does not already exist | ||
""" | ||
raise NotImplementedError | ||
|
||
def search(self, **search_kwargs) -> Generator[Any, None, None]: | ||
"""Yield a Entry objects corresponding matching ``search_kwargs``""" | ||
raise NotImplementedError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"""Client for superscore. Used for programmatic interactions with superscore""" | ||
from typing import Any, List | ||
|
||
from superscore.backends.core import _Backend | ||
from superscore.model import Entry | ||
|
||
|
||
class Client: | ||
backend: _Backend | ||
|
||
def __init__(self, backend=None, **kwargs) -> None: | ||
# if backend is None, startup default filestore backend | ||
return | ||
|
||
@classmethod | ||
def from_config(cls, cfg=None): | ||
raise NotImplementedError | ||
|
||
def search(self, **post) -> List[Entry]: | ||
"""Search by key-value pair. Can search by any field, including id""" | ||
return self.backend.search(**post) | ||
|
||
def save(self, entry: Entry): | ||
"""Save information in ``entry`` to database""" | ||
# validate entry is valid | ||
self.backend.save_entry(entry) | ||
|
||
def delete(self, entry: Entry) -> None: | ||
"""Remove item from backend, depending on backend""" | ||
# check for references to ``entry`` in other objects? | ||
self.backend.delete_entry(entry) | ||
|
||
def compare(self, entry_l: Entry, entry_r: Entry) -> Any: | ||
"""Compare two entries. Should be of same type, and return a diff""" | ||
raise NotImplementedError | ||
|
||
def apply(self, entry: Entry): | ||
"""Apply settings found in ``entry``. If no values found, no-op""" | ||
raise NotImplementedError | ||
|
||
def validate(self, entry: Entry): | ||
""" | ||
Validate ``entry`` is properly formed and able to be inserted into | ||
the backend. Includes checks the following: | ||
- dataclass is valid | ||
- reachable from root | ||
- references are not cyclical, and type-correct | ||
""" | ||
raise NotImplementedError |