Front-End

prisma-format (자동 camelCase 변환 CLI 도구)

철냄비짱 2025. 4. 8. 09:33
반응형

npx prisma-format --map-fields
model cms_board_data {
  createDate DateTime @map("create_date")  // ✅ 자동으로 바뀜!
}

 

// snake_case → camelCase 변환기 예시
function toCamel(str: string) {
  return str.replace(/_([a-z])/g, (_, g) => g.toUpperCase())
}

 

const prisma = new PrismaClient().$extends({
  result: {
    $allModels: {
      $allFields: {
        compute(value, fieldName) {
          const camelField = toCamel(fieldName)
          return { [camelField]: value }
        }
      }
    }
  }
})

 

# 1. DB 구조 가져오기
npx prisma db pull

# 2. camelCase 자동 변환 + @map 추가
npx prisma-format --map-fields
반응형