aidbox-python-sdk 0.2.1__py3-none-any.whl → 0.2.3__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.
- aidbox_python_sdk/__init__.py +2 -2
- aidbox_python_sdk/db.py +41 -4
- aidbox_python_sdk/handlers.py +1 -8
- aidbox_python_sdk/pytest_plugin.py +2 -1
- {aidbox_python_sdk-0.2.1.dist-info → aidbox_python_sdk-0.2.3.dist-info}/METADATA +1 -1
- {aidbox_python_sdk-0.2.1.dist-info → aidbox_python_sdk-0.2.3.dist-info}/RECORD +9 -9
- {aidbox_python_sdk-0.2.1.dist-info → aidbox_python_sdk-0.2.3.dist-info}/WHEEL +0 -0
- {aidbox_python_sdk-0.2.1.dist-info → aidbox_python_sdk-0.2.3.dist-info}/licenses/LICENSE.md +0 -0
- {aidbox_python_sdk-0.2.1.dist-info → aidbox_python_sdk-0.2.3.dist-info}/top_level.txt +0 -0
aidbox_python_sdk/__init__.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
__title__ = "aidbox-python-sdk"
|
|
2
|
-
__version__ = "0.2.
|
|
2
|
+
__version__ = "0.2.3"
|
|
3
3
|
__author__ = "beda.software"
|
|
4
4
|
__license__ = "None"
|
|
5
|
-
__copyright__ = "Copyright
|
|
5
|
+
__copyright__ = "Copyright 2026 beda.software"
|
|
6
6
|
|
|
7
7
|
# Version synonym
|
|
8
8
|
VERSION = __version__
|
aidbox_python_sdk/db.py
CHANGED
|
@@ -22,6 +22,36 @@ from aidbox_python_sdk.settings import Settings
|
|
|
22
22
|
|
|
23
23
|
from .exceptions import AidboxDBException
|
|
24
24
|
|
|
25
|
+
|
|
26
|
+
def parse_psql_response(response):
|
|
27
|
+
"""
|
|
28
|
+
Normalizes a $psql response into a list of result sets (one per statement).
|
|
29
|
+
Supports both formats:
|
|
30
|
+
- pre-2604: [{status, result: [row, ...], ...}]
|
|
31
|
+
- 2604+: {status, result: [{type, data: [row, ...]}, ...], ...}
|
|
32
|
+
Raises AidboxDBException on error status.
|
|
33
|
+
"""
|
|
34
|
+
entry = response[0] if isinstance(response, list) else response
|
|
35
|
+
|
|
36
|
+
if entry.get("status") == "error":
|
|
37
|
+
raise AidboxDBException(entry)
|
|
38
|
+
|
|
39
|
+
result = entry.get("result")
|
|
40
|
+
|
|
41
|
+
if not isinstance(result, list):
|
|
42
|
+
return [result] # None or True (old format execute=true)
|
|
43
|
+
|
|
44
|
+
if not result:
|
|
45
|
+
return [result]
|
|
46
|
+
|
|
47
|
+
# New format (2604+): result items carry {type, data}
|
|
48
|
+
if isinstance(result[0], dict) and "data" in result[0]:
|
|
49
|
+
return [rset["data"] for rset in result]
|
|
50
|
+
|
|
51
|
+
# Old format: single flat list of rows
|
|
52
|
+
return [result]
|
|
53
|
+
|
|
54
|
+
|
|
25
55
|
logger = logging.getLogger("aidbox_sdk.db")
|
|
26
56
|
table_metadata = MetaData()
|
|
27
57
|
|
|
@@ -124,10 +154,17 @@ class DBProxy:
|
|
|
124
154
|
) as resp:
|
|
125
155
|
logger.debug("$psql answer %s", await resp.text())
|
|
126
156
|
results = await resp.json()
|
|
127
|
-
|
|
128
|
-
if
|
|
129
|
-
|
|
130
|
-
|
|
157
|
+
result = parse_psql_response(results)
|
|
158
|
+
if execute:
|
|
159
|
+
return True
|
|
160
|
+
if len(result) > 1:
|
|
161
|
+
raise AidboxDBException(
|
|
162
|
+
{
|
|
163
|
+
"status": "error",
|
|
164
|
+
"error": "Multiple result sets returned; use execute=True for multi-statement queries",
|
|
165
|
+
}
|
|
166
|
+
)
|
|
167
|
+
return result[0]
|
|
131
168
|
|
|
132
169
|
def compile_statement(self, statement):
|
|
133
170
|
return str(
|
aidbox_python_sdk/handlers.py
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import asyncio
|
|
2
|
-
import json
|
|
3
2
|
import logging
|
|
4
3
|
from typing import Any
|
|
5
4
|
|
|
6
5
|
from aiohttp import web
|
|
7
|
-
from fhirpy.base.exceptions import
|
|
6
|
+
from fhirpy.base.exceptions import OperationOutcome
|
|
8
7
|
|
|
9
8
|
from . import app_keys as ak
|
|
10
9
|
|
|
@@ -49,12 +48,6 @@ async def operation(request: web.Request, data: dict[str, Any]):
|
|
|
49
48
|
return result
|
|
50
49
|
except OperationOutcome as exc:
|
|
51
50
|
return web.json_response(exc.resource, status=422)
|
|
52
|
-
except BaseFHIRError as exc:
|
|
53
|
-
try:
|
|
54
|
-
payload = json.loads(str(exc))
|
|
55
|
-
return web.json_response(payload, status=422)
|
|
56
|
-
except (json.JSONDecodeError, TypeError):
|
|
57
|
-
return web.Response(text=str(exc), status=422, content_type="text/plain")
|
|
58
51
|
|
|
59
52
|
|
|
60
53
|
TYPES = {
|
|
@@ -13,6 +13,7 @@ from yarl import URL
|
|
|
13
13
|
from aidbox_python_sdk.aidboxpy import AsyncAidboxClient
|
|
14
14
|
|
|
15
15
|
from . import app_keys as ak
|
|
16
|
+
from .db import parse_psql_response
|
|
16
17
|
|
|
17
18
|
_TEST_SERVER_URL = "http://127.0.0.1:8081"
|
|
18
19
|
|
|
@@ -100,7 +101,7 @@ async def safe_db(aidbox_client: AsyncAidboxClient, sdk):
|
|
|
100
101
|
"/$psql",
|
|
101
102
|
data={"query": "SELECT last_value from transaction_id_seq;"},
|
|
102
103
|
)
|
|
103
|
-
txid = results[0][
|
|
104
|
+
txid = parse_psql_response(results)[0][0]["last_value"]
|
|
104
105
|
sdk._test_start_txid = int(txid)
|
|
105
106
|
|
|
106
107
|
yield txid
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
aidbox_python_sdk/__init__.py,sha256=
|
|
1
|
+
aidbox_python_sdk/__init__.py,sha256=U0Ed_h7iQ9XWaRJHsZj4z2dcW3GQeZr4la7tq7mRRIg,192
|
|
2
2
|
aidbox_python_sdk/aidboxpy.py,sha256=7ewo0TO1FeGU8IVPqwm6PqR7-o8zSt3EvqPi2UfEWoE,4182
|
|
3
3
|
aidbox_python_sdk/app_keys.py,sha256=5ZkoJcJaUhMB-veQXVDzN_yQsOD2OOkGIIunNHujRyM,454
|
|
4
|
-
aidbox_python_sdk/db.py,sha256
|
|
4
|
+
aidbox_python_sdk/db.py,sha256=AQlju5V6F2l3HIxkaTbspx2gm4mBntO-gsIzhQgZW_M,8351
|
|
5
5
|
aidbox_python_sdk/db_migrations.py,sha256=xzTQKPyEsWQePyvaYFuHz7auCChMdTcUW8vEeY3QtkM,1459
|
|
6
6
|
aidbox_python_sdk/exceptions.py,sha256=hOn2rhEYNmuWuSiImObdd3R4xApsskmVdbVnb2PrIoA,116
|
|
7
|
-
aidbox_python_sdk/handlers.py,sha256=
|
|
7
|
+
aidbox_python_sdk/handlers.py,sha256=YEEhAkJBTjrtArwxLs8QWK1FEKvYLW6LSVZF17NpRjk,2832
|
|
8
8
|
aidbox_python_sdk/main.py,sha256=Gk-5QHo2MDQcNv7FMqmRD1JcKIJJiLdk6K4ce3Mb_pw,2464
|
|
9
9
|
aidbox_python_sdk/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
-
aidbox_python_sdk/pytest_plugin.py,sha256=
|
|
10
|
+
aidbox_python_sdk/pytest_plugin.py,sha256=wK5NqEwd9g2eDpRNv4MyFK9_ebmo56JfL4G4nUuMtXA,4845
|
|
11
11
|
aidbox_python_sdk/sdk.py,sha256=USzJryMYKGBt7SuCSt6YFjLsFqnMaTW-itxMJDl2dBo,9163
|
|
12
12
|
aidbox_python_sdk/settings.py,sha256=l-zdzH3UT4Pq_OjNgFe2ELmWKSjEnBgOAcChf-FQais,3231
|
|
13
13
|
aidbox_python_sdk/types.py,sha256=Oqcq4QZgOR71MwfoxW38-y9fWWUr49U5IoRS5LNbRq4,478
|
|
14
|
-
aidbox_python_sdk-0.2.
|
|
15
|
-
aidbox_python_sdk-0.2.
|
|
16
|
-
aidbox_python_sdk-0.2.
|
|
17
|
-
aidbox_python_sdk-0.2.
|
|
18
|
-
aidbox_python_sdk-0.2.
|
|
14
|
+
aidbox_python_sdk-0.2.3.dist-info/licenses/LICENSE.md,sha256=Opl86pEF7tgGGO2Wkdgfavnpi-MSgNY7RVJKxtZIGlE,1066
|
|
15
|
+
aidbox_python_sdk-0.2.3.dist-info/METADATA,sha256=c4J5riTGayBW3WXkV3rFzJi6gmCD1ICABApXtVS9JKI,11470
|
|
16
|
+
aidbox_python_sdk-0.2.3.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
17
|
+
aidbox_python_sdk-0.2.3.dist-info/top_level.txt,sha256=FJCCumQP-K5JkLtm0wispLy8Hy7ftneBaMMW-g5dvpQ,18
|
|
18
|
+
aidbox_python_sdk-0.2.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|