Skip to content

Add writing setting #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions tipg/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -19,6 +19,8 @@

DB_CATALOG_FILE = resources_files(__package__) / "sql" / "dbcatalog.sql"

database_settings = DatabaseSettings()


class connection_factory:
"""Connection creation."""
Expand Down Expand Up @@ -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())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure we need this 🤷 we will register (in pg_temp) functions that are passed by the user so having both options is kinda weird to me


# 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())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think tipg is going to work if you don't have this in!



async def connect_to_db(
Expand Down
2 changes: 2 additions & 0 deletions tipg/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ class DatabaseSettings(pydantic.BaseSettings):

only_spatial_tables: bool = True

write_functions: bool = True

class Config:
"""model config"""

Expand Down