# Path: irisett/sql.py
# class DBConnection:
#     def __init__(self, host: str, user: str, passwd: str, dbname: str, loop: asyncio.AbstractEventLoop=None) -> None:
#     async def initialize(self, *, only_init_tables: bool=False):
#     async def close(self) -> None:
#     async def _create_db(self) -> None:
#     async def _init_db(self, only_init_tables: bool) -> None:
#     async def _check_db_exists(self) -> bool:
#     async def _check_db_initialized(self) -> bool:
#     async def _upgrade_db(self) -> None:
#     async def _get_db_version(self) -> int:
#     async def _set_db_version(self, version: int):
#     async def fetch_all(self, query: str, args: Optional[Iterable]=None) -> List:
#     async def fetch_row(self, query: str, args: Optional[Iterable]=None) -> List:
#     async def fetch_single(self, query: str, args: Optional[Iterable]=None) -> Any:
#     async def count_rows(self, query: str, args: Optional[Iterable]=None) -> float:
#     async def operation(self, query: str, args: Optional[Iterable]=None) -> Any:
#     async def transact(self, func: Callable[..., Any], *args: Any, **kwargs: Any) -> Any:
# 
# Path: irisett/object_models.py
# def insert_values(object: Any) -> Tuple:
# def list_asdict(in_list: Iterable[Any]) -> List[Any]:
# def insert_filter(attribute: Any, value: Any) -> bool:
# class Contact:
# class ContactGroup:
# class ActiveMonitor:
# class ActiveMonitorArg:
# class ActiveMonitorAlert:
# class ActiveMonitorDef:
# class ActiveMonitorDefArg:
# class ObjectMetadata:
# class ObjectBindata:
# class MonitorGroup:


from typing import Dict, Iterable, Optional, Tuple
from irisett.sql import DBConnection, Cursor
from irisett import object_models
    q = """select `key`, value from object_metadata where object_type=%s and object_id=%s"""
    q_args = (object_type, object_id)
    rows = await dbcon.fetch_all(q, q_args)
    metadict = {}
    for key, value in rows:
        metadict[key] = value
    return metadict


async def add_metadata(dbcon: DBConnection, object_type: str, object_id: int, metadict: Dict[str, str]):
    """Add metadata to an object.

    Metadict is a dictionary of key value pairs to add.
    """

    async def _run(cur: Cursor) -> None:
        q = """insert into object_metadata (object_type, object_id, `key`, value) values (%s, %s, %s, %s)"""
        for key, value in metadict.items():
            q_args = (object_type, object_id, str(key), str(value))
            await cur.execute(q, q_args)

    await dbcon.transact(_run)


async def update_metadata(dbcon: DBConnection, object_type: str, object_id: int, metadict: Dict[str, str]):
    """Update metadata values for an object.

    Metadict is a dictionary of key value pairs to add.
    """


# Path: irisett/sql.py
# class DBConnection:
#     def __init__(self, host: str, user: str, passwd: str, dbname: str, loop: asyncio.AbstractEventLoop=None) -> None:
#     async def initialize(self, *, only_init_tables: bool=False):
#     async def close(self) -> None:
#     async def _create_db(self) -> None:
#     async def _init_db(self, only_init_tables: bool) -> None:
#     async def _check_db_exists(self) -> bool:
#     async def _check_db_initialized(self) -> bool:
#     async def _upgrade_db(self) -> None:
#     async def _get_db_version(self) -> int:
#     async def _set_db_version(self, version: int):
#     async def fetch_all(self, query: str, args: Optional[Iterable]=None) -> List:
#     async def fetch_row(self, query: str, args: Optional[Iterable]=None) -> List:
#     async def fetch_single(self, query: str, args: Optional[Iterable]=None) -> Any:
#     async def count_rows(self, query: str, args: Optional[Iterable]=None) -> float:
#     async def operation(self, query: str, args: Optional[Iterable]=None) -> Any:
#     async def transact(self, func: Callable[..., Any], *args: Any, **kwargs: Any) -> Any:
# 
# Path: irisett/object_models.py
# def insert_values(object: Any) -> Tuple:
# def list_asdict(in_list: Iterable[Any]) -> List[Any]:
# def insert_filter(attribute: Any, value: Any) -> bool:
# class Contact:
# class ContactGroup:
# class ActiveMonitor:
# class ActiveMonitorArg:
# class ActiveMonitorAlert:
# class ActiveMonitorDef:
# class ActiveMonitorDefArg:
# class ObjectMetadata:
# class ObjectBindata:
# class MonitorGroup:


# Path: irisett/metadata.py
from typing import Dict, Iterable, Optional, Tuple
from irisett.sql import DBConnection, Cursor
from irisett import object_models

    q = """select `key`, value from object_metadata where object_type=%s and object_id=%s"""
    q_args = (object_type, object_id)
    rows = await dbcon.fetch_all(q, q_args)
    metadict = {}
    for key, value in rows:
        metadict[key] = value
    return metadict


async def add_metadata(dbcon: DBConnection, object_type: str, object_id: int, metadict: Dict[str, str]):
    """Add metadata to an object.

    Metadict is a dictionary of key value pairs to add.
    """

    async def _run(cur: Cursor) -> None:
        q = """insert into object_metadata (object_type, object_id, `key`, value) values (%s, %s, %s, %s)"""
        for key, value in metadict.items():
            q_args = (object_type, object_id, str(key), str(value))
            await cur.execute(q, q_args)

    await dbcon.transact(_run)


async def update_metadata(dbcon: DBConnection, object_type: str, object_id: int, metadict: Dict[str, str]):
    """Update metadata values for an object.

    Metadict is a dictionary of key value pairs to add.
    """


    async def _run(cur: Cursor) -> None: