noirbizarre / flask-restplus

Fully featured framework for fast, easy and documented API development with Flask
http://flask-restplus.readthedocs.org
Other
2.73k stars 506 forks source link

Marshall fields from a session.query #591

Open stev-0 opened 5 years ago

stev-0 commented 5 years ago

I work a lot with geo-stuff, and often data is stored as binary geometry, but converted to a JSON representation for the browser. This poses a problem for flask-restplus - I can't really declare my model as one of the fields is based on a function, but if I write the model as a session.query object, I don't get an object with field names to marshall.

My session query below:

db.session.query(Model.r_id,Model.r_width,Model.r_length,Model.wb_id,func.ST_AsGeoJson(func.ST_Transform(Model.geom,4326))).filter(Model.wb_id == str(wbid)).all()

This gives an array of tuples, without any identifiers.

Is there a way of mapping field positions such as you get as the result of a session.query to a list of field names? Otherwise I have to use database views, which slightly defeats the object of an ORM.

ziirish commented 5 years ago

Hi, do you have any example of what your output looks like and what you expect your API to return?