"""site_sections — **개인화 데이터**의 단일 자리.""" from sqlalchemy import select from sqlalchemy.dialects.postgresql import insert as pg_insert from common.database.db_session_manager import DB_SESSION_MNG from common.database.model.models import site_sections from common.utils.gtime import GTime class SiteSectionCRUD: async def list_by_site(self, db, site_id): return await DB_SESSION_MNG.execute( db, select(site_sections).where( site_sections.site_id == site_id, site_sections.deleted == False, # noqa: E712 ).order_by(site_sections.sort_order.asc()), ) async def upsert(self, db, values: dict): """섹션 하나의 개인화 값을 넣거나 갱신한다.""" stmt = pg_insert(site_sections).values(**values) return await DB_SESSION_MNG.add( db, stmt.on_conflict_do_update( index_elements=[site_sections.site_id, site_sections.section_id], index_where=(site_sections.deleted == False), # noqa: E712 set_={ "data": stmt.excluded.data, "shared_ref": stmt.excluded.shared_ref, "updated_at": GTime.UTC(), }, ), )