From 39a1a2a7e018af2a768f4371be52c34fa05af50c Mon Sep 17 00:00:00 2001 From: smohiudd Date: Wed, 21 Feb 2024 14:04:44 -0500 Subject: [PATCH 1/3] db connect kwargs --- titiler/pgstac/db.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/titiler/pgstac/db.py b/titiler/pgstac/db.py index 8566d910..00665ade 100644 --- a/titiler/pgstac/db.py +++ b/titiler/pgstac/db.py @@ -1,6 +1,6 @@ """Database connection handling.""" -from typing import Optional +from typing import Dict, Optional from fastapi import FastAPI from psycopg_pool import ConnectionPool @@ -9,7 +9,11 @@ async def connect_to_db( - app: FastAPI, settings: Optional[PostgresSettings] = None + app: FastAPI, + settings: Optional[PostgresSettings] = None, + kwargs: Dict[str, str] = { + "options": "-c search_path=pgstac,public -c application_name=pgstac" + }, ) -> None: """Connect to Database.""" if not settings: @@ -22,7 +26,7 @@ async def connect_to_db( 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=kwargs, ) # Make sure the pool is ready From bbd572cfc2d4e4af56694b28f265e1218640c027 Mon Sep 17 00:00:00 2001 From: smohiudd Date: Wed, 21 Feb 2024 14:07:34 -0500 Subject: [PATCH 2/3] update dict type --- titiler/pgstac/db.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/titiler/pgstac/db.py b/titiler/pgstac/db.py index 00665ade..23f6fa65 100644 --- a/titiler/pgstac/db.py +++ b/titiler/pgstac/db.py @@ -1,6 +1,6 @@ """Database connection handling.""" -from typing import Dict, Optional +from typing import Any, Dict, Optional from fastapi import FastAPI from psycopg_pool import ConnectionPool @@ -11,7 +11,7 @@ async def connect_to_db( app: FastAPI, settings: Optional[PostgresSettings] = None, - kwargs: Dict[str, str] = { + kwargs: Dict[str, Any] = { "options": "-c search_path=pgstac,public -c application_name=pgstac" }, ) -> None: From d19767c8dd75ebdf18c22d4d5acdf5d602771ded Mon Sep 17 00:00:00 2001 From: smohiudd Date: Wed, 21 Feb 2024 14:32:33 -0500 Subject: [PATCH 3/3] changes to pool default kwargs --- titiler/pgstac/db.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/titiler/pgstac/db.py b/titiler/pgstac/db.py index 23f6fa65..dd7933e4 100644 --- a/titiler/pgstac/db.py +++ b/titiler/pgstac/db.py @@ -11,14 +11,18 @@ async def connect_to_db( app: FastAPI, settings: Optional[PostgresSettings] = None, - kwargs: Dict[str, Any] = { - "options": "-c search_path=pgstac,public -c application_name=pgstac" - }, + 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, @@ -26,7 +30,7 @@ async def connect_to_db( max_waiting=settings.db_max_queries, max_idle=settings.db_max_idle, num_workers=settings.db_num_workers, - kwargs=kwargs, + kwargs=pool_kwargs, ) # Make sure the pool is ready