fix (data): Parallel connection pool.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# from enum import Enum
|
||||
from typing import Optional
|
||||
from psycopg.types.enum import register_enum, EnumInfo
|
||||
from psycopg import AsyncConnection
|
||||
from .registry import Attachable, Registry
|
||||
|
||||
|
||||
@@ -23,10 +24,17 @@ class RegisterEnum(Attachable):
|
||||
connector = registry._conn
|
||||
if connector is None:
|
||||
raise ValueError("Cannot initialise without connector!")
|
||||
connection = await connector.get_connection()
|
||||
if connection is None:
|
||||
raise ValueError("Cannot Init without connection.")
|
||||
info = await EnumInfo.fetch(connection, self.name)
|
||||
connector.connect_hook(self.connection_hook)
|
||||
# await connector.refresh_pool()
|
||||
# The below may be somewhat dangerous
|
||||
# But adaption should never write to the database
|
||||
await connector.map_over_pool(self.connection_hook)
|
||||
# if conn := connector.conn:
|
||||
# # Ensure the adaption is run in the current context as well
|
||||
# await self.connection_hook(conn)
|
||||
|
||||
async def connection_hook(self, conn: AsyncConnection):
|
||||
info = await EnumInfo.fetch(conn, self.name)
|
||||
if info is None:
|
||||
raise ValueError(f"Enum {self.name} not found in database.")
|
||||
register_enum(info, connection, self.enum, mapping=list(self.mapping.items()))
|
||||
register_enum(info, conn, self.enum, mapping=list(self.mapping.items()))
|
||||
|
||||
Reference in New Issue
Block a user