import postgres from 'postgres' let client = null /** * 현재 실행 환경이 운영인지 확인한다. * @returns {boolean} 운영 환경 여부 */ const isProductionRuntime = () => process.env.NODE_ENV === 'production' /** * PostgreSQL 클라이언트 조회 * @returns {ReturnType | null} PostgreSQL 클라이언트 */ export const getPostgresClient = () => { const config = useRuntimeConfig() if (!config.databaseUrl) { if (isProductionRuntime()) { throw new Error('DATABASE_URL_REQUIRED') } return null } if (!client) { client = postgres(config.databaseUrl, { max: 5, idle_timeout: 20, connect_timeout: 10 }) } return client }