underscoreio/slickless

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

Homepage:

Size: 44

Language: Scala

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

slickless

Build Status Coverage status Join the chat at https://gitter.im/underscoreio/slickless

Shapeless HList support for Slick.

by Richard Dallaway, Miles Sabin, and Dave Gurnell.

Copyright 2015-2018 Underscore Consulting LLP. Licensed Apache 2.

Versions

| Scala | Slick | Slickless | |——-|———-|———-| | 2.12 | 3.2 | Maven Central | | 2.11 | 3.1 | Maven Central |

Getting Started

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>>"

Synopsis

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]
Notes
Compile time

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 <>.

Build example without default resolvers

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"

Publishing

We use the sbt-pgp plugin and the sbt-sonatype plugin to publish to Maven Central.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.