macss-modular-api-postgres 0.5.0__tar.gz → 0.7.0__tar.gz
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.
- {macss_modular_api_postgres-0.5.0 → macss_modular_api_postgres-0.7.0}/PKG-INFO +8 -3
- {macss_modular_api_postgres-0.5.0 → macss_modular_api_postgres-0.7.0}/README.md +4 -2
- macss_modular_api_postgres-0.7.0/pyproject.toml +95 -0
- {macss_modular_api_postgres-0.5.0 → macss_modular_api_postgres-0.7.0}/src/macss_modular_api_postgres.egg-info/PKG-INFO +8 -3
- {macss_modular_api_postgres-0.5.0 → macss_modular_api_postgres-0.7.0}/src/macss_modular_api_postgres.egg-info/SOURCES.txt +5 -1
- macss_modular_api_postgres-0.7.0/src/macss_modular_api_postgres.egg-info/requires.txt +6 -0
- {macss_modular_api_postgres-0.5.0 → macss_modular_api_postgres-0.7.0}/src/modular_api_postgres/__init__.py +10 -1
- {macss_modular_api_postgres-0.5.0 → macss_modular_api_postgres-0.7.0}/src/modular_api_postgres/db_client.py +75 -33
- macss_modular_api_postgres-0.7.0/src/modular_api_postgres/db_tracing.py +341 -0
- macss_modular_api_postgres-0.7.0/src/modular_api_postgres/py.typed +0 -0
- {macss_modular_api_postgres-0.5.0 → macss_modular_api_postgres-0.7.0}/tests/test_db_client.py +113 -3
- macss_modular_api_postgres-0.7.0/tests/test_db_conformance.py +121 -0
- macss_modular_api_postgres-0.7.0/tests/test_dependency_boundary.py +120 -0
- macss_modular_api_postgres-0.7.0/tests/test_tracing.py +532 -0
- macss_modular_api_postgres-0.5.0/pyproject.toml +0 -46
- macss_modular_api_postgres-0.5.0/src/macss_modular_api_postgres.egg-info/requires.txt +0 -3
- macss_modular_api_postgres-0.5.0/tests/test_db_conformance.py +0 -68
- {macss_modular_api_postgres-0.5.0 → macss_modular_api_postgres-0.7.0}/setup.cfg +0 -0
- {macss_modular_api_postgres-0.5.0 → macss_modular_api_postgres-0.7.0}/src/macss_modular_api_postgres.egg-info/dependency_links.txt +0 -0
- {macss_modular_api_postgres-0.5.0 → macss_modular_api_postgres-0.7.0}/src/macss_modular_api_postgres.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: macss-modular-api-postgres
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.0
|
|
4
4
|
Summary: Official MACSS Postgres integration package for Python.
|
|
5
5
|
Author: ccisne.dev
|
|
6
6
|
License-Expression: MIT
|
|
@@ -19,7 +19,10 @@ Classifier: Topic :: Database
|
|
|
19
19
|
Classifier: Typing :: Typed
|
|
20
20
|
Requires-Python: >=3.11
|
|
21
21
|
Description-Content-Type: text/markdown
|
|
22
|
+
Requires-Dist: opentelemetry-api<2,>=1.44
|
|
22
23
|
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: opentelemetry-sdk<2,>=1.44; extra == "dev"
|
|
25
|
+
Requires-Dist: pyright>=1.1.400; extra == "dev"
|
|
23
26
|
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
24
27
|
|
|
25
28
|
# macss-modular-api-postgres
|
|
@@ -56,10 +59,12 @@ else:
|
|
|
56
59
|
|
|
57
60
|
See [example/example.py](example/example.py) for a complete in-memory wiring sample.
|
|
58
61
|
|
|
59
|
-
##
|
|
62
|
+
## What this package provides
|
|
60
63
|
|
|
61
64
|
- normalized Postgres connection defaults and redacted summaries
|
|
62
65
|
- engine-agnostic `DbClient`, `DbRepository`, and transaction contracts
|
|
63
66
|
- explicit lease ownership semantics for package-owned and application-owned sessions
|
|
64
67
|
- health contributor and GraphQL support bundle for higher-level integrations
|
|
65
|
-
-
|
|
68
|
+
- the application supplies the driver binding (adapter) for its chosen engine and driver
|
|
69
|
+
|
|
70
|
+
This package is **contracts-only by design** and will never ship a driver binding; you choose your engine and driver and provide the adapter. See [ADR-0004](../../../docs/adr/0004-contracts-only-database-packages.md).
|
|
@@ -32,10 +32,12 @@ else:
|
|
|
32
32
|
|
|
33
33
|
See [example/example.py](example/example.py) for a complete in-memory wiring sample.
|
|
34
34
|
|
|
35
|
-
##
|
|
35
|
+
## What this package provides
|
|
36
36
|
|
|
37
37
|
- normalized Postgres connection defaults and redacted summaries
|
|
38
38
|
- engine-agnostic `DbClient`, `DbRepository`, and transaction contracts
|
|
39
39
|
- explicit lease ownership semantics for package-owned and application-owned sessions
|
|
40
40
|
- health contributor and GraphQL support bundle for higher-level integrations
|
|
41
|
-
-
|
|
41
|
+
- the application supplies the driver binding (adapter) for its chosen engine and driver
|
|
42
|
+
|
|
43
|
+
This package is **contracts-only by design** and will never ship a driver binding; you choose your engine and driver and provide the adapter. See [ADR-0004](../../../docs/adr/0004-contracts-only-database-packages.md).
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "macss-modular-api-postgres"
|
|
7
|
+
version = "0.7.0"
|
|
8
|
+
description = "Official MACSS Postgres integration package for Python."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.11"
|
|
12
|
+
authors = [{ name = "ccisne.dev" }]
|
|
13
|
+
keywords = ["macss", "postgres", "database"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.11",
|
|
19
|
+
"Programming Language :: Python :: 3.12",
|
|
20
|
+
"Programming Language :: Python :: 3.13",
|
|
21
|
+
"Topic :: Database",
|
|
22
|
+
"Typing :: Typed",
|
|
23
|
+
]
|
|
24
|
+
# OpenTelemetry API only — never the SDK, an exporter, grpcio or protobuf. Declared
|
|
25
|
+
# directly rather than inherited, because this package does not depend on
|
|
26
|
+
# macss-modular-api (runbook D21). The API is no-op without an SDK, so a consumer who
|
|
27
|
+
# never enables tracing pays a resolution entry and nothing else.
|
|
28
|
+
#
|
|
29
|
+
# This is the first runtime dependency the package has ever had. ADR-0004 keeps it free
|
|
30
|
+
# of any *database driver*, which is untouched: an instrumentation API is not a driver,
|
|
31
|
+
# and a new test asserts no driver is present.
|
|
32
|
+
dependencies = ["opentelemetry-api>=1.44,<2"]
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
dev = [
|
|
36
|
+
# The SDK is what makes spans observable at all — the API alone is no-op (runbook D22).
|
|
37
|
+
"opentelemetry-sdk>=1.44,<2",
|
|
38
|
+
# Configured below at `typeCheckingMode = "strict"`. Declared here because a checker the
|
|
39
|
+
# repo configures and never installs is a checker that has never run.
|
|
40
|
+
"pyright>=1.1.400",
|
|
41
|
+
"pytest>=8.0",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[project.urls]
|
|
45
|
+
Homepage = "https://github.com/macss-dev/modular_api"
|
|
46
|
+
Repository = "https://github.com/macss-dev/modular_api/tree/main/code/py/modular_api_postgres"
|
|
47
|
+
Issues = "https://github.com/macss-dev/modular_api/issues"
|
|
48
|
+
Documentation = "https://github.com/macss-dev/modular_api/tree/main/code/py/modular_api_postgres#readme"
|
|
49
|
+
|
|
50
|
+
[tool.setuptools.packages.find]
|
|
51
|
+
where = ["src"]
|
|
52
|
+
|
|
53
|
+
[tool.pytest.ini_options]
|
|
54
|
+
testpaths = ["tests"]
|
|
55
|
+
pythonpath = ["src"]
|
|
56
|
+
|
|
57
|
+
[tool.pyright]
|
|
58
|
+
pythonVersion = "3.11"
|
|
59
|
+
# `src/` is checked at full strict, because it is what a consumer's own type checker sees: these
|
|
60
|
+
# packages ship `py.typed`, so every annotation here becomes part of the public contract.
|
|
61
|
+
typeCheckingMode = "strict"
|
|
62
|
+
|
|
63
|
+
# `tests/` is strict too, minus the family that means "annotate this expression". Test code binds
|
|
64
|
+
# only this repo, and most of those diagnostics come from incomplete third-party stubs — annotating
|
|
65
|
+
# around them adds noise to a test without making anything more correct. Everything that can indicate
|
|
66
|
+
# a real defect stays on.
|
|
67
|
+
[[tool.pyright.executionEnvironments]]
|
|
68
|
+
root = "tests"
|
|
69
|
+
reportUnknownMemberType = false
|
|
70
|
+
reportUnknownArgumentType = false
|
|
71
|
+
reportUnknownVariableType = false
|
|
72
|
+
reportUnknownParameterType = false
|
|
73
|
+
reportUnknownLambdaType = false
|
|
74
|
+
reportMissingParameterType = false
|
|
75
|
+
reportMissingTypeArgument = false
|
|
76
|
+
# A pytest fixture is called by name through collection, never by a reference the checker can see, so
|
|
77
|
+
# `reportUnusedFunction` reports every `autouse` fixture in this tree. That is the tool not modelling
|
|
78
|
+
# pytest, not dead code. `reportUnusedImport` and `reportUnusedVariable` stay on — those do find dead
|
|
79
|
+
# code, and they did.
|
|
80
|
+
reportUnusedFunction = false
|
|
81
|
+
reportUnusedClass = false
|
|
82
|
+
# Tests legitimately reach into internals to exercise them directly. In `src/` this rule found real
|
|
83
|
+
# coupling and it was fixed rather than silenced.
|
|
84
|
+
reportPrivateUsage = false
|
|
85
|
+
# `example/` is documentation a consumer copies, not a published typed surface — same relaxed family
|
|
86
|
+
# as `tests/`, and the same expectation that nothing which can indicate a real defect is silenced.
|
|
87
|
+
[[tool.pyright.executionEnvironments]]
|
|
88
|
+
root = "example"
|
|
89
|
+
reportUnknownMemberType = false
|
|
90
|
+
reportUnknownArgumentType = false
|
|
91
|
+
reportUnknownVariableType = false
|
|
92
|
+
reportUnknownParameterType = false
|
|
93
|
+
reportUnknownLambdaType = false
|
|
94
|
+
reportMissingParameterType = false
|
|
95
|
+
reportMissingTypeArgument = false
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: macss-modular-api-postgres
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.0
|
|
4
4
|
Summary: Official MACSS Postgres integration package for Python.
|
|
5
5
|
Author: ccisne.dev
|
|
6
6
|
License-Expression: MIT
|
|
@@ -19,7 +19,10 @@ Classifier: Topic :: Database
|
|
|
19
19
|
Classifier: Typing :: Typed
|
|
20
20
|
Requires-Python: >=3.11
|
|
21
21
|
Description-Content-Type: text/markdown
|
|
22
|
+
Requires-Dist: opentelemetry-api<2,>=1.44
|
|
22
23
|
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: opentelemetry-sdk<2,>=1.44; extra == "dev"
|
|
25
|
+
Requires-Dist: pyright>=1.1.400; extra == "dev"
|
|
23
26
|
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
24
27
|
|
|
25
28
|
# macss-modular-api-postgres
|
|
@@ -56,10 +59,12 @@ else:
|
|
|
56
59
|
|
|
57
60
|
See [example/example.py](example/example.py) for a complete in-memory wiring sample.
|
|
58
61
|
|
|
59
|
-
##
|
|
62
|
+
## What this package provides
|
|
60
63
|
|
|
61
64
|
- normalized Postgres connection defaults and redacted summaries
|
|
62
65
|
- engine-agnostic `DbClient`, `DbRepository`, and transaction contracts
|
|
63
66
|
- explicit lease ownership semantics for package-owned and application-owned sessions
|
|
64
67
|
- health contributor and GraphQL support bundle for higher-level integrations
|
|
65
|
-
-
|
|
68
|
+
- the application supplies the driver binding (adapter) for its chosen engine and driver
|
|
69
|
+
|
|
70
|
+
This package is **contracts-only by design** and will never ship a driver binding; you choose your engine and driver and provide the adapter. See [ADR-0004](../../../docs/adr/0004-contracts-only-database-packages.md).
|
|
@@ -7,5 +7,9 @@ src/macss_modular_api_postgres.egg-info/requires.txt
|
|
|
7
7
|
src/macss_modular_api_postgres.egg-info/top_level.txt
|
|
8
8
|
src/modular_api_postgres/__init__.py
|
|
9
9
|
src/modular_api_postgres/db_client.py
|
|
10
|
+
src/modular_api_postgres/db_tracing.py
|
|
11
|
+
src/modular_api_postgres/py.typed
|
|
10
12
|
tests/test_db_client.py
|
|
11
|
-
tests/test_db_conformance.py
|
|
13
|
+
tests/test_db_conformance.py
|
|
14
|
+
tests/test_dependency_boundary.py
|
|
15
|
+
tests/test_tracing.py
|
|
@@ -14,6 +14,9 @@ from .db_client import (
|
|
|
14
14
|
DbHealthContributor,
|
|
15
15
|
DbHealthReport,
|
|
16
16
|
DbHealthStatus,
|
|
17
|
+
DbParameter,
|
|
18
|
+
DbParameterDirection,
|
|
19
|
+
DbProcedureOutcome,
|
|
17
20
|
DbProviderDescription,
|
|
18
21
|
DbRepository,
|
|
19
22
|
DbRepositoryContext,
|
|
@@ -25,8 +28,10 @@ from .db_client import (
|
|
|
25
28
|
DbTransactionContext,
|
|
26
29
|
DbTransactionRunner,
|
|
27
30
|
)
|
|
31
|
+
from .db_tracing import DbTracingOptions, trace_db_client
|
|
28
32
|
|
|
29
33
|
__all__ = [
|
|
34
|
+
"DbTracingOptions",
|
|
30
35
|
"DbClient",
|
|
31
36
|
"DbCommand",
|
|
32
37
|
"DbCommandExecutor",
|
|
@@ -40,6 +45,9 @@ __all__ = [
|
|
|
40
45
|
"DbHealthContributor",
|
|
41
46
|
"DbHealthReport",
|
|
42
47
|
"DbHealthStatus",
|
|
48
|
+
"DbParameter",
|
|
49
|
+
"DbParameterDirection",
|
|
50
|
+
"DbProcedureOutcome",
|
|
43
51
|
"DbProviderDescription",
|
|
44
52
|
"DbRepository",
|
|
45
53
|
"DbRepositoryContext",
|
|
@@ -50,4 +58,5 @@ __all__ = [
|
|
|
50
58
|
"DbSessionProvider",
|
|
51
59
|
"DbTransactionContext",
|
|
52
60
|
"DbTransactionRunner",
|
|
53
|
-
|
|
61
|
+
"trace_db_client",
|
|
62
|
+
]
|
|
@@ -7,6 +7,8 @@ from enum import Enum
|
|
|
7
7
|
from typing import Callable, Generic, Mapping, Protocol, TypeVar, cast
|
|
8
8
|
|
|
9
9
|
S = TypeVar("S")
|
|
10
|
+
#: Contravariant because the protocols below only ever *accept* a session, never return one.
|
|
11
|
+
S_contra = TypeVar("S_contra", contravariant=True)
|
|
10
12
|
T = TypeVar("T")
|
|
11
13
|
R = TypeVar("R")
|
|
12
14
|
_MISSING = object()
|
|
@@ -17,6 +19,13 @@ class DbCommandKind(str, Enum):
|
|
|
17
19
|
EXECUTE = "execute"
|
|
18
20
|
BATCH = "batch"
|
|
19
21
|
SCALAR = "scalar"
|
|
22
|
+
PROCEDURE = "procedure"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class DbParameterDirection(str, Enum):
|
|
26
|
+
INPUT = "input"
|
|
27
|
+
OUTPUT = "output"
|
|
28
|
+
INPUT_OUTPUT = "inputOutput"
|
|
20
29
|
|
|
21
30
|
|
|
22
31
|
class DbFailureKind(str, Enum):
|
|
@@ -45,7 +54,7 @@ class DbConnectionSettings:
|
|
|
45
54
|
username: str
|
|
46
55
|
password: str
|
|
47
56
|
ssl_mode: str
|
|
48
|
-
options: Mapping[str, object] = field(default_factory=dict)
|
|
57
|
+
options: Mapping[str, object] = field(default_factory=dict[str, object])
|
|
49
58
|
|
|
50
59
|
@classmethod
|
|
51
60
|
def from_environment(
|
|
@@ -81,6 +90,39 @@ class DbConnectionSettings:
|
|
|
81
90
|
)
|
|
82
91
|
|
|
83
92
|
|
|
93
|
+
@dataclass(frozen=True, slots=True)
|
|
94
|
+
class DbParameter:
|
|
95
|
+
name: str
|
|
96
|
+
value: object | None = None
|
|
97
|
+
direction: DbParameterDirection = DbParameterDirection.INPUT
|
|
98
|
+
type_hint: str | None = None
|
|
99
|
+
|
|
100
|
+
@classmethod
|
|
101
|
+
def input(cls, name: str, value: object | None, type_hint: str | None = None) -> DbParameter:
|
|
102
|
+
return cls(name=name, value=value, direction=DbParameterDirection.INPUT, type_hint=type_hint)
|
|
103
|
+
|
|
104
|
+
@classmethod
|
|
105
|
+
def output(cls, name: str, type_hint: str | None = None) -> DbParameter:
|
|
106
|
+
return cls(name=name, direction=DbParameterDirection.OUTPUT, type_hint=type_hint)
|
|
107
|
+
|
|
108
|
+
@classmethod
|
|
109
|
+
def input_output(
|
|
110
|
+
cls, name: str, value: object | None, type_hint: str | None = None
|
|
111
|
+
) -> DbParameter:
|
|
112
|
+
return cls(
|
|
113
|
+
name=name,
|
|
114
|
+
value=value,
|
|
115
|
+
direction=DbParameterDirection.INPUT_OUTPUT,
|
|
116
|
+
type_hint=type_hint,
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
@dataclass(frozen=True, slots=True)
|
|
121
|
+
class DbProcedureOutcome:
|
|
122
|
+
return_value: object | None = None
|
|
123
|
+
output_parameters: Mapping[str, object] | None = None
|
|
124
|
+
|
|
125
|
+
|
|
84
126
|
@dataclass(frozen=True, slots=True)
|
|
85
127
|
class DbCommand:
|
|
86
128
|
kind: DbCommandKind
|
|
@@ -101,12 +143,14 @@ class DbExecutionMetadata:
|
|
|
101
143
|
class DbRowSet:
|
|
102
144
|
rows: list[Mapping[str, object]]
|
|
103
145
|
metadata: DbExecutionMetadata
|
|
146
|
+
procedure: DbProcedureOutcome | None = None
|
|
104
147
|
|
|
105
148
|
|
|
106
149
|
@dataclass(frozen=True, slots=True)
|
|
107
150
|
class DbExecutionSummary:
|
|
108
151
|
affected_count: int
|
|
109
152
|
metadata: DbExecutionMetadata
|
|
153
|
+
procedure: DbProcedureOutcome | None = None
|
|
110
154
|
|
|
111
155
|
|
|
112
156
|
@dataclass(frozen=True, slots=True)
|
|
@@ -161,18 +205,18 @@ class DbResult(Generic[T]):
|
|
|
161
205
|
|
|
162
206
|
def map(self, transform: Callable[[T], R]) -> DbResult[R]:
|
|
163
207
|
if self.is_failure:
|
|
164
|
-
return DbResult.from_failure(self.failure)
|
|
165
|
-
return DbResult.success(transform(self.value))
|
|
208
|
+
return DbResult[R].from_failure(self.failure)
|
|
209
|
+
return DbResult[R].success(transform(self.value))
|
|
166
210
|
|
|
167
211
|
def flat_map(self, transform: Callable[[T], DbResult[R]]) -> DbResult[R]:
|
|
168
212
|
if self.is_failure:
|
|
169
|
-
return DbResult.from_failure(self.failure)
|
|
213
|
+
return DbResult[R].from_failure(self.failure)
|
|
170
214
|
return transform(self.value)
|
|
171
215
|
|
|
172
216
|
def map_failure(self, transform: Callable[[DbFailure], DbFailure]) -> DbResult[T]:
|
|
173
217
|
if self.is_success:
|
|
174
|
-
return DbResult.success(self.value)
|
|
175
|
-
return DbResult.from_failure(transform(self.failure))
|
|
218
|
+
return DbResult[T].success(self.value)
|
|
219
|
+
return DbResult[T].from_failure(transform(self.failure))
|
|
176
220
|
|
|
177
221
|
def get_or_throw(self, message: str | None = None) -> T:
|
|
178
222
|
if self.is_failure:
|
|
@@ -202,7 +246,7 @@ class DbSessionLease(Generic[S]):
|
|
|
202
246
|
|
|
203
247
|
def release(self) -> DbResult[None]:
|
|
204
248
|
if not self.owned_by_package:
|
|
205
|
-
return DbResult.success(None)
|
|
249
|
+
return DbResult[None].success(None)
|
|
206
250
|
return self._releaser()
|
|
207
251
|
|
|
208
252
|
|
|
@@ -214,12 +258,16 @@ class DbSessionProvider(Protocol[S]):
|
|
|
214
258
|
def describe(self) -> DbProviderDescription: ...
|
|
215
259
|
|
|
216
260
|
|
|
217
|
-
class DbCommandExecutor(Protocol[
|
|
218
|
-
def query(self, session:
|
|
261
|
+
class DbCommandExecutor(Protocol[S_contra]):
|
|
262
|
+
def query(self, session: S_contra, command: DbCommand) -> DbResult[DbRowSet]: ...
|
|
219
263
|
|
|
220
|
-
def execute(
|
|
264
|
+
def execute(
|
|
265
|
+
self, session: S_contra, command: DbCommand
|
|
266
|
+
) -> DbResult[DbExecutionSummary]: ...
|
|
221
267
|
|
|
222
|
-
def scalar(
|
|
268
|
+
def scalar(
|
|
269
|
+
self, session: S_contra, command: DbCommand
|
|
270
|
+
) -> DbResult[DbScalar[object]]: ...
|
|
223
271
|
|
|
224
272
|
|
|
225
273
|
@dataclass(frozen=True, slots=True)
|
|
@@ -234,8 +282,8 @@ class DbTransactionContext(Generic[S]):
|
|
|
234
282
|
def execute(self, command: DbCommand) -> DbResult[DbExecutionSummary]:
|
|
235
283
|
return self.command_executor.execute(self.session, command)
|
|
236
284
|
|
|
237
|
-
def scalar(self, command: DbCommand) -> DbResult[DbScalar[
|
|
238
|
-
return
|
|
285
|
+
def scalar(self, command: DbCommand) -> DbResult[DbScalar[object]]:
|
|
286
|
+
return self.command_executor.scalar(self.session, command)
|
|
239
287
|
|
|
240
288
|
|
|
241
289
|
class DbTransactionRunner(Protocol[S]):
|
|
@@ -270,13 +318,10 @@ class DbRepository(Generic[S]):
|
|
|
270
318
|
lambda lease: self.context.command_executor.execute(lease.session, command),
|
|
271
319
|
)
|
|
272
320
|
|
|
273
|
-
def scalar(self, command: DbCommand) -> DbResult[DbScalar[
|
|
274
|
-
return
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
self.context.session_provider,
|
|
278
|
-
lambda lease: self.context.command_executor.scalar(lease.session, command),
|
|
279
|
-
),
|
|
321
|
+
def scalar(self, command: DbCommand) -> DbResult[DbScalar[object]]:
|
|
322
|
+
return _with_lease(
|
|
323
|
+
self.context.session_provider,
|
|
324
|
+
lambda lease: self.context.command_executor.scalar(lease.session, command),
|
|
280
325
|
)
|
|
281
326
|
|
|
282
327
|
def transaction(self, body: Callable[[DbTransactionContext[S]], DbResult[T]]) -> DbResult[T]:
|
|
@@ -315,19 +360,16 @@ class DbClient(Generic[S]):
|
|
|
315
360
|
lambda lease: self.command_executor.execute(lease.session, command),
|
|
316
361
|
)
|
|
317
362
|
|
|
318
|
-
def scalar(self, command: DbCommand) -> DbResult[DbScalar[
|
|
319
|
-
return
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
self.session_provider,
|
|
323
|
-
lambda lease: self.command_executor.scalar(lease.session, command),
|
|
324
|
-
),
|
|
363
|
+
def scalar(self, command: DbCommand) -> DbResult[DbScalar[object]]:
|
|
364
|
+
return _with_lease(
|
|
365
|
+
self.session_provider,
|
|
366
|
+
lambda lease: self.command_executor.scalar(lease.session, command),
|
|
325
367
|
)
|
|
326
368
|
|
|
327
369
|
def transaction(self, body: Callable[[DbTransactionContext[S]], DbResult[T]]) -> DbResult[T]:
|
|
328
370
|
lease_result = self.session_provider.acquire()
|
|
329
371
|
if lease_result.is_failure:
|
|
330
|
-
return DbResult.from_failure(lease_result.failure)
|
|
372
|
+
return DbResult[T].from_failure(lease_result.failure)
|
|
331
373
|
|
|
332
374
|
lease = lease_result.value
|
|
333
375
|
context = DbTransactionContext(
|
|
@@ -339,9 +381,9 @@ class DbClient(Generic[S]):
|
|
|
339
381
|
release_result = lease.release()
|
|
340
382
|
|
|
341
383
|
if result.is_failure:
|
|
342
|
-
return DbResult.from_failure(result.failure)
|
|
384
|
+
return DbResult[T].from_failure(result.failure)
|
|
343
385
|
if release_result.is_failure:
|
|
344
|
-
return DbResult.from_failure(release_result.failure)
|
|
386
|
+
return DbResult[T].from_failure(release_result.failure)
|
|
345
387
|
return result
|
|
346
388
|
|
|
347
389
|
def repository_context(self) -> DbRepositoryContext[S]:
|
|
@@ -412,14 +454,14 @@ def _with_lease(
|
|
|
412
454
|
) -> DbResult[T]:
|
|
413
455
|
lease_result = session_provider.acquire()
|
|
414
456
|
if lease_result.is_failure:
|
|
415
|
-
return DbResult.from_failure(lease_result.failure)
|
|
457
|
+
return DbResult[T].from_failure(lease_result.failure)
|
|
416
458
|
|
|
417
459
|
lease = lease_result.value
|
|
418
460
|
operation_result = operation(lease)
|
|
419
461
|
release_result = lease.release()
|
|
420
462
|
|
|
421
463
|
if operation_result.is_failure:
|
|
422
|
-
return DbResult.from_failure(operation_result.failure)
|
|
464
|
+
return DbResult[T].from_failure(operation_result.failure)
|
|
423
465
|
if release_result.is_failure:
|
|
424
|
-
return DbResult.from_failure(release_result.failure)
|
|
466
|
+
return DbResult[T].from_failure(release_result.failure)
|
|
425
467
|
return operation_result
|