-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
enumeratum-doobie/src/main/scala/enumeratum/postgres/DoobiePgEnum.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
enumeratum-doobie/src/main/scala/enumeratum/postgres/values/DoobiePgValueEnum.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |