(
db: Database, env: dict[str, str]
)
| 126 | |
| 127 | @contextlib.contextmanager |
| 128 | def update_environment( |
| 129 | db: Database, env: dict[str, str] |
| 130 | ) -> Generator[Database, None, None]: |
| 131 | original = dict() |
| 132 | for e in db.query_all("SHOW ALL"): |
| 133 | key, old_value = e["name"], e["setting"] |
| 134 | if key in env: |
| 135 | original[key] = old_value |
| 136 | new_value = env[key] |
| 137 | db.execute(f"SET {identifier(key)} = {literal(new_value)}") |
| 138 | yield db |
| 139 | for key, old_value in original.items(): |
| 140 | db.execute(f"SET {identifier(key)} = {literal(old_value)}") |
| 141 | |
| 142 | |
| 143 | # Utility functions |
nothing calls this directly
no test coverage detected