Name: slickless
Owner: Underscore
Description: Support for shapeless HLists/Generics in Slick.
Created: 2015-08-07 11:01:50.0
Updated: 2018-05-23 21:59:24.0
Pushed: 2018-03-23 12:31:37.0
Size: 44
Language: Scala
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Shapeless HList support for Slick.
by Richard Dallaway, Miles Sabin, and Dave Gurnell.
Copyright 2015-2018 Underscore Consulting LLP. Licensed Apache 2.
| Scala | Slick | Slickless | |——-|———-|———-| | 2.12 | 3.2 | | | 2.11 | 3.1 | |
Grab the code by adding the following to your build.sbt
:
aryDependencies ++= Seq(
om.typesafe.slick" %% "slick" % "3.2.1",
om.chuusai" %% "shapeless" % "2.3.3",
o.underscore" %% "slickless" % "<<VERSION>>"
Import Slick, shapeless, and slickless,
and you should be able to define Tables
on any shapeless HList
type:
rt slick.jdbc.H2Profile.api._
rt shapeless.{ HList, ::, HNil }
rt slickless._
s Users(tag: Tag) extends Table[Long :: String :: HNil](tag, "users") {
f id = column[Long]( "id", O.PrimaryKey, O.AutoInc )
f email = column[String]("email")
f * = id :: email :: HNil
val users = TableQuery[Users]
If you want to map your HList
to a case class
(i.e. you have a case class that has more than
22 fields and you are using slickless to bypass this limit),
you can do the following
rt slick.jdbc.H2Profile.api._
rt shapeless.{ HList, ::, HNil, Generic }
rt slickless._
class User(id: Long, email: String)
s Users(tag: Tag) extends Table[User](tag, "users") {
f id = column[Long]( "id", O.PrimaryKey, O.AutoInc )
f email = column[String]("email")
f * = (id :: email :: HNil).mappedWith(Generic[User])
val users = TableQuery[Users]
Due to this issue,
if you accidentally make a mapping which is incorrect,
the Scala compiler can take a huge amount of time to report an error.
If your slickless project is taking an insanely long amount of time to compile
(more than a couple of minutes),
try to make sure you have the mapping correct before using <>
.
If you need to add resolvers into your build, here's an example:
lvers += "Maven Central" at "https://repo1.maven.org/maven2/"
lvers += Resolver.sonatypeRepo("releases")
lvers += Resolver.sonatypeRepo("snapshots")
aryDependencies ++= Seq(
om.typesafe.slick" %% "slick" % "3.2.1",
om.chuusai" %% "shapeless" % "2.3.3",
o.underscore" %% "slickless" % "0.3.3"
We use the sbt-pgp plugin and the sbt-sonatype plugin to publish to Maven Central.