Skip to content

Commit

Permalink
Merge pull request #53 from alukach/feature/customize-settings
Browse files Browse the repository at this point in the history
Support providing postgres settings via argument
  • Loading branch information
vincentsarago authored May 2, 2022
2 parents 1c5bd82 + 797470a commit 1b570c2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
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 (author @alukach, https://github.com/stac-utils/titiler-pgstac/pull/53)


## 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
) -> 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

0 comments on commit 1b570c2

Please sign in to comment.