Giter Club home page Giter Club logo

Comments (1)

geospatial-jeff avatar geospatial-jeff commented on August 23, 2024

For context, the initial postgresql application logic (PostgresCoreClient et al) was written ~1 year ago in a different repo and refactored very slightly to accommodate the api layer which was added when this project was open sourced (#1). The original application used a FastAPI dependency to inject the required resources and code into the application.

There are some problems with the current implementation which are blocking development on other things (notably #57 #58 #64) - in no particular order:

  1. PostgresClient is overloaded. It defines methods for database operations like committing, checking if a row exists etc. but these are very opinionated and don't always work for our various use cases. Overloading of functionality in this particular class means we use it everywhere, even when it doesn't make much sense to do so. It's also just very abstracted, making development hard.
  2. We are using dataclass when we really need to be using attrs. Mostly because attrs is more flexible when it comes to the definition of optional and optionally required attributes.
  3. Defaulting to the sqlalchemy models defined by the library is weird and causes some not so intuitive behavior, especially when writing certain test cases (#70). It is also poor separation of concerns.
  4. I'm really on the fence about allowing sqlalchemy models to be instance attributes of a class. I'm not sure its bad, but I think there is a better way of doing it.
  5. The separation of pagination logic from the core is also very abstracted, and should be brought into core anyways to align with the spec (#67).
  6. Coupling of resource management and application logic makes #57 a nightmare.

What I'm going for with the refactor:

  1. Separation of resource management from application logic. This blog post has an interesting implementation using a mixin, not sure if we will take the same approach but its good food for thought. Sqlalchemy models, database configuration etc. are owned by the api layer and passed down to the application logic, preferably in a separate class which is responsible for resource management across the various backends.
  2. Don't worry about DRY. I'd rather have each database operation manage its own commits and deduplicate code as needed in the future. This should make the codebase much simpler, while making it obvious where abstraction of database operations really adds value.
  3. Use the newest version of sqlalchemy with support for async (#64)

I do think the base clients which define the interfaces are good, they follow the spec which is all that matters. Just that our postgres/canonical implementation of this interface is currently not that great.

from stac-fastapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.