Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support providing postgres settings via argument #53

Merged
merged 7 commits into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## Unreleased

* Insert mosaic metadata `min/max zoom` and `bounds` in tilejson
* allow users the ability to optionally provide `PostgresSettings` to `connect_to_db()` function in the event that they want to customize how their DB credentials are populated (https://github.com/stac-utils/titiler-pgstac/pull/53)
vincentsarago marked this conversation as resolved.
Show resolved Hide resolved


## 0.1.0.a7 (2022-04-05) Pre-Release

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async def app():

await conn.close()

await connect_to_db(app)
await connect_to_db(app, settings)
async with AsyncClient(app=app, base_url="http://test") as client:
yield client
await close_db_connection(app)
Expand Down
11 changes: 8 additions & 3 deletions titiler/pgstac/db.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
"""Database connection handling."""

from typing import Optional

from psycopg_pool import ConnectionPool

from titiler.pgstac.settings import PostgresSettings

from fastapi import FastAPI

settings = PostgresSettings()


async def connect_to_db(app: FastAPI) -> None:
async def connect_to_db(
app: FastAPI, settings: Optional[PostgresSettings] = None
alukach marked this conversation as resolved.
Show resolved Hide resolved
) -> None:
"""Connect to Database."""
if not settings:
settings = PostgresSettings()

app.state.dbpool = ConnectionPool(
conninfo=settings.connection_string,
min_size=settings.db_min_conn_size,
Expand Down