macss-modular-api-sqlserver 0.5.0__py3-none-any.whl → 0.7.0__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.
- {macss_modular_api_sqlserver-0.5.0.dist-info → macss_modular_api_sqlserver-0.7.0.dist-info}/METADATA +6 -3
- macss_modular_api_sqlserver-0.7.0.dist-info/RECORD +7 -0
- {macss_modular_api_sqlserver-0.5.0.dist-info → macss_modular_api_sqlserver-0.7.0.dist-info}/WHEEL +1 -1
- modular_api_sqlserver/__init__.py +6 -0
- modular_api_sqlserver/db_client.py +76 -34
- modular_api_sqlserver/py.typed +0 -0
- macss_modular_api_sqlserver-0.5.0.dist-info/RECORD +0 -6
- {macss_modular_api_sqlserver-0.5.0.dist-info → macss_modular_api_sqlserver-0.7.0.dist-info}/top_level.txt +0 -0
{macss_modular_api_sqlserver-0.5.0.dist-info → macss_modular_api_sqlserver-0.7.0.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: macss-modular-api-sqlserver
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.0
|
|
4
4
|
Summary: Official MACSS SQL Server integration package for Python.
|
|
5
5
|
Author: ccisne.dev
|
|
6
6
|
License-Expression: MIT
|
|
@@ -20,6 +20,7 @@ Classifier: Typing :: Typed
|
|
|
20
20
|
Requires-Python: >=3.11
|
|
21
21
|
Description-Content-Type: text/markdown
|
|
22
22
|
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: pyright>=1.1.400; extra == "dev"
|
|
23
24
|
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
24
25
|
|
|
25
26
|
# macss-modular-api-sqlserver
|
|
@@ -56,10 +57,12 @@ else:
|
|
|
56
57
|
|
|
57
58
|
See [example/example.py](example/example.py) for a complete in-memory wiring sample.
|
|
58
59
|
|
|
59
|
-
##
|
|
60
|
+
## What this package provides
|
|
60
61
|
|
|
61
62
|
- normalized SQL Server connection defaults and redacted summaries
|
|
62
63
|
- engine-agnostic `DbClient`, `DbRepository`, and transaction contracts
|
|
63
64
|
- explicit lease ownership semantics for package-owned and application-owned sessions
|
|
64
65
|
- health contributor and GraphQL support bundle for higher-level integrations
|
|
65
|
-
-
|
|
66
|
+
- the application supplies the driver binding (adapter) for its chosen engine and driver
|
|
67
|
+
|
|
68
|
+
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,7 @@
|
|
|
1
|
+
modular_api_sqlserver/__init__.py,sha256=m-ExxV6JLGD41Gx1nodhzLcevLdqDYMbBz08hU26q_0,1230
|
|
2
|
+
modular_api_sqlserver/db_client.py,sha256=EXew5BRs-CGXNqiUmbUpA7eDFmqes6CkV-fNNm1wg3U,14436
|
|
3
|
+
modular_api_sqlserver/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
macss_modular_api_sqlserver-0.7.0.dist-info/METADATA,sha256=JI8R320nrgyk26f46Vy82KQbOJmWzKIT9MfU6GXOO3w,2508
|
|
5
|
+
macss_modular_api_sqlserver-0.7.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
6
|
+
macss_modular_api_sqlserver-0.7.0.dist-info/top_level.txt,sha256=n0TFMe-mbowNietmYzSthEnQ-gmZLPXaLJ6h0HhuX84,22
|
|
7
|
+
macss_modular_api_sqlserver-0.7.0.dist-info/RECORD,,
|
|
@@ -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,
|
|
@@ -40,6 +43,9 @@ __all__ = [
|
|
|
40
43
|
"DbHealthContributor",
|
|
41
44
|
"DbHealthReport",
|
|
42
45
|
"DbHealthStatus",
|
|
46
|
+
"DbParameter",
|
|
47
|
+
"DbParameterDirection",
|
|
48
|
+
"DbProcedureOutcome",
|
|
43
49
|
"DbProviderDescription",
|
|
44
50
|
"DbRepository",
|
|
45
51
|
"DbRepositoryContext",
|
|
@@ -4,9 +4,11 @@ import os
|
|
|
4
4
|
import time
|
|
5
5
|
from dataclasses import dataclass, field
|
|
6
6
|
from enum import Enum
|
|
7
|
-
from typing import
|
|
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
|
driver: 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(
|
|
@@ -84,6 +93,39 @@ class DbConnectionSettings:
|
|
|
84
93
|
)
|
|
85
94
|
|
|
86
95
|
|
|
96
|
+
@dataclass(frozen=True, slots=True)
|
|
97
|
+
class DbParameter:
|
|
98
|
+
name: str
|
|
99
|
+
value: object | None = None
|
|
100
|
+
direction: DbParameterDirection = DbParameterDirection.INPUT
|
|
101
|
+
type_hint: str | None = None
|
|
102
|
+
|
|
103
|
+
@classmethod
|
|
104
|
+
def input(cls, name: str, value: object | None, type_hint: str | None = None) -> DbParameter:
|
|
105
|
+
return cls(name=name, value=value, direction=DbParameterDirection.INPUT, type_hint=type_hint)
|
|
106
|
+
|
|
107
|
+
@classmethod
|
|
108
|
+
def output(cls, name: str, type_hint: str | None = None) -> DbParameter:
|
|
109
|
+
return cls(name=name, direction=DbParameterDirection.OUTPUT, type_hint=type_hint)
|
|
110
|
+
|
|
111
|
+
@classmethod
|
|
112
|
+
def input_output(
|
|
113
|
+
cls, name: str, value: object | None, type_hint: str | None = None
|
|
114
|
+
) -> DbParameter:
|
|
115
|
+
return cls(
|
|
116
|
+
name=name,
|
|
117
|
+
value=value,
|
|
118
|
+
direction=DbParameterDirection.INPUT_OUTPUT,
|
|
119
|
+
type_hint=type_hint,
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
@dataclass(frozen=True, slots=True)
|
|
124
|
+
class DbProcedureOutcome:
|
|
125
|
+
return_value: object | None = None
|
|
126
|
+
output_parameters: Mapping[str, object] | None = None
|
|
127
|
+
|
|
128
|
+
|
|
87
129
|
@dataclass(frozen=True, slots=True)
|
|
88
130
|
class DbCommand:
|
|
89
131
|
kind: DbCommandKind
|
|
@@ -104,12 +146,14 @@ class DbExecutionMetadata:
|
|
|
104
146
|
class DbRowSet:
|
|
105
147
|
rows: list[Mapping[str, object]]
|
|
106
148
|
metadata: DbExecutionMetadata
|
|
149
|
+
procedure: DbProcedureOutcome | None = None
|
|
107
150
|
|
|
108
151
|
|
|
109
152
|
@dataclass(frozen=True, slots=True)
|
|
110
153
|
class DbExecutionSummary:
|
|
111
154
|
affected_count: int
|
|
112
155
|
metadata: DbExecutionMetadata
|
|
156
|
+
procedure: DbProcedureOutcome | None = None
|
|
113
157
|
|
|
114
158
|
|
|
115
159
|
@dataclass(frozen=True, slots=True)
|
|
@@ -164,18 +208,18 @@ class DbResult(Generic[T]):
|
|
|
164
208
|
|
|
165
209
|
def map(self, transform: Callable[[T], R]) -> DbResult[R]:
|
|
166
210
|
if self.is_failure:
|
|
167
|
-
return DbResult.from_failure(self.failure)
|
|
168
|
-
return DbResult.success(transform(self.value))
|
|
211
|
+
return DbResult[R].from_failure(self.failure)
|
|
212
|
+
return DbResult[R].success(transform(self.value))
|
|
169
213
|
|
|
170
214
|
def flat_map(self, transform: Callable[[T], DbResult[R]]) -> DbResult[R]:
|
|
171
215
|
if self.is_failure:
|
|
172
|
-
return DbResult.from_failure(self.failure)
|
|
216
|
+
return DbResult[R].from_failure(self.failure)
|
|
173
217
|
return transform(self.value)
|
|
174
218
|
|
|
175
219
|
def map_failure(self, transform: Callable[[DbFailure], DbFailure]) -> DbResult[T]:
|
|
176
220
|
if self.is_success:
|
|
177
|
-
return DbResult.success(self.value)
|
|
178
|
-
return DbResult.from_failure(transform(self.failure))
|
|
221
|
+
return DbResult[T].success(self.value)
|
|
222
|
+
return DbResult[T].from_failure(transform(self.failure))
|
|
179
223
|
|
|
180
224
|
def get_or_throw(self, message: str | None = None) -> T:
|
|
181
225
|
if self.is_failure:
|
|
@@ -205,7 +249,7 @@ class DbSessionLease(Generic[S]):
|
|
|
205
249
|
|
|
206
250
|
def release(self) -> DbResult[None]:
|
|
207
251
|
if not self.owned_by_package:
|
|
208
|
-
return DbResult.success(None)
|
|
252
|
+
return DbResult[None].success(None)
|
|
209
253
|
return self._releaser()
|
|
210
254
|
|
|
211
255
|
|
|
@@ -217,12 +261,16 @@ class DbSessionProvider(Protocol[S]):
|
|
|
217
261
|
def describe(self) -> DbProviderDescription: ...
|
|
218
262
|
|
|
219
263
|
|
|
220
|
-
class DbCommandExecutor(Protocol[
|
|
221
|
-
def query(self, session:
|
|
264
|
+
class DbCommandExecutor(Protocol[S_contra]):
|
|
265
|
+
def query(self, session: S_contra, command: DbCommand) -> DbResult[DbRowSet]: ...
|
|
222
266
|
|
|
223
|
-
def execute(
|
|
267
|
+
def execute(
|
|
268
|
+
self, session: S_contra, command: DbCommand
|
|
269
|
+
) -> DbResult[DbExecutionSummary]: ...
|
|
224
270
|
|
|
225
|
-
def scalar(
|
|
271
|
+
def scalar(
|
|
272
|
+
self, session: S_contra, command: DbCommand
|
|
273
|
+
) -> DbResult[DbScalar[object]]: ...
|
|
226
274
|
|
|
227
275
|
|
|
228
276
|
@dataclass(frozen=True, slots=True)
|
|
@@ -237,8 +285,8 @@ class DbTransactionContext(Generic[S]):
|
|
|
237
285
|
def execute(self, command: DbCommand) -> DbResult[DbExecutionSummary]:
|
|
238
286
|
return self.command_executor.execute(self.session, command)
|
|
239
287
|
|
|
240
|
-
def scalar(self, command: DbCommand) -> DbResult[DbScalar[
|
|
241
|
-
return
|
|
288
|
+
def scalar(self, command: DbCommand) -> DbResult[DbScalar[object]]:
|
|
289
|
+
return self.command_executor.scalar(self.session, command)
|
|
242
290
|
|
|
243
291
|
|
|
244
292
|
class DbTransactionRunner(Protocol[S]):
|
|
@@ -273,13 +321,10 @@ class DbRepository(Generic[S]):
|
|
|
273
321
|
lambda lease: self.context.command_executor.execute(lease.session, command),
|
|
274
322
|
)
|
|
275
323
|
|
|
276
|
-
def scalar(self, command: DbCommand) -> DbResult[DbScalar[
|
|
277
|
-
return
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
self.context.session_provider,
|
|
281
|
-
lambda lease: self.context.command_executor.scalar(lease.session, command),
|
|
282
|
-
),
|
|
324
|
+
def scalar(self, command: DbCommand) -> DbResult[DbScalar[object]]:
|
|
325
|
+
return _with_lease(
|
|
326
|
+
self.context.session_provider,
|
|
327
|
+
lambda lease: self.context.command_executor.scalar(lease.session, command),
|
|
283
328
|
)
|
|
284
329
|
|
|
285
330
|
def transaction(self, body: Callable[[DbTransactionContext[S]], DbResult[T]]) -> DbResult[T]:
|
|
@@ -318,19 +363,16 @@ class DbClient(Generic[S]):
|
|
|
318
363
|
lambda lease: self.command_executor.execute(lease.session, command),
|
|
319
364
|
)
|
|
320
365
|
|
|
321
|
-
def scalar(self, command: DbCommand) -> DbResult[DbScalar[
|
|
322
|
-
return
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
self.session_provider,
|
|
326
|
-
lambda lease: self.command_executor.scalar(lease.session, command),
|
|
327
|
-
),
|
|
366
|
+
def scalar(self, command: DbCommand) -> DbResult[DbScalar[object]]:
|
|
367
|
+
return _with_lease(
|
|
368
|
+
self.session_provider,
|
|
369
|
+
lambda lease: self.command_executor.scalar(lease.session, command),
|
|
328
370
|
)
|
|
329
371
|
|
|
330
372
|
def transaction(self, body: Callable[[DbTransactionContext[S]], DbResult[T]]) -> DbResult[T]:
|
|
331
373
|
lease_result = self.session_provider.acquire()
|
|
332
374
|
if lease_result.is_failure:
|
|
333
|
-
return DbResult.from_failure(lease_result.failure)
|
|
375
|
+
return DbResult[T].from_failure(lease_result.failure)
|
|
334
376
|
|
|
335
377
|
lease = lease_result.value
|
|
336
378
|
context = DbTransactionContext(
|
|
@@ -342,9 +384,9 @@ class DbClient(Generic[S]):
|
|
|
342
384
|
release_result = lease.release()
|
|
343
385
|
|
|
344
386
|
if result.is_failure:
|
|
345
|
-
return DbResult.from_failure(result.failure)
|
|
387
|
+
return DbResult[T].from_failure(result.failure)
|
|
346
388
|
if release_result.is_failure:
|
|
347
|
-
return DbResult.from_failure(release_result.failure)
|
|
389
|
+
return DbResult[T].from_failure(release_result.failure)
|
|
348
390
|
return result
|
|
349
391
|
|
|
350
392
|
def repository_context(self) -> DbRepositoryContext[S]:
|
|
@@ -415,14 +457,14 @@ def _with_lease(
|
|
|
415
457
|
) -> DbResult[T]:
|
|
416
458
|
lease_result = session_provider.acquire()
|
|
417
459
|
if lease_result.is_failure:
|
|
418
|
-
return DbResult.from_failure(lease_result.failure)
|
|
460
|
+
return DbResult[T].from_failure(lease_result.failure)
|
|
419
461
|
|
|
420
462
|
lease = lease_result.value
|
|
421
463
|
operation_result = operation(lease)
|
|
422
464
|
release_result = lease.release()
|
|
423
465
|
|
|
424
466
|
if operation_result.is_failure:
|
|
425
|
-
return DbResult.from_failure(operation_result.failure)
|
|
467
|
+
return DbResult[T].from_failure(operation_result.failure)
|
|
426
468
|
if release_result.is_failure:
|
|
427
|
-
return DbResult.from_failure(release_result.failure)
|
|
469
|
+
return DbResult[T].from_failure(release_result.failure)
|
|
428
470
|
return operation_result
|
|
File without changes
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
modular_api_sqlserver/__init__.py,sha256=oc7QvcB8Ed6B8jVwzetvRrZBA3hROJs1WrC37bHv5fE,1090
|
|
2
|
-
modular_api_sqlserver/db_client.py,sha256=jVTiw9urV2AGqpg7sQzW-ID3PfUdWxSrMxG-I83pZ_c,13045
|
|
3
|
-
macss_modular_api_sqlserver-0.5.0.dist-info/METADATA,sha256=ks8IN5jOJpOsdWEhMPsCREKjo04Mk9xzaJKQd-_WDn8,2208
|
|
4
|
-
macss_modular_api_sqlserver-0.5.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
5
|
-
macss_modular_api_sqlserver-0.5.0.dist-info/top_level.txt,sha256=n0TFMe-mbowNietmYzSthEnQ-gmZLPXaLJ6h0HhuX84,22
|
|
6
|
-
macss_modular_api_sqlserver-0.5.0.dist-info/RECORD,,
|
|
File without changes
|