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

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

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

import com.datastax.oss.driver.api.core.cql.Row
import io.kaizensolutions.virgil.annotations.CqlColumn
import magnolia1._

trait RowDecoderMagnoliaDerivation {
  type Typeclass[T] = CqlRowDecoder[T]

  def join[T](ctx: CaseClass[CqlRowDecoder, T]): CqlRowDecoder.Object[T] =
    new CqlRowDecoder.Object[T] {
      override def decode(row: Row): T =
        ctx.construct { p =>
          val fieldName = CqlColumn.extractFieldName(p.annotations).getOrElse(p.label)
          p.typeclass.decodeByFieldName(row, fieldName)
        }
    }

  implicit def derive[T]: CqlRowDecoder.Object[T] = macro Magnolia.gen[T]
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy