context.py 456 B

123456789101112131415
  1. from contextvars import ContextVar, Token
  2. project_schema_context: ContextVar[str | None] = ContextVar(
  3. "project_schema_context", default=None
  4. )
  5. def get_current_project_schema() -> str | None:
  6. """Get the current project schema name from context."""
  7. return project_schema_context.get()
  8. def set_project_schema(schema_name: str) -> Token:
  9. """Set the current project schema in context."""
  10. return project_schema_context.set(schema_name)