// lib/vendor-data-plant/queries.ts "use server" import db from "@/db/db" import { tagsPlant } from "@/db/schema/vendorData" import { eq, and } from "drizzle-orm" import { revalidateTag, unstable_noStore } from "next/cache"; /** * 모든 태그 가져오기 (클라이언트 렌더링용) */ export async function getAllTagsPlant( projectCode: string, packageCode: string ) { unstable_noStore(); try { const tags = await db .select() .from(tagsPlant) .where( and( eq(tagsPlant.projectCode, projectCode), eq(tagsPlant.packageCode, packageCode) ) ) .orderBy(tagsPlant.createdAt) return tags } catch (error) { console.error("Error fetching all tags:", error) return [] } } /** * 고유 속성 키 추출 */ export async function getUniqueAttributeKeys( projectCode: string, packageCode: string ): Promise { try { const result = await db .select({ attributes: tagsPlant.attributes }) .from(tagsPlant) .where( and( eq(tagsPlant.projectCode, projectCode), eq(tagsPlant.packageCode, packageCode) ) ) const allKeys = new Set() for (const row of result) { if (row.attributes && typeof row.attributes === 'object') { Object.keys(row.attributes).forEach(key => allKeys.add(key)) } } return Array.from(allKeys).sort() } catch (error) { console.error("Error getting unique attribute keys:", error) return [] } }