underscoreio/essential-slick-code

Name: essential-slick-code

Owner: Underscore

Description: Source Code for the examples in Essential Slick

Created: 2015-02-10 10:23:37.0

Updated: 2018-05-08 22:23:32.0

Pushed: 2018-03-07 07:52:41.0

Homepage: null

Size: 1294

Language: Scala

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Source Code to Accompany Essential Slick.

About the Book

Essential Slick provides a compact, no-nonsense guide to everything you need to know to use Slick in a commercial setting:

To find out more about the book and download the preview chapters, see Underscore.io.

If you're looking for the example code for Slick 2.1, use the 2.1 branch.

About the Code

The code is organised as a folder for each chapter. Each folder contains an SBT project.

Each file is either the examples from the book, or the scaffolding for the exercises.

Chapter 1 (Basics), 2 (Selecting Data), 3 (Creating and Modifying Data), and 4 (Action Combinators)

These projects contain a single source file, main.scala. Use the SBT run or ~run command.

For example:

 chapter-01
sbt.sh

n

o] Running Example
ting database table

rting test data

cting all messages:
age(Dave,Hello, HAL. Do you read me, HAL?,1)
age(HAL,Affirmative, Dave. I read you.,2)
age(Dave,Open the pod bay doors, HAL.,3)
age(HAL,I'm sorry, Dave. I'm afraid I can't do that.,4)

cting only messages from HAL:
age(HAL,Affirmative, Dave. I read you.,2)
age(HAL,I'm sorry, Dave. I'm afraid I can't do that.,4)
cess] Total time: 5 s, completed 06/05/2015 2:22:22 PM
Chapter 5 (Data Modelling)

Chapter 5 contains several applications. Using the SBT run command will prompt you for the file to run.

Alternatively, use runMain or ~runMail and supply the name of the class to run a particular example:

 chapter-05
sbt.sh
unMain StructureExample

The examples are:

  1. StructureExample in structure.scala - an illustration of separating schema and profile.
  2. HListExampleApp in hlists.scala - the HList example from the book.
  3. NestedCaseClassExampleApp in nested_case_class.scala - is the exercise on custom case class mapping.
  4. NullExample in nulls.scala - where the User table has an optional email field.
  5. PKExample in primary_keys.scala - the User.id becomes an Option[Long], and the OccupantTable is added.
  6. ForeignKeyExample in foreign_keys.scala - where MessageTable has a foreign key to the UserTable.
  7. ValueClassesExample in value_classes.scala - introduces types for primary keys, as MessagePK and UserPk.
  8. SumTypesExample in sum_types.scala - the message Flaging example from the book.
  9. CustomBooleanExample in custom_boolean.scala - is the “Custom Boolean” exercise code.
Chapter 6 (Joins and Aggregates)

This project contains a chat_schema.scala file that defines the schema for the chapter. It also defines the method populate which inserts our standard cast, rooms, and messages into the database.

The schema is re-used in the following examples:

  1. JoinsExample in joins.scala - runs through a variety of joins using the sample data in chat_schema.scala.
  2. AggregatesExample in aggregates.scala - various group by and aggregation examples..

joins.scala contains much that is commented out. Remove the comments from around the code you are interest in to run it.

Chapter 7 (Plain SQL)

This project contains the following examples:

  1. SelectExample in select.scala - gives examples with the sql interpolator.
  2. UpdateExample in updates.scala - gives examples with the sqlu interpolator.
  3. TsqlExample in tsql.scala - examples using typed plain queries.

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.