igorbenav / fastcrud

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

Supporting geoalchemy2 #74

Open neatek opened 6 months ago

neatek commented 6 months 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 6 months ago

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

neatek commented 6 months 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.

ciaran-nolan commented 1 month ago

I'm in a similar position to you, what was your workaround to handle point objects?

igorbenav commented 1 month ago

Hey, guys, sorry for the long delay here. I'll see if I can add this support after I finish stuff for 0.15. There were a lot of stuff that needed fixing or improving before adding this support

neatek commented 1 month ago

I'm in a similar position to you, what was your workaround to handle point objects?

writing my own query to databases using : func.ST_AsText(models.MyModel.location).label("location"), also ST_Distance for distance filter it will return string POINT(x, y)