Query Loaders
Definition of loader for queries from files and directories.
load_query_data_from_dir_path(dir_path)
¶
Load queries from esdl file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dir_path |
Path |
path to file with queriesto be parsed. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Union[edgeql_queries.models.Query, QueriesTree]] |
List of queries that will be used later by container for them. |
Exceptions:
Type | Description |
---|---|
ValueError |
if dir_path is not directory. |
Source code in edgeql_queries/query_loaders.py
def load_query_data_from_dir_path(dir_path: Path) -> QueriesTree:
"""Load queries from esdl file.
Arguments:
dir_path: path to file with queriesto be parsed.
Returns:
List of [queries][edgeql_queries.models.Query] that will be used
later by [container][edgeql_queries.queries.Queries] for them.
Raises:
ValueError: if dir_path is not directory.
"""
if not dir_path.is_dir():
raise ValueError("path {0} must be a directory".format(dir_path))
return _load_query_data_tree(dir_path, dir_path)
load_query_data_from_edgeql(edgeql)
¶
Load queries from string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edgeql |
str |
edgeql string that contains queries to be parsed. |
required |
Returns:
Type | Description |
---|---|
List[edgeql_queries.models.Query] |
List of queries that will be used later by container for them. |
Source code in edgeql_queries/query_loaders.py
def load_query_data_from_edgeql(edgeql: str) -> List[Query]:
"""Load queries from string.
Arguments:
edgeql: edgeql string that contains queries to be parsed.
Returns:
List of [queries][edgeql_queries.models.Query] that will be used
later by [container][edgeql_queries.queries.Queries] for them.
"""
query_data = []
matches_iter = _iter_pairs(QUERY_DEFINITION_PATTERN.finditer(edgeql))
for (start_match, end_match) in matches_iter:
if end_match is not None:
end_position = end_match.start()
else:
end_position = len(edgeql)
query_data.append(
parse_query_from_string(
start_match.groups()[0],
edgeql[start_match.end() : end_position],
),
)
return query_data
load_query_data_from_file(file_path)
¶
Load queries from esdl file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
Path |
path to file with queries to be parsed. |
required |
Returns:
Type | Description |
---|---|
List[edgeql_queries.models.Query] |
List of queries that will be used later by container for them. |
Exceptions:
Type | Description |
---|---|
FileNotFoundError |
if failed to open file. # noqa: DAR402 |
Source code in edgeql_queries/query_loaders.py
def load_query_data_from_file(file_path: Path) -> List[Query]:
"""Load queries from esdl file.
Arguments:
file_path: path to file with queries to be parsed.
Returns:
List of [queries][edgeql_queries.models.Query] that will be used
later by [container][edgeql_queries.queries.Queries] for them.
Raises:
FileNotFoundError: if failed to open file. # noqa: DAR402
"""
with open(file_path) as edgeql_file:
return load_query_data_from_edgeql(edgeql_file.read())