internetofwater / nldi-services

Network Linked Data Index Navigation Web Services
https://waterdata.usgs.gov/blog/nldi-intro/
Creative Commons Zero v1.0 Universal
19 stars 15 forks source link

SQLAlchemy connector #381

Open webb-ben opened 1 year ago

webb-ben commented 1 year ago

User story

As an NLDI Admin, I want to connect to the nldi-database via SQLAlchemy so that I am able to using python framework to structure and process the API request.

Acceptance criteria

Definition of done

gzt5142 commented 1 year ago

An example of a sqlalchemy connection and ORM for this database is here:

data access layer -- a convenience object to hold db connect details: https://github.com/gzt5142/nldi-crawler-py/blob/7e0aa4c6230c983a4931561ab6322c2d68ece527/src/nldi_crawler/db.py#L28

The ORM is used in two places in the crawler:

I've chosen a 'classic' binding mechanism to map a table to a simplified dataclass (rather than subclassing DeclarativeBase). This makes the ORM dependent on the dataclass rather than the other way around. Code which manipulates the feature dataclass is protected from knowing sql details this way.