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

io.github.methrat0n.restruct.handlers.bson.SimpleBsonFormaterInterpreter.scala Maven / Gradle / Ivy

The newest version!
package io.github.methrat0n.restruct.handlers.bson

import java.time.{ LocalDate, LocalTime, ZonedDateTime }

import reactivemongo.bson.DefaultBSONHandlers
import io.github.methrat0n.restruct.core.data.schema.SimpleSchemaAlgebra
import io.github.methrat0n.restruct.readers.bson.SimpleBsonReaderInterpreter
import io.github.methrat0n.restruct.writers.bson.SimpleBsonWriterInterpreter

trait SimpleBsonFormaterInterpreter extends SimpleSchemaAlgebra[BsonHandler] {

  private[this] object Reader extends SimpleBsonReaderInterpreter
  private[this] object Writer extends SimpleBsonWriterInterpreter

  override def charSchema: BsonHandler[Char] =
    BsonHandler(
      Reader.charSchema.read,
      Writer.charSchema.write
    )

  override def byteSchema: BsonHandler[Byte] =
    BsonHandler(
      Reader.byteSchema.read,
      Writer.byteSchema.write
    )

  override def shortSchema: BsonHandler[Short] =
    BsonHandler(
      Reader.shortSchema.read,
      Writer.shortSchema.write
    )

  override def floatSchema: BsonHandler[Float] =
    BsonHandler(
      Reader.floatSchema.read,
      Writer.floatSchema.write
    )

  override def decimalSchema: BsonHandler[Double] =
    DefaultBSONHandlers.BSONDoubleHandler.asInstanceOf[BsonHandler[Double]]

  override def bigDecimalSchema: BsonHandler[BigDecimal] =
    DefaultBSONHandlers.BSONDecimalHandler.asInstanceOf[BsonHandler[BigDecimal]]

  override def integerSchema: BsonHandler[Int] =
    DefaultBSONHandlers.BSONIntegerHandler.asInstanceOf[BsonHandler[Int]]

  override def longSchema: BsonHandler[Long] =
    DefaultBSONHandlers.BSONLongHandler.asInstanceOf[BsonHandler[Long]]

  override def bigIntSchema: BsonHandler[BigInt] =
    BsonHandler(
      Reader.bigIntSchema.read,
      Writer.bigIntSchema.write
    )

  override def booleanSchema: BsonHandler[Boolean] =
    DefaultBSONHandlers.BSONBooleanHandler.asInstanceOf[BsonHandler[Boolean]]

  override def stringSchema: BsonHandler[String] =
    DefaultBSONHandlers.BSONStringHandler.asInstanceOf[BsonHandler[String]]

  override def dateTimeSchema: BsonHandler[ZonedDateTime] =
    BsonHandler(
      Reader.dateTimeSchema.read,
      Writer.dateTimeSchema.write
    )

  override def timeSchema: BsonHandler[LocalTime] =
    BsonHandler(
      Reader.timeSchema.read,
      Writer.timeSchema.write
    )

  override def dateSchema: BsonHandler[LocalDate] =
    BsonHandler(
      Reader.dateSchema.read,
      Writer.dateSchema.write
    )
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy