Skip to content

Commit

Permalink
Merge bb0f246 into 561b416
Browse files Browse the repository at this point in the history
  • Loading branch information
yaroot committed Jul 26, 2019
2 parents 561b416 + bb0f246 commit 735080e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ lazy val enumeratumDoobie =
libraryDependencies ++= {
Seq(
"com.beachape" %%% "enumeratum" % Versions.Core.stable,
"org.tpolecat" %% "doobie-postgres" % doobieVersion % Optional,
"org.tpolecat" %% "doobie-core" % doobieVersion
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package enumeratum.postgres

import doobie._
import doobie.postgres.implicits.pgEnumStringOpt
import enumeratum._

import scala.reflect.runtime.universe.TypeTag

object DoobiePgEnum {

/**
* {{{
* trait Foo extends EnumEntry
* object Foo extends Enum[Foo] {
* case object Bar extends Foo
*
* val values = findValues
* implicit val doobieMeta: Meta[Foo] = DoobiePgEnum("foo", Foo)
* }
* }}}
* @param name type in postgres
* @return Meta[A] for the given enum
*/
def meta[A <: EnumEntry: TypeTag](name: String, enum: Enum[A]): Meta[A] = {
pgEnumStringOpt(name, enum.withNameOption, _.entryName)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package enumeratum.postgres.values

import doobie._
import doobie.postgres.implicits.pgEnumStringOpt
import enumeratum.values.{StringEnumEntry, ValueEnum}

import scala.reflect.runtime.universe.TypeTag

object DoobiePgValueEnum {
def meta[A <: StringEnumEntry: TypeTag](name: String, enum: ValueEnum[String, A]): Meta[A] = {
pgEnumStringOpt(name, enum.withValueOpt, _.value)
}
}

0 comments on commit 735080e

Please sign in to comment.