igorbenav / fastcrud

FastCRUD is a Python package for FastAPI, offering robust async CRUD operations and flexible endpoint creation utilities.
MIT License
530 stars 32 forks source link

Supporting geoalchemy2 #74

Open neatek opened 1 month ago

neatek commented 1 month ago

The issue arises when using a column with the type Geometry("POINT") from geoalchemy2, as attempting to utilize FastCRUD results in an error: 'utf-8' codec can't decode byte 0xe6 in position 5: invalid continuation byte. It would be beneficial to add support for geoalchemy2. If that's not feasible, is there an alternative approach for handling such a column type? Or is it necessary to write custom queries and routes? As always thank for you answer!

igorbenav commented 1 month ago

Are you talking about the crud methods or the endpoint creation functionalities? Could you please provide some code to reproduce?

neatek commented 1 month ago

Example:

CRUD (routes)

photo_location_crud = FastCRUD(models.PhotoLocation)
photo_location_router = crud_router(
    session=get_session,
    model=models.PhotoLocation,
    crud=photo_location_crud,
    path="/photos",
    tags=["Photos"],
    ...
)

SQLAlchemy Model

from geoalchemy2 import Geometry
class PhotoLocation(Base):
    __tablename__ = "photo_location"
    id = Column(BigInteger, primary_key=True, autoincrement=True)
    ...
    location = Column(
        Geometry("POINT"), nullable=True
    )

Then when I start using get_multi and stuff, it gets binary data by location (POINT), and can't output to get_multi or other routing. It is clear that to process absolutely all possible binary data in the database is almost impossible, probably, but to make support for a point for example I think it is possible.