SlideShare uma empresa Scribd logo
1 de 47
Baixar para ler offline
Slick 3.0: Functional
programming with
database side effects
(On short notice…)
Joost de Vries
twitter: @jouke
email: joost@de-vries.name
codestar.nl
github: joost-de-vries
๏ Database actions in Slick 3.0
• Actions in FP: side effects
• A lightweight database action implementation
• Database actions in Slick 3.0 revisited
What is Slick
• Slick is originally a Scala framework that offers
flatmappable relational queries
• Comparable to Microsofts Linq to Sql
• Blocking, thread based
var xs = array.Where(x => x >= 1); array filter { _ >= 1 }
var xs = array.Select(x => x + 1); array map { _ + 1 }
var yx = array.SelectMany(x => new
[] { x, 3 });
array flatMap { Array(_, 3) }
var results =
from x in array
where x >= 1
select x;
for (x <- array if x >= 1)
yield x
LINQ to Sql: SQL as map, flatmap & filter
Slick offers the same paradigm in Scala
JOOQ is an alternative to Slick for the JVM
This talk is not about SQL querying using map and flatmap
What’s new in Slick 3.0
• Non blocking
• (Or is it?)
• Source for reactive streams
DBIO[A] (non streaming)
From: Hello Slick 3.0 example project
A DBIO[R] (simplified)
Type hierarchy
Type hierarchy
Reactive streams
The goal
Reactive streams feature pure functions
to process a stream of events
back pressure
“asynchronous computations that allow separating cpu
intensive code from IO intensive code”
So we need a way to deal with db
side effects in a purely functional
way
FP vs side effects
• Db manipulation is all about side effects
• So how do you deal with side effects in a purely
functional programming model?
• Using flatmappable ‘actions’
• Database actions in Slick 3.0
๏ Actions in FP: side effects
• A lightweight database action implementation
• Database actions in Slick 3.0 revisited
functional stream processing
• Remember we wanted to let db manipulation
take part in the purely functional world of stream
computing
• Hence we need a flatmappable way of dealing
with side effects
Functional stream
processing
• In Scala we’re used to flatmappables for
• Null values
• Exceptions
• Latency
• Collections
• But not for
• Input / Output
• Reading from an environment
• Mutating state
I.e. managing side effects
The power of semi colons!
Great for side effects but not streamable
What’s so great about
supporting flatmap?
• Put building blocks together into bigger building
blocks
• Alternate outcomes are transparantly
propagated through parts to the whole
• … depending on the instance
Chaining outcomes in Swift
• Pure functions don’t have side effects
• I.e. a function evaluation has always the same
value
• (a.k.a. Substitution principle, referential
transparency)
• But a program without f.i. IO is useless
How does Haskell handle
side effects?
• Haskell is a pure lazy language
• There’s no ; operator to evaluate sequentially
• To do IO so called actions are used:
recognisable from the their type
So writing hello
world is in Haskell not
the first thing you do
Spot the side effect
def f : Unit => A
def g: A => Unit
f
A
?
g
A
?
Actions
• A value of type IO t is an action that, when
performed, may do some input/output before
delivering a result of type t.
• Actions are also called computations
• Evaluating an action has no effect; performing
an action has effect.
• Actions can be put together into bigger actions
Source: Simon Peyton Jones - Lazy functional
programming for real
Function declaration: type
Function implementation
Haskell to Scala translation
Actions…
Our building blocks
Chaining actions into a
programme
The type of >>= :
() means: infix operator (ignore the ‘ accent)
flatmap in Scala
meaning is similar to ; in Scala
Chaining actions into a
programme
In the FP world this is called ‘composition’;
‘composing’ 3 flatmappables into a composite
action
type IO a = World -> (a, World)
Ignore the result of a
previous action
Pronounced as andThen
• Database actions in Slick 3.0
• Actions in FP: side effects
๏ A lightweight database action implementation
• Database actions in Slick 3.0 revisited
Resource mgmt with
functions
In the early days of the Spring
framework it provided this as
JdbcTemplate
From: 2012 talk by Paul Chuisano
Let’s flatmap that
[coding]
Putting actions together into
bigger actions
The Reader flatmappable
Anything that takes a context like object to
create results is a candidate for a Reader type
of flat mappable
• Database actions in Slick 3.0
• Actions in FP: side effects
• A lightweight database action implementation
๏ Database actions in Slick 3.0 revisited
DBIO[A] (non streaming)
StreamingDBIO
Type of materialised
result
Read and/or Write side
effect for master/slave
routing
Type of streamed
elements
Client code is run in client execution context
DB code is run against dedicated thread pool
Separated!
Resources
• Stefan Zeigers talk at Scala Days San Fransisco
• slides http://slick.typesafe.com/talks/scaladays2015sf/
Reactive_Slick_for_Database_Programming.pdf
• video https://www.parleys.com/tutorial/reactive-slick-
database-programming
• Paul Chiusano and Rúnar Bjarnason - Functional programming
in Scala
• Activator template hello-slick-3.0
• Let’s take a short break and start hacking!
• The idea is to enhance a scala application that
uses Slick and deploy it to Heroku to
demonstrate.
• If you’ve forwarded your github handle I’ll add
you to the project repo.
• The repo code is for todays use only. Please be
responsible and don’t put it on the public
internet somewhere.

Mais conteúdo relacionado

Mais procurados

Alexander Kolb – Flink. Yet another Streaming Framework?
Alexander Kolb – Flink. Yet another Streaming Framework?Alexander Kolb – Flink. Yet another Streaming Framework?
Alexander Kolb – Flink. Yet another Streaming Framework?
Flink Forward
 

Mais procurados (20)

Flink forward SF 2017: Elizabeth K. Joseph and Ravi Yadav - Flink meet DC/OS ...
Flink forward SF 2017: Elizabeth K. Joseph and Ravi Yadav - Flink meet DC/OS ...Flink forward SF 2017: Elizabeth K. Joseph and Ravi Yadav - Flink meet DC/OS ...
Flink forward SF 2017: Elizabeth K. Joseph and Ravi Yadav - Flink meet DC/OS ...
 
Grokking TechTalk #20: PostgreSQL Internals 101
Grokking TechTalk #20: PostgreSQL Internals 101Grokking TechTalk #20: PostgreSQL Internals 101
Grokking TechTalk #20: PostgreSQL Internals 101
 
Stream processing from single node to a cluster
Stream processing from single node to a clusterStream processing from single node to a cluster
Stream processing from single node to a cluster
 
Spec: a lisp-flavoured type system
Spec: a lisp-flavoured type systemSpec: a lisp-flavoured type system
Spec: a lisp-flavoured type system
 
Correctness and Performance of Apache Spark SQL with Bogdan Ghit and Nicolas ...
Correctness and Performance of Apache Spark SQL with Bogdan Ghit and Nicolas ...Correctness and Performance of Apache Spark SQL with Bogdan Ghit and Nicolas ...
Correctness and Performance of Apache Spark SQL with Bogdan Ghit and Nicolas ...
 
Airflow for Beginners
Airflow for BeginnersAirflow for Beginners
Airflow for Beginners
 
Anatomy of Data Source API : A deep dive into Spark Data source API
Anatomy of Data Source API : A deep dive into Spark Data source APIAnatomy of Data Source API : A deep dive into Spark Data source API
Anatomy of Data Source API : A deep dive into Spark Data source API
 
Apache Airflow (incubating) NL HUG Meetup 2016-07-19
Apache Airflow (incubating) NL HUG Meetup 2016-07-19Apache Airflow (incubating) NL HUG Meetup 2016-07-19
Apache Airflow (incubating) NL HUG Meetup 2016-07-19
 
Scala Days NYC 2016
Scala Days NYC 2016Scala Days NYC 2016
Scala Days NYC 2016
 
Building Data Pipelines in Python
Building Data Pipelines in PythonBuilding Data Pipelines in Python
Building Data Pipelines in Python
 
A Tool For Big Data Analysis using Apache Spark
A Tool For Big Data Analysis using Apache SparkA Tool For Big Data Analysis using Apache Spark
A Tool For Big Data Analysis using Apache Spark
 
ELK at LinkedIn - Kafka, scaling, lessons learned
ELK at LinkedIn - Kafka, scaling, lessons learnedELK at LinkedIn - Kafka, scaling, lessons learned
ELK at LinkedIn - Kafka, scaling, lessons learned
 
ELK Wrestling (Leeds DevOps)
ELK Wrestling (Leeds DevOps)ELK Wrestling (Leeds DevOps)
ELK Wrestling (Leeds DevOps)
 
Spark Summit EU talk by Tim Hunter
Spark Summit EU talk by Tim HunterSpark Summit EU talk by Tim Hunter
Spark Summit EU talk by Tim Hunter
 
Flink Forward SF 2017: Malo Deniélou - No shard left behind: Dynamic work re...
Flink Forward SF 2017: Malo Deniélou -  No shard left behind: Dynamic work re...Flink Forward SF 2017: Malo Deniélou -  No shard left behind: Dynamic work re...
Flink Forward SF 2017: Malo Deniélou - No shard left behind: Dynamic work re...
 
Introduction to ScalaZ
Introduction to ScalaZIntroduction to ScalaZ
Introduction to ScalaZ
 
Alexander Kolb – Flink. Yet another Streaming Framework?
Alexander Kolb – Flink. Yet another Streaming Framework?Alexander Kolb – Flink. Yet another Streaming Framework?
Alexander Kolb – Flink. Yet another Streaming Framework?
 
Machine learning pipeline with spark ml
Machine learning pipeline with spark mlMachine learning pipeline with spark ml
Machine learning pipeline with spark ml
 
Journey into Reactive Streams and Akka Streams
Journey into Reactive Streams and Akka StreamsJourney into Reactive Streams and Akka Streams
Journey into Reactive Streams and Akka Streams
 
Vectorized Query Execution in Apache Spark at Facebook
Vectorized Query Execution in Apache Spark at FacebookVectorized Query Execution in Apache Spark at Facebook
Vectorized Query Execution in Apache Spark at Facebook
 

Destaque

1.7 functional programming
1.7 functional programming1.7 functional programming
1.7 functional programming
futurespective
 

Destaque (20)

Patterns for slick database applications
Patterns for slick database applicationsPatterns for slick database applications
Patterns for slick database applications
 
Slick – the modern way to access your Data
Slick – the modern way to access your DataSlick – the modern way to access your Data
Slick – the modern way to access your Data
 
Slick - The Structured Way
Slick - The Structured WaySlick - The Structured Way
Slick - The Structured Way
 
Union Types and Literal Singleton Types in Scala (and Typescript)
Union Types and Literal Singleton Types in Scala (and Typescript)Union Types and Literal Singleton Types in Scala (and Typescript)
Union Types and Literal Singleton Types in Scala (and Typescript)
 
Reactive Database Access With Slick 3
Reactive Database Access With Slick 3Reactive Database Access With Slick 3
Reactive Database Access With Slick 3
 
Typescript: enjoying large scale browser development
Typescript: enjoying large scale browser developmentTypescript: enjoying large scale browser development
Typescript: enjoying large scale browser development
 
実戦Scala
実戦Scala実戦Scala
実戦Scala
 
1.7 functional programming
1.7 functional programming1.7 functional programming
1.7 functional programming
 
Frp
FrpFrp
Frp
 
The essence of Reactive Programming
The essence of Reactive ProgrammingThe essence of Reactive Programming
The essence of Reactive Programming
 
Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access
 
Elm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and WebElm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and Web
 
The taste of F#
The taste of F#The taste of F#
The taste of F#
 
Designing with Capabilities
Designing with CapabilitiesDesigning with Capabilities
Designing with Capabilities
 
Real-World Functional Programming @ Incubaid
Real-World Functional Programming @ IncubaidReal-World Functional Programming @ Incubaid
Real-World Functional Programming @ Incubaid
 
Doge-driven design
Doge-driven designDoge-driven design
Doge-driven design
 
The Theory of Chains
The Theory of ChainsThe Theory of Chains
The Theory of Chains
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
Dr Frankenfunctor and the Monadster
Dr Frankenfunctor and the MonadsterDr Frankenfunctor and the Monadster
Dr Frankenfunctor and the Monadster
 
Swift vs. Language X
Swift vs. Language XSwift vs. Language X
Swift vs. Language X
 

Semelhante a Slick 3.0 functional programming and db side effects

AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)
Paul Chao
 

Semelhante a Slick 3.0 functional programming and db side effects (20)

Flink internals web
Flink internals web Flink internals web
Flink internals web
 
あなたのScalaを爆速にする7つの方法
あなたのScalaを爆速にする7つの方法あなたのScalaを爆速にする7つの方法
あなたのScalaを爆速にする7つの方法
 
cb streams - gavin pickin
cb streams - gavin pickincb streams - gavin pickin
cb streams - gavin pickin
 
Advanced Data Science on Spark-(Reza Zadeh, Stanford)
Advanced Data Science on Spark-(Reza Zadeh, Stanford)Advanced Data Science on Spark-(Reza Zadeh, Stanford)
Advanced Data Science on Spark-(Reza Zadeh, Stanford)
 
Apache Flink internals
Apache Flink internalsApache Flink internals
Apache Flink internals
 
Reactive programming with rx java
Reactive programming with rx javaReactive programming with rx java
Reactive programming with rx java
 
From Pipelines to Refineries: Scaling Big Data Applications
From Pipelines to Refineries: Scaling Big Data ApplicationsFrom Pipelines to Refineries: Scaling Big Data Applications
From Pipelines to Refineries: Scaling Big Data Applications
 
Java 8
Java 8Java 8
Java 8
 
Data Summer Conf 2018, “Hands-on with Apache Spark for Beginners (ENG)” — Akm...
Data Summer Conf 2018, “Hands-on with Apache Spark for Beginners (ENG)” — Akm...Data Summer Conf 2018, “Hands-on with Apache Spark for Beginners (ENG)” — Akm...
Data Summer Conf 2018, “Hands-on with Apache Spark for Beginners (ENG)” — Akm...
 
Java 8
Java 8Java 8
Java 8
 
SparkSQL: A Compiler from Queries to RDDs
SparkSQL: A Compiler from Queries to RDDsSparkSQL: A Compiler from Queries to RDDs
SparkSQL: A Compiler from Queries to RDDs
 
Computing recommendations at extreme scale with Apache Flink @Buzzwords 2015
Computing recommendations at extreme scale with Apache Flink @Buzzwords 2015Computing recommendations at extreme scale with Apache Flink @Buzzwords 2015
Computing recommendations at extreme scale with Apache Flink @Buzzwords 2015
 
AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)
 
CBStreams - Java Streams for ColdFusion (CFML)
CBStreams - Java Streams for ColdFusion (CFML)CBStreams - Java Streams for ColdFusion (CFML)
CBStreams - Java Streams for ColdFusion (CFML)
 
ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...
ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...
ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...
 
Large-scale Recommendation Systems on Just a PC
Large-scale Recommendation Systems on Just a PCLarge-scale Recommendation Systems on Just a PC
Large-scale Recommendation Systems on Just a PC
 
Exploring Clojurescript
Exploring ClojurescriptExploring Clojurescript
Exploring Clojurescript
 
Data herding
Data herdingData herding
Data herding
 
Data herding
Data herdingData herding
Data herding
 
RxJS and Reactive Programming - Modern Web UI - May 2015
RxJS and Reactive Programming - Modern Web UI - May 2015RxJS and Reactive Programming - Modern Web UI - May 2015
RxJS and Reactive Programming - Modern Web UI - May 2015
 

Último

Último (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 

Slick 3.0 functional programming and db side effects

  • 1. Slick 3.0: Functional programming with database side effects (On short notice…) Joost de Vries twitter: @jouke email: joost@de-vries.name codestar.nl github: joost-de-vries
  • 2. ๏ Database actions in Slick 3.0 • Actions in FP: side effects • A lightweight database action implementation • Database actions in Slick 3.0 revisited
  • 3. What is Slick • Slick is originally a Scala framework that offers flatmappable relational queries • Comparable to Microsofts Linq to Sql • Blocking, thread based
  • 4. var xs = array.Where(x => x >= 1); array filter { _ >= 1 } var xs = array.Select(x => x + 1); array map { _ + 1 } var yx = array.SelectMany(x => new [] { x, 3 }); array flatMap { Array(_, 3) } var results = from x in array where x >= 1 select x; for (x <- array if x >= 1) yield x LINQ to Sql: SQL as map, flatmap & filter Slick offers the same paradigm in Scala JOOQ is an alternative to Slick for the JVM This talk is not about SQL querying using map and flatmap
  • 5. What’s new in Slick 3.0 • Non blocking • (Or is it?) • Source for reactive streams
  • 6. DBIO[A] (non streaming) From: Hello Slick 3.0 example project
  • 11.
  • 12. Reactive streams feature pure functions to process a stream of events back pressure “asynchronous computations that allow separating cpu intensive code from IO intensive code” So we need a way to deal with db side effects in a purely functional way
  • 13. FP vs side effects • Db manipulation is all about side effects • So how do you deal with side effects in a purely functional programming model? • Using flatmappable ‘actions’
  • 14. • Database actions in Slick 3.0 ๏ Actions in FP: side effects • A lightweight database action implementation • Database actions in Slick 3.0 revisited
  • 15. functional stream processing • Remember we wanted to let db manipulation take part in the purely functional world of stream computing • Hence we need a flatmappable way of dealing with side effects
  • 16. Functional stream processing • In Scala we’re used to flatmappables for • Null values • Exceptions • Latency • Collections • But not for • Input / Output • Reading from an environment • Mutating state I.e. managing side effects
  • 17. The power of semi colons! Great for side effects but not streamable
  • 18. What’s so great about supporting flatmap? • Put building blocks together into bigger building blocks • Alternate outcomes are transparantly propagated through parts to the whole • … depending on the instance
  • 20. • Pure functions don’t have side effects • I.e. a function evaluation has always the same value • (a.k.a. Substitution principle, referential transparency) • But a program without f.i. IO is useless
  • 21. How does Haskell handle side effects? • Haskell is a pure lazy language • There’s no ; operator to evaluate sequentially • To do IO so called actions are used: recognisable from the their type
  • 22. So writing hello world is in Haskell not the first thing you do
  • 23. Spot the side effect def f : Unit => A def g: A => Unit f A ? g A ?
  • 24. Actions • A value of type IO t is an action that, when performed, may do some input/output before delivering a result of type t. • Actions are also called computations • Evaluating an action has no effect; performing an action has effect. • Actions can be put together into bigger actions Source: Simon Peyton Jones - Lazy functional programming for real
  • 26. Haskell to Scala translation
  • 28. Chaining actions into a programme The type of >>= : () means: infix operator (ignore the ‘ accent) flatmap in Scala meaning is similar to ; in Scala
  • 29. Chaining actions into a programme In the FP world this is called ‘composition’; ‘composing’ 3 flatmappables into a composite action type IO a = World -> (a, World)
  • 30. Ignore the result of a previous action Pronounced as andThen
  • 31.
  • 32. • Database actions in Slick 3.0 • Actions in FP: side effects ๏ A lightweight database action implementation • Database actions in Slick 3.0 revisited
  • 33. Resource mgmt with functions In the early days of the Spring framework it provided this as JdbcTemplate
  • 34. From: 2012 talk by Paul Chuisano
  • 37. Putting actions together into bigger actions
  • 38.
  • 39. The Reader flatmappable Anything that takes a context like object to create results is a candidate for a Reader type of flat mappable
  • 40.
  • 41. • Database actions in Slick 3.0 • Actions in FP: side effects • A lightweight database action implementation ๏ Database actions in Slick 3.0 revisited
  • 44. Type of materialised result Read and/or Write side effect for master/slave routing Type of streamed elements
  • 45. Client code is run in client execution context DB code is run against dedicated thread pool Separated!
  • 46. Resources • Stefan Zeigers talk at Scala Days San Fransisco • slides http://slick.typesafe.com/talks/scaladays2015sf/ Reactive_Slick_for_Database_Programming.pdf • video https://www.parleys.com/tutorial/reactive-slick- database-programming • Paul Chiusano and Rúnar Bjarnason - Functional programming in Scala • Activator template hello-slick-3.0
  • 47. • Let’s take a short break and start hacking! • The idea is to enhance a scala application that uses Slick and deploy it to Heroku to demonstrate. • If you’ve forwarded your github handle I’ll add you to the project repo. • The repo code is for todays use only. Please be responsible and don’t put it on the public internet somewhere.