api-foundry-query-engine 0.8.84__tar.gz → 0.8.86__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.
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/PKG-INFO +1 -1
- api_foundry_query_engine-0.8.86/api_foundry_query_engine/__init__.py +1 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/connectors/data_api_connection.py +5 -3
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/connectors/postgres_connection.py +13 -1
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/dao/sql_query_handler.py +15 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/lambda_handler.py +11 -3
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/operation.py +35 -21
- api_foundry_query_engine-0.8.86/api_foundry_query_engine/services/transactional_service.py +81 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/utils/api_model.py +44 -0
- api_foundry_query_engine-0.8.84/api_foundry_query_engine/__init__.py +0 -1
- api_foundry_query_engine-0.8.84/api_foundry_query_engine/services/transactional_service.py +0 -52
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/.gitignore +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/LICENSE +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/.pre-commit-config.yaml +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/adapters/adapter.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/adapters/gateway_adapter.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/connectors/connection.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/connectors/connection_factory.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/dao/batch_operation_handler.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/dao/dao.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/dao/operation_dao.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/dao/sql_custom_query_handler.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/dao/sql_delete_query_handler.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/dao/sql_insert_query_handler.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/dao/sql_restore_query_handler.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/dao/sql_select_query_handler.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/dao/sql_subselect_query_handler.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/dao/sql_update_query_handler.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/services/service.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/utils/app_exception.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/utils/claims_check.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/utils/dependency_resolver.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/utils/logger.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/utils/reference_resolver.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/api_foundry_query_engine/utils/token_decoder.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.86}/pyproject.toml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: api-foundry-query-engine
|
|
3
|
-
Version: 0.8.
|
|
3
|
+
Version: 0.8.86
|
|
4
4
|
Summary: The AWS lambda service handler use by the `api_foundry` project is a powerful tool designed to automate the deployment of REST APIs on AWS using Lambda services to access and interact with relational databases (RDBMS). This project leverages the OpenAPI specification to define and manage the APIs
|
|
5
5
|
Project-URL: Documentation, https://github.com/DanRepik/api-foundry
|
|
6
6
|
Project-URL: Source, https://github.com/DanRepik/api-foundry
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.8.86"
|
|
@@ -66,9 +66,11 @@ def _encode_parameter(value: Any) -> dict:
|
|
|
66
66
|
if isinstance(value, time_type):
|
|
67
67
|
return {"stringValue": value.strftime("%H:%M:%S.%f")}
|
|
68
68
|
if isinstance(value, (dict, list)):
|
|
69
|
-
#
|
|
70
|
-
#
|
|
71
|
-
#
|
|
69
|
+
# Postgres array columns (x-af-column-type "text[]" and the like)
|
|
70
|
+
# arrive as lists: the Data API has no array parameter, so they
|
|
71
|
+
# travel as JSON text and SQLQueryHandler.placeholder unpacks them.
|
|
72
|
+
# Embedded objects are already JSON text by now; dumping is also the
|
|
73
|
+
# only non-lossy fallback for anything else.
|
|
72
74
|
return {"stringValue": json.dumps(value)}
|
|
73
75
|
return {"stringValue": str(value)}
|
|
74
76
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
1
3
|
from api_foundry_query_engine.connectors.connection import (
|
|
2
4
|
Connection,
|
|
3
5
|
Cursor,
|
|
@@ -8,6 +10,16 @@ from api_foundry_query_engine.utils.logger import logger
|
|
|
8
10
|
# Initialize the logger
|
|
9
11
|
log = logger(__name__)
|
|
10
12
|
|
|
13
|
+
# postgresql://user:secret@host/db and "... password=secret ..."
|
|
14
|
+
_URI_PASSWORD = re.compile(r"(://[^:/@\s]*:)[^@\s]*(@)")
|
|
15
|
+
_KEYWORD_PASSWORD = re.compile(r"(\bpassword\s*=\s*)('(?:[^'\\]|\\.)*'|\S+)", re.IGNORECASE)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def redact_dsn(dsn: str) -> str:
|
|
19
|
+
"""The DSN with its password replaced, so it can be logged."""
|
|
20
|
+
dsn = _URI_PASSWORD.sub(r"\1***\2", dsn)
|
|
21
|
+
return _KEYWORD_PASSWORD.sub(r"\1***", dsn)
|
|
22
|
+
|
|
11
23
|
|
|
12
24
|
class PostgresCursor(Cursor):
|
|
13
25
|
def __init__(self, cursor):
|
|
@@ -121,7 +133,7 @@ class PostgresConnection(Connection):
|
|
|
121
133
|
|
|
122
134
|
# If DSN is provided, use it directly (simplifies fixture_foundry integration)
|
|
123
135
|
if "dsn" in self.db_config:
|
|
124
|
-
log.info("Connecting using DSN: %s", self.db_config["dsn"])
|
|
136
|
+
log.info("Connecting using DSN: %s", redact_dsn(self.db_config["dsn"]))
|
|
125
137
|
return connect(self.db_config["dsn"])
|
|
126
138
|
|
|
127
139
|
# Otherwise, build connection from individual parameters
|
|
@@ -185,6 +185,21 @@ class SQLQueryHandler:
|
|
|
185
185
|
elif property.column_type == "time":
|
|
186
186
|
return f"TO_TIME(:{param}, 'HH24:MI:SS.FF')"
|
|
187
187
|
return f":{param}"
|
|
188
|
+
element_type = getattr(property, "array_element_type", None)
|
|
189
|
+
if element_type and self.dialect == "postgres":
|
|
190
|
+
# A Postgres array column (x-af-column-type "text[]" and the
|
|
191
|
+
# like). The Data API can't bind an array parameter, so the
|
|
192
|
+
# value travels as JSON text (data_api_connection dumps a
|
|
193
|
+
# list) and is unpacked into an array of the column's element
|
|
194
|
+
# type; NULL stays NULL and [] becomes an empty array.
|
|
195
|
+
# psycopg2 adapts a list to ARRAY[...] itself; the cast types
|
|
196
|
+
# an empty list.
|
|
197
|
+
if self.driver == "data-api":
|
|
198
|
+
return (
|
|
199
|
+
f"CASE WHEN :{param}::jsonb IS NULL THEN NULL ELSE "
|
|
200
|
+
f"CAST(ARRAY(SELECT jsonb_array_elements_text(:{param}::jsonb)) AS {element_type}[]) END"
|
|
201
|
+
)
|
|
202
|
+
return f"CAST(%({param})s AS {element_type}[])"
|
|
188
203
|
if self.driver == "data-api":
|
|
189
204
|
# JSON-serialized properties (embedded objects/arrays, see
|
|
190
205
|
# SQLInsertSchemaQueryHandler.insert_values) always need a
|
|
@@ -80,13 +80,21 @@ class QueryEngine:
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
|
|
83
|
+
def load_engine_config():
|
|
84
|
+
log.info("Loading engine config from environment variables")
|
|
85
|
+
config = os.environ
|
|
86
|
+
# Names only: the Lambda environment holds the execution role's
|
|
87
|
+
# credentials (AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN) and often
|
|
88
|
+
# database DSNs with passwords.
|
|
89
|
+
log.debug("engine_config keys: %s", sorted(config))
|
|
90
|
+
return config
|
|
91
|
+
|
|
92
|
+
|
|
83
93
|
@token_decoder()
|
|
84
94
|
@claims_check(validate_path_scope=False, validate_scope_format=False)
|
|
85
95
|
def handler(event, _):
|
|
86
96
|
if not hasattr(handler, "engine_config"):
|
|
87
|
-
|
|
88
|
-
handler.engine_config = os.environ
|
|
89
|
-
log.info("engine_config: %s", handler.engine_config)
|
|
97
|
+
handler.engine_config = load_engine_config()
|
|
90
98
|
|
|
91
99
|
if not hasattr(handler, "query_engine"):
|
|
92
100
|
set_api_model(handler.engine_config)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import json
|
|
2
|
+
import re
|
|
2
3
|
from typing import Any, Dict, List, Optional
|
|
3
4
|
|
|
4
5
|
from api_foundry_query_engine.utils.logger import logger
|
|
@@ -98,14 +99,18 @@ class Operation:
|
|
|
98
99
|
def roles(self) -> List[str]:
|
|
99
100
|
"""Get the roles from claims.
|
|
100
101
|
|
|
101
|
-
Falls back to a singular `role` claim plus `groups`
|
|
102
|
-
plural `roles` key itself isn't present
|
|
103
|
-
a custom Lambda TOKEN authorizer
|
|
104
|
-
of a `role` string and a `groups`
|
|
102
|
+
Falls back to a singular `role` claim plus `groups` and
|
|
103
|
+
`cognito:groups` when the plural `roles` key itself isn't present
|
|
104
|
+
-- some authorizers (e.g. a custom Lambda TOKEN authorizer
|
|
105
|
+
following AWS's own convention of a `role` string and a `groups`
|
|
106
|
+
list, or API Gateway's Cognito user pool authorizer, which passes
|
|
107
|
+
the pool's groups as `cognito:groups`) never populate `roles`,
|
|
105
108
|
which previously made every such caller look role-less even with
|
|
106
|
-
a perfectly valid, correctly-scoped token.
|
|
107
|
-
|
|
108
|
-
context (whose values must be strings), a JSON-encoded
|
|
109
|
+
a perfectly valid, correctly-scoped token. Groups may arrive as a
|
|
110
|
+
real list or, when they passed through an API Gateway authorizer
|
|
111
|
+
context (whose values must be strings), as a JSON-encoded list, a
|
|
112
|
+
bracketed list ("[admin member]", "[admin, member]"), a
|
|
113
|
+
comma-separated string, or one group name.
|
|
109
114
|
"""
|
|
110
115
|
if not self.claims:
|
|
111
116
|
return []
|
|
@@ -118,20 +123,10 @@ class Operation:
|
|
|
118
123
|
if role:
|
|
119
124
|
fallback.append(str(role))
|
|
120
125
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
parsed = json.loads(groups_raw)
|
|
126
|
-
groups = [str(item) for item in parsed] if isinstance(parsed, list) else [groups_raw]
|
|
127
|
-
except (TypeError, ValueError):
|
|
128
|
-
groups = [groups_raw]
|
|
129
|
-
elif isinstance(groups_raw, list):
|
|
130
|
-
groups = [str(item) for item in groups_raw]
|
|
131
|
-
|
|
132
|
-
for group in groups:
|
|
133
|
-
if group not in fallback:
|
|
134
|
-
fallback.append(group)
|
|
126
|
+
for key in ("groups", "cognito:groups"):
|
|
127
|
+
for group in _parse_groups(self.claims.get(key)):
|
|
128
|
+
if group not in fallback:
|
|
129
|
+
fallback.append(group)
|
|
135
130
|
return fallback
|
|
136
131
|
|
|
137
132
|
def subject(self) -> Optional[str]:
|
|
@@ -141,3 +136,22 @@ class Operation:
|
|
|
141
136
|
def groups(self) -> List[str]:
|
|
142
137
|
"""Get the groups from claims."""
|
|
143
138
|
return self.claims.get("groups", []) if self.claims else []
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def _parse_groups(raw: Any) -> List[str]:
|
|
142
|
+
"""Group names from a groups claim, in any of the shapes an authorizer
|
|
143
|
+
passes them (see Operation.roles)."""
|
|
144
|
+
if isinstance(raw, (list, tuple)):
|
|
145
|
+
return [str(item) for item in raw if str(item).strip()]
|
|
146
|
+
if not isinstance(raw, str) or not raw.strip():
|
|
147
|
+
return []
|
|
148
|
+
text = raw.strip()
|
|
149
|
+
try:
|
|
150
|
+
parsed = json.loads(text)
|
|
151
|
+
if isinstance(parsed, list):
|
|
152
|
+
return [str(item) for item in parsed if str(item).strip()]
|
|
153
|
+
except (TypeError, ValueError):
|
|
154
|
+
pass
|
|
155
|
+
if text.startswith("[") and text.endswith("]"):
|
|
156
|
+
text = text[1:-1]
|
|
157
|
+
return [part for part in re.split(r"[\s,]+", text) if part]
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import traceback
|
|
2
|
+
from typing import Mapping, Optional
|
|
3
|
+
|
|
4
|
+
from api_foundry_query_engine.utils.logger import logger
|
|
5
|
+
from api_foundry_query_engine.utils.app_exception import ApplicationException
|
|
6
|
+
from api_foundry_query_engine.operation import Operation
|
|
7
|
+
from api_foundry_query_engine.services.service import ServiceAdapter
|
|
8
|
+
from api_foundry_query_engine.connectors.connection_factory import ConnectionFactory
|
|
9
|
+
from api_foundry_query_engine.dao.operation_dao import OperationDAO
|
|
10
|
+
from api_foundry_query_engine.utils.api_model import (
|
|
11
|
+
get_path_operation,
|
|
12
|
+
get_schema_object,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
log = logger(__name__)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class TransactionalService(ServiceAdapter):
|
|
19
|
+
def __init__(self, config: Mapping[str, str]):
|
|
20
|
+
super().__init__()
|
|
21
|
+
self.config = config
|
|
22
|
+
self.connection_factory = ConnectionFactory(config)
|
|
23
|
+
|
|
24
|
+
def execute(self, operation: Operation) -> list[dict]:
|
|
25
|
+
if operation.entity == "batch" and operation.action == "create":
|
|
26
|
+
database = self._batch_database(operation)
|
|
27
|
+
else:
|
|
28
|
+
database = self._database(operation.entity, operation.action)
|
|
29
|
+
if database is None:
|
|
30
|
+
raise ApplicationException(500, f"Unknown operation: {operation.entity}")
|
|
31
|
+
|
|
32
|
+
# Pass config to connection_factory if needed (future extension)
|
|
33
|
+
connection = self.connection_factory.get_connection(database)
|
|
34
|
+
|
|
35
|
+
try:
|
|
36
|
+
result = OperationDAO(operation, connection.engine()).execute(connection)
|
|
37
|
+
if operation.action != "read":
|
|
38
|
+
connection.commit()
|
|
39
|
+
if isinstance(result, dict):
|
|
40
|
+
return [result]
|
|
41
|
+
return result
|
|
42
|
+
except Exception as error:
|
|
43
|
+
log.error("transaction exception: %s", error)
|
|
44
|
+
log.error("traceback: %s", traceback.format_exc())
|
|
45
|
+
raise error
|
|
46
|
+
finally:
|
|
47
|
+
connection.close()
|
|
48
|
+
|
|
49
|
+
@staticmethod
|
|
50
|
+
def _database(entity, action) -> Optional[str]:
|
|
51
|
+
path_operation = get_path_operation(entity, action)
|
|
52
|
+
if path_operation:
|
|
53
|
+
return path_operation.database
|
|
54
|
+
schema_object = get_schema_object(entity)
|
|
55
|
+
if schema_object:
|
|
56
|
+
return schema_object.database
|
|
57
|
+
return None
|
|
58
|
+
|
|
59
|
+
def _batch_database(self, operation: Operation) -> str:
|
|
60
|
+
"""The database a batch runs against.
|
|
61
|
+
|
|
62
|
+
"batch" is not an entity in the API model, so the database comes
|
|
63
|
+
from the sub-operations. They share one connection, so they must all
|
|
64
|
+
resolve to the same database. A sub-operation naming an unknown
|
|
65
|
+
entity doesn't pick the database; it fails on its own inside the
|
|
66
|
+
batch, where continueOnError decides what happens next.
|
|
67
|
+
"""
|
|
68
|
+
operations = (operation.store_params or {}).get("operations")
|
|
69
|
+
if not isinstance(operations, list) or not operations:
|
|
70
|
+
raise ApplicationException(400, "Batch request must contain at least one operation")
|
|
71
|
+
|
|
72
|
+
databases = {self._database(op.get("entity"), op.get("action")) for op in operations if isinstance(op, dict)}
|
|
73
|
+
databases.discard(None)
|
|
74
|
+
if not databases:
|
|
75
|
+
raise ApplicationException(500, "Unknown operation: no batch operation names a known entity")
|
|
76
|
+
if len(databases) > 1:
|
|
77
|
+
raise ApplicationException(
|
|
78
|
+
400,
|
|
79
|
+
"Batch operations must all use the same database; got " + ", ".join(sorted(databases)),
|
|
80
|
+
)
|
|
81
|
+
return databases.pop()
|
|
@@ -1,13 +1,31 @@
|
|
|
1
|
+
import json
|
|
1
2
|
import os
|
|
3
|
+
import re
|
|
2
4
|
import yaml
|
|
3
5
|
|
|
4
6
|
from datetime import datetime
|
|
5
7
|
from typing import Any, Dict, List, Mapping, Optional
|
|
6
8
|
|
|
9
|
+
from api_foundry_query_engine.utils.app_exception import ApplicationException
|
|
7
10
|
from api_foundry_query_engine.utils.logger import logger
|
|
8
11
|
|
|
9
12
|
log = logger(__name__)
|
|
10
13
|
|
|
14
|
+
# A Postgres array column type: an element type followed by "[]", as in
|
|
15
|
+
# "text[]", "integer[]" or "character varying[]". The element type is
|
|
16
|
+
# interpolated into SQL casts, so only letters, digits, underscores and
|
|
17
|
+
# inner spaces are accepted.
|
|
18
|
+
_ARRAY_COLUMN_TYPE = re.compile(r"^\s*([A-Za-z][A-Za-z0-9_ ]*?)\s*\[\]\s*$")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def array_element_type(column_type: Optional[str]) -> Optional[str]:
|
|
22
|
+
"""The element type of an array column type ("text" for "text[]"), or
|
|
23
|
+
None when the column is not an array."""
|
|
24
|
+
if not isinstance(column_type, str):
|
|
25
|
+
return None
|
|
26
|
+
match = _ARRAY_COLUMN_TYPE.match(column_type)
|
|
27
|
+
return " ".join(match.group(1).lower().split()) if match else None
|
|
28
|
+
|
|
11
29
|
api_model = None
|
|
12
30
|
|
|
13
31
|
|
|
@@ -49,10 +67,19 @@ class SchemaObjectProperty:
|
|
|
49
67
|
def __repr__(self):
|
|
50
68
|
return f"SchemaObjectProperty(api_name={self.api_name}, column_name={self.column_name}, type={self.type})"
|
|
51
69
|
|
|
70
|
+
@property
|
|
71
|
+
def array_element_type(self) -> Optional[str]:
|
|
72
|
+
"""The element type when the column is a Postgres array
|
|
73
|
+
(x-af-column-type "text[]" and the like), else None."""
|
|
74
|
+
return array_element_type(self.column_type)
|
|
75
|
+
|
|
52
76
|
def convert_to_db_value(self, value) -> Optional[Any]:
|
|
53
77
|
if value is None:
|
|
54
78
|
return None
|
|
55
79
|
|
|
80
|
+
if self.array_element_type:
|
|
81
|
+
return self._convert_array(value)
|
|
82
|
+
|
|
56
83
|
column_type = self.column_type if self.column_type is not None else "string"
|
|
57
84
|
|
|
58
85
|
# Handle string types
|
|
@@ -105,6 +132,23 @@ class SchemaObjectProperty:
|
|
|
105
132
|
else:
|
|
106
133
|
return value
|
|
107
134
|
|
|
135
|
+
def _convert_array(self, value) -> list:
|
|
136
|
+
"""An array column's value: a list of scalars. A string (a query
|
|
137
|
+
parameter) must hold a JSON array."""
|
|
138
|
+
if isinstance(value, str):
|
|
139
|
+
try:
|
|
140
|
+
value = json.loads(value)
|
|
141
|
+
except ValueError:
|
|
142
|
+
value = None
|
|
143
|
+
if not isinstance(value, (list, tuple)) or any(
|
|
144
|
+
isinstance(item, (list, tuple, dict)) for item in value
|
|
145
|
+
):
|
|
146
|
+
raise ApplicationException(
|
|
147
|
+
400,
|
|
148
|
+
f"Property '{self.api_name}' is a {self.column_type} column and takes an array of scalar values",
|
|
149
|
+
)
|
|
150
|
+
return list(value)
|
|
151
|
+
|
|
108
152
|
def is_soft_delete_field(self) -> bool:
|
|
109
153
|
"""Check if this property is configured for soft delete."""
|
|
110
154
|
return self.soft_delete is not None
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.8.84"
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import traceback
|
|
2
|
-
from typing import Mapping
|
|
3
|
-
|
|
4
|
-
from api_foundry_query_engine.utils.logger import logger
|
|
5
|
-
from api_foundry_query_engine.utils.app_exception import ApplicationException
|
|
6
|
-
from api_foundry_query_engine.operation import Operation
|
|
7
|
-
from api_foundry_query_engine.services.service import ServiceAdapter
|
|
8
|
-
from api_foundry_query_engine.connectors.connection_factory import ConnectionFactory
|
|
9
|
-
from api_foundry_query_engine.dao.operation_dao import OperationDAO
|
|
10
|
-
from api_foundry_query_engine.utils.api_model import (
|
|
11
|
-
get_path_operation,
|
|
12
|
-
get_schema_object,
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
log = logger(__name__)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class TransactionalService(ServiceAdapter):
|
|
19
|
-
def __init__(self, config: Mapping[str, str]):
|
|
20
|
-
super().__init__()
|
|
21
|
-
self.config = config
|
|
22
|
-
self.connection_factory = ConnectionFactory(config)
|
|
23
|
-
|
|
24
|
-
def execute(self, operation: Operation) -> list[dict]:
|
|
25
|
-
path_operation = get_path_operation(operation.entity, operation.action)
|
|
26
|
-
if path_operation:
|
|
27
|
-
database = path_operation.database
|
|
28
|
-
else:
|
|
29
|
-
schema_object = get_schema_object(operation.entity)
|
|
30
|
-
if schema_object:
|
|
31
|
-
database = schema_object.database
|
|
32
|
-
else:
|
|
33
|
-
raise ApplicationException(
|
|
34
|
-
500, f"Unknown operation: {operation.entity}"
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
# Pass config to connection_factory if needed (future extension)
|
|
38
|
-
connection = self.connection_factory.get_connection(database)
|
|
39
|
-
|
|
40
|
-
try:
|
|
41
|
-
result = OperationDAO(operation, connection.engine()).execute(connection)
|
|
42
|
-
if operation.action != "read":
|
|
43
|
-
connection.commit()
|
|
44
|
-
if isinstance(result, dict):
|
|
45
|
-
return [result]
|
|
46
|
-
return result
|
|
47
|
-
except Exception as error:
|
|
48
|
-
log.error("transaction exception: %s", error)
|
|
49
|
-
log.error("traceback: %s", traceback.format_exc())
|
|
50
|
-
raise error
|
|
51
|
-
finally:
|
|
52
|
-
connection.close()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|