# -*- coding: utf-8 -*-
from sqlalchemy import create_engine, text
import json

engine = create_engine('postgresql://admin:trajet6640@192.168.0.87:5432/apdb_master')
with engine.connect() as conn:
    result = conn.execute(text("""
        SELECT apc, product_name, llm_pharm, main_ingredient, component_name_ko
        FROM apc 
        WHERE product_name ILIKE '%티어가드%60mg%'
        ORDER BY apc
        LIMIT 3
    """))
    
    print('=== 티어가드 60mg 허가사항 상세 ===')
    for row in result:
        print(f'APC: {row.apc}')
        print(f'제품명: {row.product_name}')
        print(f'main_ingredient: {row.main_ingredient}')
        print(f'component_name_ko: {row.component_name_ko}')
        if row.llm_pharm:
            llm = row.llm_pharm if isinstance(row.llm_pharm, dict) else json.loads(row.llm_pharm)
            print('llm_pharm 내용:')
            for k, v in llm.items():
                print(f'  {k}: {v}')
        print()
