Skip to content

Commit 571bb02

Browse files
committed
Add query.get_queries
1 parent 119821a commit 571bb02

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

labkey/query.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
4141
############################################################################
4242
"""
43+
44+
from dataclasses import dataclass, asdict
4345
import functools
4446
from typing import List, Literal, NotRequired, TextIO, TypedDict
4547

@@ -60,6 +62,7 @@ class Pagination:
6062
ALL = "all"
6163
NONE = "none"
6264

65+
6366
# TODO: Provide filter generators.
6467
#
6568
# There are some inconsistencies between the different filter types with multiple values,
@@ -143,7 +146,6 @@ class Types:
143146
ARRAY_ISEMPTY = "arrayisempty"
144147
ARRAY_ISNOTEMPTY = "arrayisnotempty"
145148

146-
147149
# Table/Query-wise operators
148150
Q = "q"
149151

@@ -704,6 +706,32 @@ def move_rows(
704706
)
705707

706708

709+
@dataclass
710+
class GetQueriesOptions:
711+
include_columns: bool
712+
include_system_queries: bool
713+
include_title: bool
714+
include_user_queries: bool
715+
include_view_data_url: bool
716+
query_detail_columns: bool
717+
718+
719+
def get_queries(
720+
server_context: ServerContext,
721+
schema_name: str,
722+
container_path: str = None,
723+
options: GetQueriesOptions = None,
724+
timeout=_default_timeout,
725+
) -> dict:
726+
url = server_context.build_url("query", "getQueries.api", container_path=container_path)
727+
payload = {"schemaName": schema_name}
728+
729+
if options is not None:
730+
payload = {*payload, *asdict(options)}
731+
732+
return server_context.make_request(url, payload, timeout=timeout)
733+
734+
707735
class QueryWrapper:
708736
"""
709737
Wrapper for all of the API methods exposed in the query module. Used by the APIWrapper class.
@@ -939,3 +967,13 @@ def move_rows(
939967
audit_user_comment,
940968
timeout,
941969
)
970+
971+
@functools.wraps(get_queries)
972+
def get_queries(
973+
self,
974+
schema_name: str,
975+
container_path: str = None,
976+
options: GetQueriesOptions = None,
977+
timeout=_default_timeout,
978+
):
979+
return get_queries(self.server_context, schema_name, container_path, options, timeout)

test/integration/test_query.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,3 +411,30 @@ def test_api_save_rows(api: APIWrapper, blood_sample_type_fixture, tissue_sample
411411
assert resp["result"][2]["rowsAffected"] == 1
412412
assert resp["result"][2]["rows"][0]["rowid"] == first_tissue_row_id
413413
assert resp["result"][2]["rows"][0]["receiveddate"] == "2025-07-07 12:34:56.000"
414+
415+
416+
expected_fields = {
417+
"canEdit",
418+
"canEditSharedViews",
419+
"columns",
420+
"hidden",
421+
"inherit",
422+
"isIncludedForLookups",
423+
"isInherited",
424+
"isMetadataOverrideable",
425+
"isUserDefined",
426+
"moduleName",
427+
"name",
428+
"snapshot",
429+
"title",
430+
"viewDataUrl",
431+
}
432+
433+
434+
def test_get_queries(api: APIWrapper):
435+
resp = api.query.get_queries("core")
436+
437+
assert set(resp.keys()) == {"schemaName", "queries"}
438+
assert resp["schemaName"] == "core"
439+
assert len(resp["queries"]) > 0
440+
assert set(resp["queries"][0].keys()) == set(expected_fields)

0 commit comments

Comments
 (0)