def _build_geojson_select(statement): """ See usages below. """ # this is basically a translation of the postgis ST_AsGeoJSON example into sqlalchemy/geoalchemy2 return func.json_build_object( "type", "FeatureCollection", "features", func.json_agg(func.ST_AsGeoJSON(statement.subquery(), maxdecimaldigits=5).cast(JSON)), )
def json_agg(query): return session.session.query(func.json_agg(literal_column("row"))) \ .select_from(Alias(query.subquery(), "row"))
def json_agg_core(selectable): return select([func.json_agg(literal_column("row"))]) \ .select_from(selectable.alias("row"))