• Stars
    star
    164
  • Rank 230,032 (Top 5 %)
  • Language
    Scala
  • License
    Apache License 2.0
  • Created over 9 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Support for shapeless HLists/Generics in Slick.

slickless

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

Shapeless HList support for Slick.

by Richard Dallaway, Miles Sabin, and Dave Gurnell.

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

Versions

Scala Slick Slickless
2.13 3.3 Maven Central
2.12 3.3 Maven Central
2.12 3.2 0.3.3
2.11 3.1 0.3.0

Getting Started

Grab the code by adding the following to your build.sbt:

libraryDependencies ++= Seq(
  "com.typesafe.slick" %% "slick"     % "3.3.2",
  "com.chuusai"        %% "shapeless" % "2.3.3",
  "io.underscore"      %% "slickless" % "<<VERSION>>"
)

Synopsis

Import Slick, shapeless, and slickless, and you should be able to define Tables on any shapeless HList type:

import slick.jdbc.H2Profile.api._
import shapeless.{ HList, ::, HNil }
import slickless._

class Users(tag: Tag) extends Table[Long :: String :: HNil](tag, "users") {
  def id    = column[Long]( "id", O.PrimaryKey, O.AutoInc )
  def email = column[String]("email")

  def * = id :: email :: HNil
}

lazy 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

import slick.jdbc.H2Profile.api._
import shapeless.{ HList, ::, HNil, Generic }
import slickless._

case class User(id: Long, email: String)

class Users(tag: Tag) extends Table[User](tag, "users") {
  def id    = column[Long]( "id", O.PrimaryKey, O.AutoInc )
  def email = column[String]("email")

  def * = (id :: email :: HNil).mappedWith(Generic[User])
}

lazy 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:

resolvers += "Maven Central" at "https://repo1.maven.org/maven2/"

resolvers += Resolver.sonatypeRepo("releases")

resolvers += Resolver.sonatypeRepo("snapshots")

libraryDependencies ++= Seq(
  "com.typesafe.slick" %% "slick"     % "3.2.1",
  "com.chuusai"        %% "shapeless" % "2.3.3",
  "io.underscore"      %% "slickless" % "0.3.3"
)

Publishing

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

Publish sequence could be:

sbt> set pgpPassphrase := Some(Array('s','e','c','r','3','t'))
sbt> set publishTo := sonatypePublishTo.value
sbt> +publishSigned
sbt> sonatypeRelease

More Repositories

1

shapeless-guide

The Type Astronaut's Guide to Shapeless
TeX
760
star
2

essential-macros

Examples of simple Scala Macros
Scala
146
star
3

shapeless-guide-code

Example code to accompany shapeless-guide.
Scala
133
star
4

essential-scala

Source code for Underscore's Essential Scala
Scala
118
star
5

essential-slick-code

Source Code for the examples in Essential Slick
Scala
83
star
6

compose

Compositional music composition using Scala, SuperCollider, and Web Audio.
Scala
76
star
7

advanced-scala-code

Code examples for Underscore's Advanced Scala course
Scala
54
star
8

essential-interpreters

Patterns for building interpreters in Scala
Scala
50
star
9

scalax15-slick

Slick workshop for Scala Exchange 2015
Scala
45
star
10

essential-slick

Essential Slick Pandoc Source
TeX
38
star
11

underscore-ebook-template

Template for Underscore eBooks
CoffeeScript
29
star
12

scalax15-interpreters

Source code for the Interpreters workshop at Scala Exchange 2015.
Scala
28
star
13

creative-scala-template

Template for those following Creative Scala
Scala
22
star
14

csvside

CSV reader and writer combinators for Scala. Made with Cats.
Scala
21
star
15

eescala

20
star
16

essential-scala-code

Exercises and examples for the Essential Scala training course.
Scala
20
star
17

essential-play-code

Exercises and solutions for Underscore's Essential Play
Scala
17
star
18

essential-scala-doodle-case-study

The Doodle case study supplement to Essential Scala
Scala
17
star
19

philosopher-emoji

Philosopher emoji for all your online metaphysical needs.
14
star
20

free-objects-code

Code samples accompanying the Essential Scalaz supplement dealing with free monoids and free monads.
Scala
12
star
21

books

HTML
10
star
22

scalaxhack-2016

Topic and project suggestions for ScalaxHack 2016.
9
star
23

doodlebot

An Essential Scala case study using Finch and Scala.js
JavaScript
9
star
24

numeric-vc

Derives instances of Numeric for value classes
Scala
7
star
25

eescala-code

Scala
7
star
26

essential-speaking

Slides and notes on speaking at tech conferences.
6
star
27

essential-scala-exercises

Exercises for Essential Scala (replaces essential-scala-code)
Scala
6
star
28

annihilator

Example implementation of Annihilator type class
Scala
5
star
29

interpreters-and-you

Scala
5
star
30

essential-play

Essential Play
Shell
5
star
31

http4s-example

An example using http4s
Scala
4
star
32

essential-interpreters-code

Code samples from Essential Interpreters
Scala
4
star
33

rtb

Example of real-time bidding engine (for training purposes)
Scala
3
star
34

remarkjs-template

Remarkjs Presentation Template, with Underscore Branding
HTML
3
star
35

essential-slick-workshop

Introductory Slick workshop (slides and code samples).
Scala
3
star
36

chatbot

Online chat with http4s and FS2
Scala
2
star
37

jobby

Automating conversion of jobs spreadsheet data into markdown
Scala
1
star
38

underscoreio

Underscore web site and blog.
HTML
1
star
39

linter-explorer

An extremely brief example of WartRemover and Scapegoat. Two scala linters
Scala
1
star
40

scala-start

Quick start for Scala
Shell
1
star
41

wejo-autumn-2019

Wejo Autumn 2019
Scala
1
star
42

csv-workshop

Functional programming workshop exploring the magical domain of CSV parsing.
Scala
1
star
43

formless

A form / questionnaire library, analogous to Google Forms, with http4s and Finch backends
Scala
1
star