from argparse import _SubParsersAction
from functools import partial
from typing import List
from lxml.objectify import IntElement, StringElement
from q2_sdk.core.dynamic_imports import (
api_ExecuteStoredProcedure as ExecuteStoredProcedure,
)
from .db_object import DbObject
from .representation_row_base import RepresentationRowBase
[docs]
class BranchRow(RepresentationRowBase):
BranchID: IntElement = "BranchID"
HostBranch: StringElement = "HostBranch"
BranchName: StringElement = "BranchName"
[docs]
class Branch(DbObject):
NAME = "BranchName"
REPRESENTATION_ROW_CLASS = BranchRow
[docs]
def add_arguments(self, parser: _SubParsersAction):
subparser = parser.add_parser("get_branch")
subparser.set_defaults(parser="get")
subparser.set_defaults(func=partial(self.get, serialize_for_cli=True))
[docs]
async def get(self, serialize_for_cli=False) -> List[BranchRow]:
response = await self.call_hq(
"sdk_GetBranch", ExecuteStoredProcedure.SqlParameters([])
)
if serialize_for_cli:
columns = ["BranchID", "HostBranch", "BranchName"]
response = self.serialize_for_cli(response, columns)
return response