Saving recommended updates by the Svelte Gemini agent.
This commit is contained in:
@@ -2141,6 +2141,12 @@ def sql_search_qry_part(
|
||||
def process_node(query_node) -> str:
|
||||
clauses = []
|
||||
|
||||
# Process 'query_string' (Standardized Full-Text Search)
|
||||
if hasattr(query_node, 'query_string') and query_node.query_string:
|
||||
p_name = get_param_name()
|
||||
clauses.append(f"MATCH( default_qry_str ) AGAINST( :{p_name} IN BOOLEAN MODE )")
|
||||
data[p_name] = query_node.query_string
|
||||
|
||||
# Process 'and' filters
|
||||
if hasattr(query_node, 'and_filters') and query_node.and_filters:
|
||||
and_clauses = []
|
||||
|
||||
@@ -25,6 +25,7 @@ class SearchQuery(BaseModel):
|
||||
"""
|
||||
Represents a complex search query with optional logical grouping.
|
||||
"""
|
||||
query_string: Optional[str] = Field(None, alias="q")
|
||||
and_filters: Optional[List[Union[SearchFilter, 'SearchQuery']]] = Field(None, alias="and")
|
||||
or_filters: Optional[List[Union[SearchFilter, 'SearchQuery']]] = Field(None, alias="or")
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ async def get_obj(
|
||||
response: Response,
|
||||
obj_type_l1: str = Path(min_length=2, max_length=50),
|
||||
obj_id: str = Path(min_length=11, max_length=22),
|
||||
view: str = Query('default', description="Select alternative view/model (e.g., enriched, detail)"),
|
||||
account: AccountContext = Depends(get_account_context),
|
||||
serialization: SerializationParams = Depends(get_serialization_params),
|
||||
delay: DelayParams = Depends(get_delay_params),
|
||||
@@ -60,6 +61,7 @@ async def get_obj(
|
||||
using Redis for performance, falling back to SQL if not found.
|
||||
- Consistency: Uses 'obj_type_kv_li' from ae_obj_types_def.py to map URL paths
|
||||
to database views/tables and Pydantic models.
|
||||
- View Selection: Use the 'view' parameter to fetch a richer model (e.g., view=enriched).
|
||||
"""
|
||||
if delay.sleep_time_s > 0:
|
||||
await asyncio.sleep(delay.sleep_time_s)
|
||||
@@ -72,11 +74,13 @@ async def get_obj(
|
||||
return mk_resp(data=False, status_code=400, response=response, status_message=f"Object type '{obj_name}' not found.")
|
||||
|
||||
obj_cfg = obj_type_kv_li[obj_name]
|
||||
table_name = obj_cfg.get('tbl_default', obj_cfg.get('tbl'))
|
||||
base_name = obj_cfg.get('mdl_default', obj_cfg.get('mdl'))
|
||||
|
||||
# Support view selection: tbl_{view} and mdl_{view}
|
||||
table_name = obj_cfg.get(f'tbl_{view}', obj_cfg.get('tbl_default', obj_cfg.get('tbl')))
|
||||
base_name = obj_cfg.get(f'mdl_{view}', obj_cfg.get('mdl_default', obj_cfg.get('mdl')))
|
||||
|
||||
if not table_name or not base_name:
|
||||
return mk_resp(data=False, status_code=500, response=response, status_message=f"Configuration for object type '{obj_name}' is incomplete.")
|
||||
return mk_resp(data=False, status_code=500, response=response, status_message=f"Configuration for object type '{obj_name}' (view: {view}) is incomplete.")
|
||||
|
||||
record_id = redis_lookup_id_random(record_id_random=obj_id, table_name=obj_name)
|
||||
if not record_id:
|
||||
@@ -95,6 +99,7 @@ async def get_obj_li(
|
||||
obj_type_l1: str,
|
||||
for_obj_type: Optional[str] = None,
|
||||
for_obj_id: Optional[str] = None,
|
||||
view: str = Query('default'),
|
||||
order_by_li: Optional[str] = None,
|
||||
jp: Optional[Union[str, None]] = None,
|
||||
account: AccountContext = Depends(get_account_context),
|
||||
@@ -112,6 +117,7 @@ async def get_obj_li(
|
||||
- Flexible Querying: Supports complex JSON-based queries via the 'jp' parameter.
|
||||
- Contextual Filtering: Optionally filters by parent object relationship if
|
||||
'for_obj_type' and 'for_obj_id' are provided.
|
||||
- View Selection: Fetch alternative views (e.g., ?view=enriched).
|
||||
"""
|
||||
if delay.sleep_time_s > 0:
|
||||
await asyncio.sleep(delay.sleep_time_s)
|
||||
@@ -156,11 +162,13 @@ async def get_obj_li(
|
||||
return mk_resp(data=False, status_code=400, response=response, status_message=f"Object type '{obj_name}' not found.")
|
||||
|
||||
obj_cfg = obj_type_kv_li[obj_name]
|
||||
table_name = obj_cfg.get('tbl_default', obj_cfg.get('tbl'))
|
||||
base_name = obj_cfg.get('mdl_default', obj_cfg.get('mdl'))
|
||||
|
||||
# Support view selection: tbl_{view} and mdl_{view}
|
||||
table_name = obj_cfg.get(f'tbl_{view}', obj_cfg.get('tbl_default', obj_cfg.get('tbl')))
|
||||
base_name = obj_cfg.get(f'mdl_{view}', obj_cfg.get('mdl_default', obj_cfg.get('mdl')))
|
||||
|
||||
if not table_name or not base_name:
|
||||
return mk_resp(data=False, status_code=500, response=response, status_message=f"Configuration for object type '{obj_name}' is incomplete.")
|
||||
return mk_resp(data=False, status_code=500, response=response, status_message=f"Configuration for object type '{obj_name}' (view: {view}) is incomplete.")
|
||||
|
||||
if for_obj_type and for_obj_id:
|
||||
# Resolve random ID to integer ID
|
||||
@@ -219,6 +227,9 @@ async def search_obj_li(
|
||||
response: Response,
|
||||
obj_type_l1: str,
|
||||
search_query: SearchQuery,
|
||||
for_obj_type: Optional[str] = Query(None, description="Explicit parent type filter"),
|
||||
for_obj_id: Optional[str] = Query(None, description="Explicit parent ID filter"),
|
||||
view: str = Query('default', description="Select alternative view/model (e.g., enriched, detail)"),
|
||||
order_by_li: Optional[str] = Query(None),
|
||||
account: AccountContext = Depends(get_account_context),
|
||||
pagination: PaginationParams = Depends(get_pagination_params),
|
||||
@@ -232,7 +243,9 @@ async def search_obj_li(
|
||||
This endpoint supports:
|
||||
- Recursive AND/OR grouping
|
||||
- Operators: eq, ne, gt, gte, lt, lte, like, in, is_null, is_not_null
|
||||
- Large filters that would exceed URL length limits.
|
||||
- Hybrid Filtering: Combines standard query params (enabled, hidden, for_obj_type)
|
||||
with the complex logic in the body.
|
||||
- View Selection: Fetch richer models via the 'view' parameter.
|
||||
"""
|
||||
if delay.sleep_time_s > 0:
|
||||
await asyncio.sleep(delay.sleep_time_s)
|
||||
@@ -248,22 +261,43 @@ async def search_obj_li(
|
||||
return mk_resp(data=False, status_code=400, response=response, status_message=f"Object type '{obj_name}' not found.")
|
||||
|
||||
obj_cfg = obj_type_kv_li[obj_name]
|
||||
table_name = obj_cfg.get('tbl_default', obj_cfg.get('tbl'))
|
||||
base_name = obj_cfg.get('mdl_default', obj_cfg.get('mdl'))
|
||||
|
||||
# Support view selection: tbl_{view} and mdl_{view}
|
||||
table_name = obj_cfg.get(f'tbl_{view}', obj_cfg.get('tbl_default', obj_cfg.get('tbl')))
|
||||
base_name = obj_cfg.get(f'mdl_{view}', obj_cfg.get('mdl_default', obj_cfg.get('mdl')))
|
||||
|
||||
if not table_name or not base_name:
|
||||
return mk_resp(data=False, status_code=500, response=response, status_message=f"Configuration for object type '{obj_name}' is incomplete.")
|
||||
return mk_resp(data=False, status_code=500, response=response, status_message=f"Configuration for object type '{obj_name}' (view: {view}) is incomplete.")
|
||||
|
||||
sql_result = sql_select(
|
||||
table_name=table_name,
|
||||
enabled=status_filter.enabled,
|
||||
hidden=status_filter.hidden,
|
||||
search_query=search_query,
|
||||
order_by_li=order_by_li,
|
||||
limit=pagination.limit,
|
||||
offset=pagination.offset,
|
||||
as_list=True,
|
||||
)
|
||||
if for_obj_type and for_obj_id:
|
||||
# Resolve parentage context for search
|
||||
resolved_for_obj_id = redis_lookup_id_random(record_id_random=for_obj_id, table_name=for_obj_type)
|
||||
if not resolved_for_obj_id:
|
||||
return mk_resp(data=False, status_code=404, response=response, status_message=f"Parent object with ID '{for_obj_id}' not found.")
|
||||
|
||||
sql_result = sql_select(
|
||||
table_name=table_name,
|
||||
field_name=f'{for_obj_type}_id',
|
||||
field_value=resolved_for_obj_id,
|
||||
enabled=status_filter.enabled,
|
||||
hidden=status_filter.hidden,
|
||||
search_query=search_query,
|
||||
order_by_li=order_by_li,
|
||||
limit=pagination.limit,
|
||||
offset=pagination.offset,
|
||||
as_list=True,
|
||||
)
|
||||
else:
|
||||
sql_result = sql_select(
|
||||
table_name=table_name,
|
||||
enabled=status_filter.enabled,
|
||||
hidden=status_filter.hidden,
|
||||
search_query=search_query,
|
||||
order_by_li=order_by_li,
|
||||
limit=pagination.limit,
|
||||
offset=pagination.offset,
|
||||
as_list=True,
|
||||
)
|
||||
|
||||
if sql_result:
|
||||
resp_data_li = []
|
||||
|
||||
Reference in New Issue
Block a user