4040
4141############################################################################
4242"""
43+
4344import functools
4445from typing import List , Literal , NotRequired , TextIO , TypedDict
4546
4647from .server_context import ServerContext
47- from .utils import waf_encode
48+ from .utils import waf_encode , transform_options
4849
4950_default_timeout = 60 * 5 # 5 minutes
5051
@@ -60,6 +61,7 @@ class Pagination:
6061 ALL = "all"
6162 NONE = "none"
6263
64+
6365# TODO: Provide filter generators.
6466#
6567# There are some inconsistencies between the different filter types with multiple values,
@@ -143,7 +145,6 @@ class Types:
143145 ARRAY_ISEMPTY = "arrayisempty"
144146 ARRAY_ISNOTEMPTY = "arrayisnotempty"
145147
146-
147148 # Table/Query-wise operators
148149 Q = "q"
149150
@@ -704,6 +705,53 @@ def move_rows(
704705 )
705706
706707
708+ get_queries_fields = [
709+ "schema_name" ,
710+ "include_columns" ,
711+ "include_system_queries" ,
712+ "include_title" ,
713+ "include_user_queries" ,
714+ "include_view_data_url" ,
715+ "query_detail_columns" ,
716+ ]
717+
718+
719+ def get_queries (
720+ server_context : ServerContext ,
721+ schema_name : str ,
722+ container_path : str = None ,
723+ timeout = _default_timeout ,
724+ ** kwargs ,
725+ ) -> dict :
726+ """
727+ :param server_context: A LabKey server context. See utils.create_server_context.
728+ :param schema_name: schema of table
729+ :param container_path: folder path if not already part of server_context
730+ :param timeout: Request timeout in seconds (defaults to 300s)
731+ :param kwargs: Optional parameters supported by this API:
732+ include_columns: boolean, if set to False, information about the available columns in this query will not be
733+ included in the results. Default is True.
734+ include_system_queries: boolean, if set to false, system-defined queries will not be included in the results.
735+ Default is True.
736+ include_title: boolean, if set to False, no custom query titles will be included. Instead, titles will be
737+ identical to names. Default is True.
738+ include_user_queries: boolean, if set to False, user-defined queries will not be included in the results.
739+ Default is True.
740+ include_view_data_url: boolean, if set to False, view data URLs will not be included in the results.
741+ Default is True.
742+ query_detail_columns: boolean, if set to True, and includeColumns is set to True, information about the
743+ available columns will be the same details as specified by getQueryDetails for columns. Defaults to False.
744+ :return: dict
745+ """
746+ url = server_context .build_url ("query" , "getQueries.api" , container_path = container_path )
747+ payload = {"schemaName" : schema_name }
748+
749+ if len (kwargs ) > 0 :
750+ payload = {** payload , ** transform_options (kwargs , get_queries_fields )}
751+
752+ return server_context .make_request (url , payload , timeout = timeout )
753+
754+
707755class QueryWrapper :
708756 """
709757 Wrapper for all of the API methods exposed in the query module. Used by the APIWrapper class.
@@ -939,3 +987,29 @@ def move_rows(
939987 audit_user_comment ,
940988 timeout ,
941989 )
990+
991+ @functools .wraps (get_queries )
992+ def get_queries (
993+ self ,
994+ schema_name : str ,
995+ container_path : str = None ,
996+ include_columns : bool = None ,
997+ include_system_queries : bool = None ,
998+ include_title : bool = None ,
999+ include_user_queries : bool = None ,
1000+ include_view_data_url : bool = None ,
1001+ query_detail_columns : bool = None ,
1002+ timeout = _default_timeout ,
1003+ ):
1004+ return get_queries (
1005+ self .server_context ,
1006+ schema_name ,
1007+ container_path ,
1008+ timeout ,
1009+ include_columns = include_columns ,
1010+ include_system_queries = include_system_queries ,
1011+ include_title = include_title ,
1012+ include_user_queries = include_user_queries ,
1013+ include_view_data_url = include_view_data_url ,
1014+ query_detail_columns = query_detail_columns ,
1015+ )
0 commit comments