Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 32 additions & 32 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,40 @@ jobs:

strategy:
matrix:
python-version: [ '3.9', '3.11' ]
sqlalchemy-version: [ '1.4' ]
python-version: ["3.9", "3.11", "3.13"]
sqlalchemy-version: ["1.4"]
include:
- sqlalchemy-version: '1.4'
sqlalchemy-lt-version: '2.0'
flask-sqlalchemy-version: '3.0'
flask-sqlalchemy-lt-version: '4.0'
flask-version: '3.0'
flask-lt-version: '4.0'
- sqlalchemy-version: "1.4"
sqlalchemy-lt-version: "2.0"
flask-sqlalchemy-version: "3.0"
flask-sqlalchemy-lt-version: "4.0"
flask-version: "3.0"
flask-lt-version: "4.0"

name: Python ${{ matrix.python-version }} - SQLAlchemy ${{ matrix.sqlalchemy-version }}

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -e .[tests] pytest-cov \
"sqlalchemy>=${{ matrix.sqlalchemy-version }},<${{ matrix.sqlalchemy-lt-version }}" \
"flask-sqlalchemy>=${{ matrix.flask-sqlalchemy-version }},<${{ matrix.flask-sqlalchemy-lt-version }}" \
"flask>=${{ matrix.flask-version }},<${{ matrix.flask-lt-version }}"

- name: Test with pytest
run: |
pytest -v --cov --cov-report xml

- name: Upload coverage to Codecov
if: ${{ matrix.python-version == '3.11' && matrix.sqlalchemy-version == '1.4'}}
uses: codecov/codecov-action@v3
with:
flags: pytest
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -e .[tests] pytest-cov \
"sqlalchemy>=${{ matrix.sqlalchemy-version }},<${{ matrix.sqlalchemy-lt-version }}" \
"flask-sqlalchemy>=${{ matrix.flask-sqlalchemy-version }},<${{ matrix.flask-sqlalchemy-lt-version }}" \
"flask>=${{ matrix.flask-version }},<${{ matrix.flask-lt-version }}"

- name: Test with pytest
run: |
pytest -v --cov --cov-report xml

- name: Upload coverage to Codecov
if: ${{ matrix.python-version == '3.11' && matrix.sqlalchemy-version == '1.4'}}
uses: codecov/codecov-action@v3
with:
flags: pytest
29 changes: 29 additions & 0 deletions src/utils_flask_sqla_geo/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from flask import jsonify
from marshmallow import fields

Expand Down Expand Up @@ -52,3 +53,31 @@ def geojsonify(*args, **kwargs):
response = jsonify(*args, **kwargs)
response.mimetype = "application/geo+json"
return response


def rows_to_geojson(rows, geom_field):
features = []

for row in rows:
row = row._mapping # SQLAlchemy Row → dict-like

geom = row.get(geom_field)
if geom:
geometry = json.loads(geom) if isinstance(geom, str) else geom
else:
geometry = None

properties = {k: v for k, v in row.items() if k != geom_field}

features.append(
{
"type": "Feature",
"geometry": geometry,
"properties": properties,
}
)

return {
"type": "FeatureCollection",
"features": features,
}
Loading