From df80dc61a1c807171f299c97552e4afb9cc0cd66 Mon Sep 17 00:00:00 2001 From: Remco Meeuwissen Date: Mon, 3 Jul 2023 13:58:35 +0200 Subject: [PATCH 1/2] Added a setting for disabling the writing of sql to the database --- tipg/database.py | 14 ++++++++------ tipg/settings.py | 2 ++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/tipg/database.py b/tipg/database.py index 60f90c6f..a0712f9c 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 PostgresSettings, DatabaseSettings from fastapi import FastAPI @@ -19,6 +19,7 @@ DB_CATALOG_FILE = resources_files(__package__) / "sql" / "dbcatalog.sql" +database_settings = DatabaseSettings() class connection_factory: """Connection creation.""" @@ -59,12 +60,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""" From aa4eeb2ee3870421027ca074db47178625ecbcdf Mon Sep 17 00:00:00 2001 From: Remco Meeuwissen Date: Tue, 4 Jul 2023 13:09:36 +0200 Subject: [PATCH 2/2] Linter fixes --- tipg/database.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tipg/database.py b/tipg/database.py index a0712f9c..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, DatabaseSettings +from tipg.settings import DatabaseSettings, PostgresSettings from fastapi import FastAPI @@ -21,6 +21,7 @@ database_settings = DatabaseSettings() + class connection_factory: """Connection creation."""