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

doobie.enum.autogeneratedkeys.scala Maven / Gradle / Ivy

The newest version!
package doobie.enum

import doobie.util.invariant._

import java.sql.Statement._

import scalaz.Equal
import scalaz.std.anyVal.intInstance

object autogeneratedkeys {

  /** @group Implementation */
  sealed abstract class AutoGeneratedKeys(val toInt: Int)

  /** @group Values */ case object ReturnGeneratedKeys extends AutoGeneratedKeys(RETURN_GENERATED_KEYS)
  /** @group Values */ case object NoGeneratedKeys extends AutoGeneratedKeys(NO_GENERATED_KEYS)

  /** @group Implementation */
  object AutoGeneratedKeys {

    def fromInt(n: Int): Option[AutoGeneratedKeys] =
      Some(n) collect {
        case ReturnGeneratedKeys.toInt => ReturnGeneratedKeys
        case NoGeneratedKeys.toInt => NoGeneratedKeys
      }

    def unsafeFromInt(n: Int): AutoGeneratedKeys =
      fromInt(n).getOrElse(throw InvalidOrdinal[AutoGeneratedKeys](n))

    implicit val EqualAutoGeneratedKeys: Equal[AutoGeneratedKeys] =
      Equal.equalBy(_.toInt)

  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy