-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Provide a SQL (preferably a SQLAlchemy dialect
) interface to query the REST API
#31
Comments
From my initial reading, the way we should approach this is to write a customer adapter for The references the following
as their philosophy for |
adds shillelagh to attempt implementing a sql layer on top of the library and see if it helps with #9 todo items for me are: - see if pyndatic can help define sqlalchemy schema - as per #31 i want to have a sqlclahemy dialect - be able to sync two sources one being the rest endpoints using sqlalchemy
This is awesome! Thanks for the heads up, and let me know if you have any questions, I'm happy to help. |
Quick note for anyone else working with
I figured it would be easier to this before I get into building a SQLAlchemy dialect #9 At first attempt it all looked well and when I ran:
I got the
upon restarting the console, I saw the following, and found that my adapter wasn't registering properly:
Upon inspecting my
And given that it returns the required rows of data, the logs should make it easier to debug the adapter.
|
adds a few lines of logging to discover that the shillelagh adapter wasn't register due to a syntax error in pyproject, this change verifies that we can return rows of data back via the shillelagh adapter note this commit does not query the api for results, this is to come in subsequent commits, read the following comment #31 (comment) for how we got to this solution Refs #31
initially i was implementing a sql interface within the dto objects, as the solution grew it made more sense to be able to consolidate this into the shillelagh extension, ensuring that if the sql interface isn't in use the normal dto isn't burdened by imports i've kept some helper methods to concat dictionaries of annotations, this should not affect the workings of the solution refs #31
using the detail dto_retrieve model to parse the sql responses returned to the shillelagh, things to check post this commit - can we get the detail fields when the user requests a model via where clause - is this the right thing to do (moving away from using the sql_model configuration) removes various TODO markers as appropriate where the issues have been resolved refs #31
@classmethod
def _accumulated_annotations(cls) -> dict:
"""Return a dictionary of all annotations
This method is used to return a dictionary of all the
annotations from itself and it's parent classes.
It is intended for use by the shillelagh extension
"""
annotations = cls.__annotations__.copy() # TODO: should we make copies?
for base in cls.__bases__:
if issubclass(base, BaseModel):
# Copy annotations from classes that are pydantic models
# they are the only things that form part of the response
annotations.update(base.__annotations__)
return annotations.items() This recommendation has changes in Looking at the >>> import typing
>>> typing.get_type_honest(CardholderSummary)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'typing' has no attribute 'get_type_honest'. Did you mean: 'get_type_hints'?
>>> typing.get_type_hints(CardholderSummary)
{'href': <class 'pydantic_core._pydantic_core.Url'>, 'id': <class 'str'>, '_good_known_since': typing.Optional[datetime.datetime], 'first_name': <class 'str'>, 'last_name': <class 'str'>, 'short_name': typing.Optional[str], 'description': typing.Optional[str], 'authorised': <class 'bool'>} We should refactor this method to use a |
As our ambition around the library grows, the sync feature #9 looks to be a lot more useful than I previously imagined. One of my thoughts was to treat this as if they were two databases sources and use a layer like SQLAlchemy to keep them in sync.
Sync is a difficult problem (see also SQL Sync for Schema with SQLAlchemy
python-sync-db) at the best of times. My initial research lead me down the path of writing a SQLAlchemy dialect primarily thinking about if it's possible to wrap a REST service as a SQL source.
I found a number of articles and discussions which leads to believe this is a possible way forward:
Digging through the list of external dialects I found betodealmeida / gsheets-db-api which provides that we can converse with a REST API via a SQLAlchemy dialect. This project links to Shillelagh which is a library is an implementation of the Python DB API 2.0 based on SQLite (using the APSW library)
Other resources:
The requirement is thus to research the above resources and outline the possibility of using a SQLALchemy dialect to write the sync module with the view of being able to use the REST client to communicate with the Gallagher proxy.
Why SQL?
One of the major questions around this is
Why SQL?
, we could head down the route of using an object database. The question to consider is if the end user / customer would benefit from the data being available in an object database?With a foundation of writing to SQL backend we also stand the advantage of writing to / reading from corporate database backends.
The text was updated successfully, but these errors were encountered: