Skip to content

Commit

Permalink
Merge pull request #155 from smohiudd/fix/db-connect-kwargs
Browse files Browse the repository at this point in the history
Change db connection kwargs default
  • Loading branch information
vincentsarago authored Feb 21, 2024
2 parents 1151835 + d19767c commit 61d5324
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions titiler/pgstac/db.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Database connection handling."""

from typing import Optional
from typing import Any, Dict, Optional

from fastapi import FastAPI
from psycopg_pool import ConnectionPool
Expand All @@ -9,20 +9,28 @@


async def connect_to_db(
app: FastAPI, settings: Optional[PostgresSettings] = None
app: FastAPI,
settings: Optional[PostgresSettings] = None,
pool_kwargs: Optional[Dict[str, Any]] = None,
) -> None:
"""Connect to Database."""
if not settings:
settings = PostgresSettings()

pool_kwargs = (
pool_kwargs
if pool_kwargs is not None
else {"options": "-c search_path=pgstac,public -c application_name=pgstac"}
)

app.state.dbpool = ConnectionPool(
conninfo=str(settings.database_url),
min_size=settings.db_min_conn_size,
max_size=settings.db_max_conn_size,
max_waiting=settings.db_max_queries,
max_idle=settings.db_max_idle,
num_workers=settings.db_num_workers,
kwargs={"options": "-c search_path=pgstac,public -c application_name=pgstac"},
kwargs=pool_kwargs,
)

# Make sure the pool is ready
Expand Down

0 comments on commit 61d5324

Please sign in to comment.