Skip to content

Connect to all schemas in the database? #123

Closed

Description

@swdmike

It would be helpful if I could set TIPG_DB_SCHEMAS='["*"]' to connect to all schemas in my database. In my work environment, schemas are frequently created based on project requirements, with each project having one or more schemas. I want to be able to see all spatial data within TIPG without constantly modifying its configuration.

Thanks!

Activity

  1. vincentsarago commented on Sep 21, 2023

    @vincentsarago
    Member

    @swdmike I don't think it's currently possible but you could customize this

    tipg/tipg/database.py

    Lines 23 to 67 in fdb6ec6

    class connection_factory:
    """Connection creation."""
    schemas: List[str]
    user_sql_files: List[pathlib.Path]
    def __init__(
    self,
    schemas: Optional[List[str]] = None,
    user_sql_files: Optional[List[pathlib.Path]] = None,
    ) -> None:
    """Init."""
    self.schemas = schemas or []
    self.user_sql_files = user_sql_files or []
    async def __call__(self, conn: asyncpg.Connection):
    """Create connection."""
    await conn.set_type_codec(
    "json", encoder=orjson.dumps, decoder=orjson.loads, schema="pg_catalog"
    )
    await conn.set_type_codec(
    "jsonb", encoder=orjson.dumps, decoder=orjson.loads, schema="pg_catalog"
    )
    # Note: we add `pg_temp as the first element of the schemas list to make sure
    # we register the custom functions and `dbcatalog` in it.
    schemas = ",".join(["pg_temp", *self.schemas])
    logger.debug(f"Looking for Tables and Functions in {schemas} schemas")
    await conn.execute(
    f"""
    SELECT set_config(
    'search_path',
    '{schemas},' || current_setting('search_path', false),
    false
    );
    """
    )
    # 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())
    to first list all the schemas and then construct the search path
    schemas = ",".join(["pg_temp", *self.schemas])

  2. locked and limited conversation to collaborators on Sep 21, 2023
  3. converted this issue into a discussion #124 on Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions