Skip to content

Instantly share code, notes, and snippets.

@domdorn
Created January 19, 2021 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domdorn/e5d2b09ab98ab4f7745857d8ee8e79fe to your computer and use it in GitHub Desktop.
Save domdorn/e5d2b09ab98ab4f7745857d8ee8e79fe to your computer and use it in GitHub Desktop.
Slick PostgreSQL List
trait MyPostgresProfile
extends ExPostgresProfile
with PgArraySupport
with PgDate2Support
with PgRangeSupport
with PgHStoreSupport {
def pgjson = "jsonb"
// Add back `capabilities.insertOrUpdate` to enable native `upsert` support; for postgres 9.5+
override protected def computeCapabilities: Set[Capability] =
super.computeCapabilities + slick.jdbc.JdbcCapabilities.insertOrUpdate
override val api = MyAPI
object MyAPI extends API with ArrayImplicits with DateTimeImplicits with RangeImplicits with HStoreImplicits {
val strSimpleJdbcArrayListType: SimpleArrayJdbcType[String] = new SimpleArrayJdbcType[String]("text")
implicit val strListTypeMapper: JdbcType[List[String]] =
strSimpleJdbcArrayListType.to(_.toList)
// here we
implicit val useCaseListTypeMapper: JdbcType[List[UseCase]] = strSimpleJdbcArrayListType
.mapTo[UseCase](str => UseCase.of(str), uc => uc.label)
.to(_.toList)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment