diff --git a/tipg/database.py b/tipg/database.py index 60f90c6f..edc3bc6c 100644 --- a/tipg/database.py +++ b/tipg/database.py @@ -7,7 +7,7 @@ from buildpg import asyncpg from tipg.logger import logger -from tipg.settings import PostgresSettings +from tipg.settings import DatabaseSettings, PostgresSettings from fastapi import FastAPI @@ -19,6 +19,8 @@ DB_CATALOG_FILE = resources_files(__package__) / "sql" / "dbcatalog.sql" +database_settings = DatabaseSettings() + class connection_factory: """Connection creation.""" @@ -59,12 +61,13 @@ async def __call__(self, conn: asyncpg.Connection): """ ) - # Register custom SQL functions/table/views in pg_temp - for sqlfile in self.user_sql_files: - await conn.execute(sqlfile.read_text()) + if database_settings.write_functions: + # Register custom SQL functions/table/views in pg_temp + for sqlfile in self.user_sql_files: + await conn.execute(sqlfile.read_text()) - # Register TiPG functions in `pg_temp` - await conn.execute(DB_CATALOG_FILE.read_text()) + # Register TiPG functions in `pg_temp` + await conn.execute(DB_CATALOG_FILE.read_text()) async def connect_to_db( diff --git a/tipg/settings.py b/tipg/settings.py index aff9e11c..c9115310 100644 --- a/tipg/settings.py +++ b/tipg/settings.py @@ -177,6 +177,8 @@ class DatabaseSettings(pydantic.BaseSettings): only_spatial_tables: bool = True + write_functions: bool = True + class Config: """model config"""