netherframe.backends.postgresql 0.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- netherframe/backends/postgresql/__init__.py +59 -0
- netherframe/backends/postgresql/connection_settings.py +40 -0
- netherframe/backends/postgresql/graph.py +2511 -0
- netherframe/backends/postgresql/graph_authorization.py +102 -0
- netherframe/backends/postgresql/graph_checkpoints.py +239 -0
- netherframe/backends/postgresql/graph_completion.py +66 -0
- netherframe/backends/postgresql/graph_convergence.py +103 -0
- netherframe/backends/postgresql/graph_invalidation.py +115 -0
- netherframe/backends/postgresql/graph_lease_queue.py +236 -0
- netherframe/backends/postgresql/graph_planning_reads.py +97 -0
- netherframe/backends/postgresql/graph_publication.py +373 -0
- netherframe/backends/postgresql/graph_retention.py +141 -0
- netherframe/backends/postgresql/graph_reverse_edges.py +143 -0
- netherframe/backends/postgresql/graph_schema.py +2038 -0
- netherframe/backends/postgresql/graph_transfers.py +128 -0
- netherframe/backends/postgresql/postgresql.py +1207 -0
- netherframe/backends/postgresql/postgresql_backend_bootstrap.py +139 -0
- netherframe/backends/postgresql/py.typed +0 -0
- netherframe_backends_postgresql-0.2.1.dist-info/METADATA +138 -0
- netherframe_backends_postgresql-0.2.1.dist-info/RECORD +40 -0
- netherframe_backends_postgresql-0.2.1.dist-info/WHEEL +4 -0
- netherframe_backends_postgresql-0.2.1.dist-info/licenses/LICENSE +21 -0
- nf/backends/postgresql/__init__.py +4 -0
- nf/backends/postgresql/connection_settings.py +4 -0
- nf/backends/postgresql/graph.py +4 -0
- nf/backends/postgresql/graph_authorization.py +4 -0
- nf/backends/postgresql/graph_checkpoints.py +4 -0
- nf/backends/postgresql/graph_completion.py +4 -0
- nf/backends/postgresql/graph_convergence.py +4 -0
- nf/backends/postgresql/graph_invalidation.py +4 -0
- nf/backends/postgresql/graph_lease_queue.py +4 -0
- nf/backends/postgresql/graph_planning_reads.py +4 -0
- nf/backends/postgresql/graph_publication.py +4 -0
- nf/backends/postgresql/graph_retention.py +4 -0
- nf/backends/postgresql/graph_reverse_edges.py +4 -0
- nf/backends/postgresql/graph_schema.py +4 -0
- nf/backends/postgresql/graph_transfers.py +4 -0
- nf/backends/postgresql/postgresql.py +4 -0
- nf/backends/postgresql/postgresql_backend_bootstrap.py +4 -0
- nf/backends/postgresql/py.typed +0 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""PostgreSQL backend for Netherframe."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, cast
|
|
4
|
+
|
|
5
|
+
from .graph import PostgreSQLGraphBackend
|
|
6
|
+
from .postgresql import PostgreSQLBackend
|
|
7
|
+
from .postgresql_backend_bootstrap import (
|
|
8
|
+
PostgreSQLBackendBootstrapper,
|
|
9
|
+
PostgreSQLBackendResources,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"PostgreSQLBackend",
|
|
14
|
+
"PostgreSQLBackendBootstrapper",
|
|
15
|
+
"PostgreSQLBackendResources",
|
|
16
|
+
"PostgreSQLGraphBackend",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _register_core_components() -> None:
|
|
21
|
+
"""Register PostgreSQL backends with the shared registries."""
|
|
22
|
+
from netherframe.core.backends.backend_bootstrap import BackendBootstrapManager
|
|
23
|
+
from netherframe.core.backends.backend_registry import BackendRegistry
|
|
24
|
+
|
|
25
|
+
BackendRegistry.register_state_backend(
|
|
26
|
+
"postgresql",
|
|
27
|
+
PostgreSQLBackend,
|
|
28
|
+
package_name="netherframe.backends.postgresql",
|
|
29
|
+
)
|
|
30
|
+
BackendBootstrapManager.register_bootstrapper(
|
|
31
|
+
"postgresql",
|
|
32
|
+
PostgreSQLBackendBootstrapper,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _postgresql_factory(config: dict[str, Any]) -> PostgreSQLBackend:
|
|
37
|
+
"""Factory for creating PostgreSQL backends from registry config."""
|
|
38
|
+
return PostgreSQLBackend(**cast("Any", config))
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def register_backends() -> None:
|
|
42
|
+
"""Register PostgreSQL backends with the registry."""
|
|
43
|
+
try:
|
|
44
|
+
from netherframe.core.backends.backend_registry import BackendRegistry
|
|
45
|
+
|
|
46
|
+
_register_core_components()
|
|
47
|
+
BackendRegistry.register_backend_factory(
|
|
48
|
+
"postgresql",
|
|
49
|
+
_postgresql_factory,
|
|
50
|
+
package_name="netherframe.backends.postgresql",
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
except ImportError:
|
|
54
|
+
# netherframe.core not available, skip registration
|
|
55
|
+
pass
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
# Auto-registration disabled to avoid circular imports during entry point discovery
|
|
59
|
+
# register_backends()
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Connection settings of the PostgreSQL state backends, as every setting: flag > ``[tool.nf.config]`` > argument > default.
|
|
2
|
+
|
|
3
|
+
``nf --postgresql-host db.internal --postgresql-database nf ...`` or ``postgresql_host`` in
|
|
4
|
+
``[tool.nf.config]``. The password is never a flag: it comes from a file
|
|
5
|
+
(``--postgresql-password-file``, ``postgresql_password_file``, or the backend's
|
|
6
|
+
``password_file``, such as a mounted secret or ``<(...)``), or from the backend's own argument
|
|
7
|
+
or callable. Nothing is read from the environment.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
from netherframe.core.config.config_values import get_config_value
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def setting(name: str, given: Any, default: Any = None, parser: Any = None) -> Any:
|
|
19
|
+
"""``postgresql_<name>``: its flag, else ``[tool.nf.config]``, else ``given`` (the backend's argument), else ``default``."""
|
|
20
|
+
return get_config_value(f"postgresql_{name}", default=default, app_value=given, parser=parser)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def password_file(given: str | Path | None) -> Path | None:
|
|
24
|
+
"""The file holding the password: ``--postgresql-password-file``, else ``[tool.nf.config]``, else ``given``."""
|
|
25
|
+
value = setting("password_file", given, parser=str)
|
|
26
|
+
return Path(value).expanduser() if value else None
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
#: What each pipe (``<(...)``) gave: it can be read once, and the pool may connect again later
|
|
30
|
+
_piped: dict[str, str] = {}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def read_password_file(path: Path) -> str:
|
|
34
|
+
"""The password in ``path``: a file is read on each use (a rotated secret applies), a pipe once."""
|
|
35
|
+
if (kept := _piped.get(str(path))) is not None:
|
|
36
|
+
return kept
|
|
37
|
+
password = path.read_text(encoding="utf-8").strip()
|
|
38
|
+
if not path.is_file():
|
|
39
|
+
_piped[str(path)] = password
|
|
40
|
+
return password
|