from argparse import _SubParsersAction
from functools import partial
from lxml.objectify import IntElement, StringElement
from q2_sdk.core.dynamic_imports import (
api_ExecuteStoredProcedure as ExecuteStoredProcedure,
)
from .db_object import DbObject
from q2_sdk.hq.table_row import TableRow
[docs]
class VendorPropertyElementsRow(TableRow):
# object name: type hinting = "column name in the db response"
VendorPropertyElementID: IntElement = "VendorPropertyElementID"
VendorPropertyName: StringElement = "VendorPropertyName"
Description: StringElement = "Description"
DataTypeID: IntElement = "DataTypeID"
VendorID: IntElement = "VendorID"
[docs]
class VendorPropertyElements(DbObject):
# GET_BY_NAME_KEY = "column in the db response"
NAME = "VendorPropertyElements"
REPRESENTATION_ROW_CLASS = VendorPropertyElementsRow
[docs]
def add_arguments(self, parser: _SubParsersAction):
subparser = parser.add_parser("get_vendor_property_elements")
subparser.set_defaults(parser="get")
subparser.set_defaults(func=partial(self.get, serialize_for_cli=True))
subparser = parser.add_parser("add_vendor_property_elements")
subparser.set_defaults(parser="add_vendor_property_elements")
subparser.set_defaults(func=partial(self.add))
subparser.add_argument(
"property_name", help="Q2_VendorPropertyElements.PropertyName"
)
subparser.add_argument("vendor_id", help="Q2_VendorPropertyData.VendorID_")
subparser.add_argument(
"description", help="Q2_VendorPropertyElements.Description"
)
subparser.add_argument("data_type", help="Q2_DataType.DataType")
[docs]
async def get(self, serialize_for_cli=False) -> list[VendorPropertyElementsRow]:
response = await self.call_hq(
stored_proc_short_name="Q2_VendorPropertyDataElementGet"
)
if serialize_for_cli:
columns = [
"VendorPropertyElementID",
"VendorPropertyName",
"Description",
"DataTypeID",
"VendorID",
]
response = self.serialize_for_cli(response, columns)
return response
[docs]
async def add(
self, property_name: str, vendor_id: int, description: str, data_type: str
) -> list[VendorPropertyElementsRow]:
response = await self.call_hq(
stored_proc_short_name="Q2_VendorPropertyDataElementInsert",
sql_parameters=ExecuteStoredProcedure.SqlParameters([
ExecuteStoredProcedure.SqlParam(
ExecuteStoredProcedure.DataType.VarChar,
"propertyName",
property_name,
),
ExecuteStoredProcedure.SqlParam(
ExecuteStoredProcedure.DataType.Int, "vendorID", vendor_id
),
ExecuteStoredProcedure.SqlParam(
ExecuteStoredProcedure.DataType.VarChar, "desc", description
),
ExecuteStoredProcedure.SqlParam(
ExecuteStoredProcedure.DataType.VarChar, "datatype", data_type
),
]),
)
return response