Replace the legacy Session.query() API #17
1 changed files with 2 additions and 2 deletions
Count with .scalar_one() in velofy.console.gridify
A `COUNT` always returns exactly one row; `.scalar_one()` is typed as `int` and is used for all other counts as well.
commit
bc2e3f439d
|
|
@ -38,11 +38,11 @@ def gridify() -> None: # pragma: no cover note:b1f68d24
|
|||
# Because the number of assigned addresses is the same across
|
||||
# different `side_length`s, we can take the last `grid` from the `city`.
|
||||
last_grid_id = grid.id # type: ignore[possibly-undefined]
|
||||
n_assigned = db.session.scalar(
|
||||
n_assigned = db.session.execute(
|
||||
sa.select(sa.func.count())
|
||||
.select_from(db.AddressPixelAssociation)
|
||||
.where(db.AddressPixelAssociation.grid_id == last_grid_id),
|
||||
)
|
||||
).scalar_one()
|
||||
click.echo(
|
||||
f"=> Assigned {n_assigned} out of {len(city.addresses)} addresses in {city.name}", # noqa:E501
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue