-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds the possibility to list saved queries from the GraphQL API.
- Loading branch information
1 parent
2f4889f
commit abf305c
Showing
9 changed files
with
122 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from dataclasses import dataclass | ||
from typing import Optional | ||
|
||
from dbtsl.models.base import BaseModel, GraphQLFragmentMixin | ||
|
||
|
||
@dataclass(frozen=True) | ||
class SavedQuery(BaseModel, GraphQLFragmentMixin): | ||
"""A saved query.""" | ||
|
||
name: str | ||
description: Optional[str] | ||
label: Optional[str] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""Fetch all available saved queries from the metadata API and display them.""" | ||
|
||
import asyncio | ||
from argparse import ArgumentParser | ||
|
||
from dbtsl.asyncio import AsyncSemanticLayerClient | ||
|
||
|
||
def get_arg_parser() -> ArgumentParser: | ||
p = ArgumentParser() | ||
|
||
p.add_argument("--env-id", required=True, help="The dbt environment ID", type=int) | ||
p.add_argument("--token", required=True, help="The API auth token") | ||
p.add_argument("--host", required=True, help="The API host") | ||
|
||
return p | ||
|
||
|
||
async def main() -> None: | ||
arg_parser = get_arg_parser() | ||
args = arg_parser.parse_args() | ||
|
||
client = AsyncSemanticLayerClient( | ||
environment_id=args.env_id, | ||
auth_token=args.token, | ||
host=args.host, | ||
) | ||
|
||
async with client.session(): | ||
saved_queries = await client.saved_queries() | ||
for sq in saved_queries: | ||
print(f"{sq.name}:") | ||
print(f" label: {sq.label}") | ||
print(f" description: {sq.description}") | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters