All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.kaizensolutions.virgil.codecs.UdtValueDecoderMagnoliaDerivation.scala Maven / Gradle / Ivy

There is a newer version: 1.2.2
Show newest version
package io.kaizensolutions.virgil.codecs

import com.datastax.oss.driver.api.core.data.UdtValue
import io.kaizensolutions.virgil.annotations.CqlColumn
import magnolia1.*

import scala.deriving.Mirror

// Note: Fully automatic derivation is not yet present in Scala 3 just yet (because I haven't figured out how to do it yet)
trait UdtValueDecoderMagnoliaDerivation extends ProductDerivation[CqlUdtValueDecoder]:
  final def join[T](ctx: CaseClass[Typeclass, T]): CqlUdtValueDecoder.Object[T] =
    (structure: UdtValue) =>
      ctx.construct { param =>
        val fieldName = CqlColumn.extractFieldName(param.annotations).getOrElse(param.label)
        val decoder   = param.typeclass
        decoder.decodeByFieldName(structure, fieldName)
      }

  inline def derive[A](using Mirror.Of[A]): CqlUdtValueDecoder.Object[A] =
    derived.asInstanceOf[CqlUdtValueDecoder.Object[A]]




© 2015 - 2024 Weber Informatics LLC | Privacy Policy