geopython / pygeoapi

pygeoapi is a Python server implementation of the OGC API suite of standards. The project emerged as part of the next generation OGC API efforts in 2018 and provides the capability for organizations to deploy a RESTful OGC API endpoint using OpenAPI, GeoJSON, and HTML. pygeoapi is open source and released under an MIT license.
https://pygeoapi.io
MIT License
460 stars 250 forks source link

Refactor postgresql provider to allow exposing cached engine and table models to other providers #1643

Closed ricardogsilva closed 1 month ago

ricardogsilva commented 2 months ago

Overview

I'm working on an OGC API EDR provider that is backed by a postgresql DB, which coincidentally is the same DB being used for exposing the same resource as an OGC API features collection.

Therefore I would like to reuse the same DB engine and table reflected models as the pygeoapi postgresql features provider. Unfortunately these are not currently exposed to code outside the postgresql feature provider. This PR thus presents a light refactor of the pygeoapi.provider.postgresql.py module, with the intention of letting other providers make use of the engine and table caching facilities.

With this proposed implementation, the private method PostgreSQLProvider._get_engine_and_table_model() is replaced by two public functions:

Both of these functions use the standard lib's functools.cache decorator, ensuring that they are cached.

Dependency policy (RFC2)

Updates to public demo

Contributions and licensing

(as per https://github.com/geopython/pygeoapi/blob/master/CONTRIBUTING.md#contributions-and-licensing)

tomkralidis commented 2 months ago

cc @KoalaGeo for any initial comments.