SlideShare a Scribd company logo
Scala Frameworks for
Web Application 2016
BizReach, Inc
Scala Kansai Summit 2016
#scala_ks
Standard Frameworks for
Web Application in Scala
Why we've used Play2 and Slick?
● Many users and developers
● Future prospects
● Supported by Typesafe
Dissatisfaction to Play2
● Unnecessary features
○ View support
○ Assets management
○ Dependency injection
● Poor integration
○ Zipkin https://github.com/levkhomich/akka-tracing
○ Swagger https://github.com/swagger-api/swagger-play
Dissatisfaction to Slick
● Lerning curve
○ DBIO is hard for non-functional programmers
○ Asynchronous is not always needed
● Performance
○ Join makes subquery frequently
○ It causes performance issue with MySQL
Alternatives?
Alternatives
● Web Framework
○ Finagle
○ Akka HTTP
○ Skinny Micro
● Database Framework
○ Quill
○ doobie
○ Scalike JDBC
Finagle
● Pluggable asynchronous RPC framework
based on Netty
● Client API with Circuit Breaker
● Zipkin integration
● Finatra or Finch for HTTP server
● Swagger 1.x support for Finatra (3rd party)
○ https://github.com/xiaodongw/swagger-finatra
Finagle
val router = RoutingService.byPathObject[Request] {
case Root => new Service[Request,Response] {
def apply(req: Request): Future[Response] = {
Future(Response(
req.version, Status.Ok, Reader.fromBuf(Utf8("API is Ready."))
))
}
}
case Root / "hello"/ name => new Service[Request, Response] {
def apply(req: Request): Future[Response] = {
Future(Response(
req.version, Status.Ok, Reader.fromBuf(Utf8(s"Hello ${name}!"))
))
}
}
}
Maybe Finatra or Finch is better choise for REST API server
Akka HTTP
● Actor-based toolkit for interacting web
services and clients
● spray like routing DSL
● Reactive Streams
● Swagger 2.0 support (3rd party)
○ https://github.com/swagger-akka-http/swagger-akka-http
● Play 3.0 will move to Akka HTTP?
○ Experimental in Play 2.5
○ https://www.playframework.com/documentation/2.5.x/AkkaHttpServer
Akka HTTP
val route = get {
pathEndOrSingleSlash {
handleWith((request: HttpRequest) => "API is ready.")
}
} ~ path("hello" / ".+".r) {
get { case (name) =>
complete {
HelloResult(message = s"Hello, ${request.name}!")
}
}
}
Skiny Micro
● Servlet-based micro framework
● Scalatra comparible routing DSL
● Future-wired async operation
● No Swagger and Zipkin support
Skiny Micro
object Hello extends WebApp with JSONSupport {
get("/") {
"API is ready"
}
post("/hello/:name") {
contentType = "application/json"
toJSONString(
HelloResult(message = s"Hello, ${params("name")}!")
)
}
}
Results
Version View DI Routing Circuit
Breaker
Reactive
Streams
Zipkin Swagger
Play2 2.5.8 Supported Guice Method +
DSL
- ※2 3rd party
library
3rd party
library
Finagle 6.38.0 - ※1 DSL Supported - Supported 3rd party
library
Akka HTTP 2.4.10-exp
erimantal
- - DSL - Supported 3rd party
library
3rd party
library
Skinny
Micro
1.1.0 - - DSL - - - -
※1 Finatra is equipped Guice based dependency injection as same as Play2
※2 There is an experimental module in Play 2.5
https://www.playframework.com/documentation/2.5.x/ReactiveStreamsIntegration
Quill
● Macro-based compile time SQL generation
○ No overhead in runtime
○ Compile time SQL validation is available
○ Some constraints in query building
● Development is very active
○ Many sub modules are available such as async,
cassandra support and finagle integration
● Move to scala.meta in the future?
Quill
val account: Option[Account] = ctx.run(
quote { (mailAddress: String, includeRemoved: Boolean) =>
query[Account].filter { t =>
if(includeRemoved){
t.mailAddress == mailAddress
} else {
t.mailAddress == mailAddress && t.removed == false
}
}
}
)(mailAddress, includeRemoved).headOption
Quill
val account: Option[Account] = ctx.run(
quote { (mailAddress: String, includeRemoved: Boolean) =>
query[Account].filter { t =>
if(includeRemoved){
t.mailAddress == mailAddress
} else {
t.mailAddress == mailAddress && t.removed == false
}
}
}
)(mailAddress, includeRemoved).headOption
Macro (expanded in compile time)
Quill
val account: Option[Account] = ctx.run(
quote { (mailAddress: String, includeRemoved: Boolean) =>
query[Account].filter { t =>
if(includeRemoved){
t.mailAddress == mailAddress
} else {
t.mailAddress == mailAddress && t.removed == false
}
}
}
)(mailAddress, includeRemoved).headOption
Take variables as argument
Quill
val account: Option[Account] = ctx.run(
quote { (mailAddress: String, includeRemoved: Boolean) =>
query[Account].filter { t =>
if(includeRemoved){
t.mailAddress == mailAddress
} else {
t.mailAddress == mailAddress && t.removed == false
}
}
}
)(mailAddress, includeRemoved).headOption
Assemble condition dynamically?
Quill
SELECT ...
FROM account t
WHERE CASE WHEN ? THEN
t.mail_address = ?
ELSE
(t.mail_address = ?) AND (t.removed = false)
END
No, translated to CASE expression
doobie
● A pure-functional JDBC layer for Scala
○ It is not an ORM
● Designed for people who are interested in:
○ typed
○ pure functional programming
● IO and monadic effects
doobie
sql"select * from account where uid = $id"
.query[Account]
.option
.transact(xa)
.unsafePerformAsync {
case -/(throwable) => ...
case /-(account) => ...
}
doobie
sql"select * from account where uid = $id"
.query[Account] // Query0[Account]
.option // ConnectionIO[Option[Account]]
.transact(xa) // Task[Option[Account]]
.unsafePerformAsync {
case -/(throwable) => … // Throwable
case /-(account) => … // Option[Account]
}
Query0[Account] is all columns query that maps one returned row.
Ultimately producing a value of type Option[Account].
doobie
sql"select * from account where uid = $id"
.query[Account] // Query0[Account]
.option // ConnectionIO[Option[Account]]
.transact(xa) // Task[Option[Account]]
.unsafePerformAsync {
case -/(throwable) => … // Throwable
case /-(account) => … // Option[Account]
}
Task is scalaz.concurrent.Task!!
doobie
● Typechecking (experimental)
○ Validate queries against the database schema in
runtime
val q: Query0[Account] =
sql"select * from account where uid = $id".query[Account]
q.check.unsafePerformSync
✓ SQL Compiles and Typechecks
✕ C01 UID INTEGER (INTEGER) NOT NULL → String
- INTEGER (INTEGER) is ostensibly coercible to String according to the JDBC
specification but is not a recommended target type. Fix this by changing the
schema type to CHAR or VARCHAR; or the Scala type to Int or JdbcType.
✓ C02 LOGIN_ID VARCHAR (VARCHAR) NOT NULL → String
ScalikeJDBC
● A tidy SQL-based DB access library for
Scala
○ Naturally wrap JDBC APIs
○ easy-to-use
● QueryDSL is available (since 1.6)
ScalikeJDBC
val id = 1
// QueryDSL
val a = Account.syntax("a")
val account: Option[Account] = DB readOnly { implicit s =>
withSQL {
select.from(Account as a).where.eq(a.uid, id)
}.map(Account(a)).single.apply()
}
ScalikeJDBC
val id = 1
case class Email(name: String, address: String)
// basic SQL
val email: Option[Email] = DB readOnly { implicit s =>
sql"select * from account where uid = ${id}"
.map(rs =>
Email(rs.get("name"), rs.get("mail_address"))
).single.apply()
}
Results
Version Monad Async Mapping Typesafe
DSL
Genarated
SQL
Timing PlainSQL
Slick 3.1.1 Required Always Required
※2
Supported Non-intuitiv
e
Runtime Supported
Quill 0.10.0 Option ※1 - Supported
※3
Intuitive Compile
time
-
doobie 0.3.0 Required Option - - - - Supported
※4
Scalike
JDBC
2.4.2 - ※1 Required
※2
Supported Intuitive Runtime Supported
※1 Provides non-blocking API using postgresql-async or mysql-async
※2 A tool to generate table mappings from actual database schema is available
※3 Compile time SQL validation is available
※4 Runtime typechecking is available as experimental feature
Conclusion
Conclusion
● Web Fraemwork
○ All alternatives look good, but Play2 is not so bad
as well
○ For servlet container, Skinny Micro would be good
● Database Framework
○ There is no de-facto standard library currently
○ ScalikeJDBC looks good for us and almost users

More Related Content

PDF
Develop realtime web with Scala and Xitrum
PDF
Type-safe front-end development with Scala
PDF
Xitrum @ Scala Matsuri Tokyo 2014
PDF
How to write a web framework
PPTX
I18nize Scala programs à la gettext
PPTX
Search and analyze your data with elasticsearch
PDF
Lightbend Lagom: Microservices Just Right
PDF
Run-time of Node.js : V8 JavaScript Engine
Develop realtime web with Scala and Xitrum
Type-safe front-end development with Scala
Xitrum @ Scala Matsuri Tokyo 2014
How to write a web framework
I18nize Scala programs à la gettext
Search and analyze your data with elasticsearch
Lightbend Lagom: Microservices Just Right
Run-time of Node.js : V8 JavaScript Engine

What's hot (20)

PDF
Microservices in Scala: Play Framework
PPTX
Scala adoption by enterprises
PDF
Web a Quebec - JS Debugging
PPTX
No Container: a Modern Java Stack with Bootique
PPT
Sbt, idea and eclipse
PPTX
Scala in the Wild
PDF
Scala profiling
PPTX
Composable Futures with Akka 2.0
PDF
Grand Central Dispatch and multi-threading [iCONdev 2014]
PDF
JCR - Java Content Repositories
PDF
End to-end W3C - JS.everywhere(2012) Europe
PPTX
Node.js, for architects - OpenSlava 2013
PPTX
Oak, the architecture of Apache Jackrabbit 3
PDF
Logging in Scala
PPTX
Monitoring Open Source Databases with Icinga
PDF
angular-wakanda ngParis meetup 15 at 42
PPTX
Spider进化论
PDF
Apache Jackrabbit
PPTX
The ELK Stack - Get to Know Logs
PDF
Scala.js & friends: SCALA ALL THE THINGS
Microservices in Scala: Play Framework
Scala adoption by enterprises
Web a Quebec - JS Debugging
No Container: a Modern Java Stack with Bootique
Sbt, idea and eclipse
Scala in the Wild
Scala profiling
Composable Futures with Akka 2.0
Grand Central Dispatch and multi-threading [iCONdev 2014]
JCR - Java Content Repositories
End to-end W3C - JS.everywhere(2012) Europe
Node.js, for architects - OpenSlava 2013
Oak, the architecture of Apache Jackrabbit 3
Logging in Scala
Monitoring Open Source Databases with Icinga
angular-wakanda ngParis meetup 15 at 42
Spider进化论
Apache Jackrabbit
The ELK Stack - Get to Know Logs
Scala.js & friends: SCALA ALL THE THINGS
Ad

Viewers also liked (20)

PDF
Macro in Scala
PDF
Tracing Microservices with Zipkin
PDF
Http4s, Doobie and Circe: The Functional Web Stack
PDF
Scala Warrior and type-safe front-end development with Scala.js
PDF
Play Framework: async I/O with Java and Scala
PDF
Skinny Framework で始めた Scala
PDF
Xitrum HOWTOs
PPTX
Finagle Your Own Codec - Scala By The Bay 2016
PDF
Hawkular Alerting
PDF
Aplicações Web de Alta Performance
PDF
Como se tornar um viciado em performance em 5 passos
PDF
Git in 5 minuti
PDF
Facilitando o desenvolvimento orientado a testes em aplicações PHP
PDF
Unbound/NSD最新情報(OSC 2014 Tokyo/Spring)
PDF
実戦Scala
PDF
Desbancando mitos sobre PHP e o futuro da linguagem
PDF
【D3 公開用】ドメイン駆動設計とscala 〜既存プロジェクトへの適用〜
PDF
Play Framework on Google App Engine - Productivity Stack
PDF
PDF
"Go" Contra ou a favor? Já vale a pena investir nessa linguagem?
Macro in Scala
Tracing Microservices with Zipkin
Http4s, Doobie and Circe: The Functional Web Stack
Scala Warrior and type-safe front-end development with Scala.js
Play Framework: async I/O with Java and Scala
Skinny Framework で始めた Scala
Xitrum HOWTOs
Finagle Your Own Codec - Scala By The Bay 2016
Hawkular Alerting
Aplicações Web de Alta Performance
Como se tornar um viciado em performance em 5 passos
Git in 5 minuti
Facilitando o desenvolvimento orientado a testes em aplicações PHP
Unbound/NSD最新情報(OSC 2014 Tokyo/Spring)
実戦Scala
Desbancando mitos sobre PHP e o futuro da linguagem
【D3 公開用】ドメイン駆動設計とscala 〜既存プロジェクトへの適用〜
Play Framework on Google App Engine - Productivity Stack
"Go" Contra ou a favor? Já vale a pena investir nessa linguagem?
Ad

Similar to Scala Frameworks for Web Application 2016 (20)

PDF
Scala in a wild enterprise
PDF
Core2 Document - Java SCORE Overview.pptx.pdf
PDF
GraphQL the holy contract between client and server
PDF
SE2016 BigData Vitalii Bondarenko "HD insight spark. Advanced in-memory Big D...
PDF
Vitalii Bondarenko HDinsight: spark. advanced in memory big-data analytics wi...
PDF
SproutCore and the Future of Web Apps
PPTX
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
ODP
Slickdemo
PPTX
NoSQL Endgame DevoxxUA Conference 2020
PDF
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
PDF
Scala Frustrations
ODP
[4 dev] lagom
PDF
Reactive Web Applications with Scala & Liftweb - CodeWeek 2015
PDF
Codeweek 2015 - Reactive Web Applications with Scala and LIFT framework
PDF
PDF
Rafael Bagmanov «Scala in a wild enterprise»
PPTX
Domain-Driven Design with SeedStack
PDF
Building Kafka Connectors with Kotlin: A Step-by-Step Guide to Creation and D...
PDF
Naver_alternative_to_jpa
PDF
Kabukiza.tech 1 LT - ScalikeJDBC-Async & Skinny Framework #kbkz_tech
Scala in a wild enterprise
Core2 Document - Java SCORE Overview.pptx.pdf
GraphQL the holy contract between client and server
SE2016 BigData Vitalii Bondarenko "HD insight spark. Advanced in-memory Big D...
Vitalii Bondarenko HDinsight: spark. advanced in memory big-data analytics wi...
SproutCore and the Future of Web Apps
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Slickdemo
NoSQL Endgame DevoxxUA Conference 2020
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Scala Frustrations
[4 dev] lagom
Reactive Web Applications with Scala & Liftweb - CodeWeek 2015
Codeweek 2015 - Reactive Web Applications with Scala and LIFT framework
Rafael Bagmanov «Scala in a wild enterprise»
Domain-Driven Design with SeedStack
Building Kafka Connectors with Kotlin: A Step-by-Step Guide to Creation and D...
Naver_alternative_to_jpa
Kabukiza.tech 1 LT - ScalikeJDBC-Async & Skinny Framework #kbkz_tech

More from takezoe (20)

PDF
Journey of Migrating Millions of Queries on The Cloud
PDF
GitBucket: Open source self-hosting Git server built by Scala
PDF
Testing Distributed Query Engine as a Service
PDF
Revisit Dependency Injection in scala
PDF
How to keep maintainability of long life Scala applications
PDF
頑張りすぎないScala
PDF
GitBucket: Git Centric Software Development Platform by Scala
PDF
Non-Functional Programming in Scala
PDF
Scala警察のすすめ
PDF
Scala製機械学習サーバ「Apache PredictionIO」
PDF
The best of AltJava is Xtend
PDF
Java9 and Project Jigsaw
PDF
Reactive database access with Slick3
PDF
markedj: The best of markdown processor on JVM
PDF
ネタじゃないScala.js
PDF
Excel方眼紙を支えるJava技術 2015
PDF
ビズリーチの新サービスをScalaで作ってみた 〜マイクロサービスの裏側 #jissenscala
PDF
GitBucket: The perfect Github clone by Scala
PDF
Play2実践tips集
PDF
Scala界隈の近況
Journey of Migrating Millions of Queries on The Cloud
GitBucket: Open source self-hosting Git server built by Scala
Testing Distributed Query Engine as a Service
Revisit Dependency Injection in scala
How to keep maintainability of long life Scala applications
頑張りすぎないScala
GitBucket: Git Centric Software Development Platform by Scala
Non-Functional Programming in Scala
Scala警察のすすめ
Scala製機械学習サーバ「Apache PredictionIO」
The best of AltJava is Xtend
Java9 and Project Jigsaw
Reactive database access with Slick3
markedj: The best of markdown processor on JVM
ネタじゃないScala.js
Excel方眼紙を支えるJava技術 2015
ビズリーチの新サービスをScalaで作ってみた 〜マイクロサービスの裏側 #jissenscala
GitBucket: The perfect Github clone by Scala
Play2実践tips集
Scala界隈の近況

Recently uploaded (20)

PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Introduction to Artificial Intelligence
PDF
Digital Strategies for Manufacturing Companies
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
L1 - Introduction to python Backend.pptx
PDF
System and Network Administration Chapter 2
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
How to Migrate SBCGlobal Email to Yahoo Easily
Introduction to Artificial Intelligence
Digital Strategies for Manufacturing Companies
VVF-Customer-Presentation2025-Ver1.9.pptx
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Design an Analysis of Algorithms II-SECS-1021-03
Navsoft: AI-Powered Business Solutions & Custom Software Development
Design an Analysis of Algorithms I-SECS-1021-03
How Creative Agencies Leverage Project Management Software.pdf
Reimagine Home Health with the Power of Agentic AI​
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
CHAPTER 2 - PM Management and IT Context
Upgrade and Innovation Strategies for SAP ERP Customers
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
wealthsignaloriginal-com-DS-text-... (1).pdf
L1 - Introduction to python Backend.pptx
System and Network Administration Chapter 2
Operating system designcfffgfgggggggvggggggggg
How to Choose the Right IT Partner for Your Business in Malaysia

Scala Frameworks for Web Application 2016

  • 1. Scala Frameworks for Web Application 2016 BizReach, Inc Scala Kansai Summit 2016 #scala_ks
  • 2. Standard Frameworks for Web Application in Scala
  • 3. Why we've used Play2 and Slick? ● Many users and developers ● Future prospects ● Supported by Typesafe
  • 4. Dissatisfaction to Play2 ● Unnecessary features ○ View support ○ Assets management ○ Dependency injection ● Poor integration ○ Zipkin https://github.com/levkhomich/akka-tracing ○ Swagger https://github.com/swagger-api/swagger-play
  • 5. Dissatisfaction to Slick ● Lerning curve ○ DBIO is hard for non-functional programmers ○ Asynchronous is not always needed ● Performance ○ Join makes subquery frequently ○ It causes performance issue with MySQL
  • 7. Alternatives ● Web Framework ○ Finagle ○ Akka HTTP ○ Skinny Micro ● Database Framework ○ Quill ○ doobie ○ Scalike JDBC
  • 8. Finagle ● Pluggable asynchronous RPC framework based on Netty ● Client API with Circuit Breaker ● Zipkin integration ● Finatra or Finch for HTTP server ● Swagger 1.x support for Finatra (3rd party) ○ https://github.com/xiaodongw/swagger-finatra
  • 9. Finagle val router = RoutingService.byPathObject[Request] { case Root => new Service[Request,Response] { def apply(req: Request): Future[Response] = { Future(Response( req.version, Status.Ok, Reader.fromBuf(Utf8("API is Ready.")) )) } } case Root / "hello"/ name => new Service[Request, Response] { def apply(req: Request): Future[Response] = { Future(Response( req.version, Status.Ok, Reader.fromBuf(Utf8(s"Hello ${name}!")) )) } } } Maybe Finatra or Finch is better choise for REST API server
  • 10. Akka HTTP ● Actor-based toolkit for interacting web services and clients ● spray like routing DSL ● Reactive Streams ● Swagger 2.0 support (3rd party) ○ https://github.com/swagger-akka-http/swagger-akka-http ● Play 3.0 will move to Akka HTTP? ○ Experimental in Play 2.5 ○ https://www.playframework.com/documentation/2.5.x/AkkaHttpServer
  • 11. Akka HTTP val route = get { pathEndOrSingleSlash { handleWith((request: HttpRequest) => "API is ready.") } } ~ path("hello" / ".+".r) { get { case (name) => complete { HelloResult(message = s"Hello, ${request.name}!") } } }
  • 12. Skiny Micro ● Servlet-based micro framework ● Scalatra comparible routing DSL ● Future-wired async operation ● No Swagger and Zipkin support
  • 13. Skiny Micro object Hello extends WebApp with JSONSupport { get("/") { "API is ready" } post("/hello/:name") { contentType = "application/json" toJSONString( HelloResult(message = s"Hello, ${params("name")}!") ) } }
  • 14. Results Version View DI Routing Circuit Breaker Reactive Streams Zipkin Swagger Play2 2.5.8 Supported Guice Method + DSL - ※2 3rd party library 3rd party library Finagle 6.38.0 - ※1 DSL Supported - Supported 3rd party library Akka HTTP 2.4.10-exp erimantal - - DSL - Supported 3rd party library 3rd party library Skinny Micro 1.1.0 - - DSL - - - - ※1 Finatra is equipped Guice based dependency injection as same as Play2 ※2 There is an experimental module in Play 2.5 https://www.playframework.com/documentation/2.5.x/ReactiveStreamsIntegration
  • 15. Quill ● Macro-based compile time SQL generation ○ No overhead in runtime ○ Compile time SQL validation is available ○ Some constraints in query building ● Development is very active ○ Many sub modules are available such as async, cassandra support and finagle integration ● Move to scala.meta in the future?
  • 16. Quill val account: Option[Account] = ctx.run( quote { (mailAddress: String, includeRemoved: Boolean) => query[Account].filter { t => if(includeRemoved){ t.mailAddress == mailAddress } else { t.mailAddress == mailAddress && t.removed == false } } } )(mailAddress, includeRemoved).headOption
  • 17. Quill val account: Option[Account] = ctx.run( quote { (mailAddress: String, includeRemoved: Boolean) => query[Account].filter { t => if(includeRemoved){ t.mailAddress == mailAddress } else { t.mailAddress == mailAddress && t.removed == false } } } )(mailAddress, includeRemoved).headOption Macro (expanded in compile time)
  • 18. Quill val account: Option[Account] = ctx.run( quote { (mailAddress: String, includeRemoved: Boolean) => query[Account].filter { t => if(includeRemoved){ t.mailAddress == mailAddress } else { t.mailAddress == mailAddress && t.removed == false } } } )(mailAddress, includeRemoved).headOption Take variables as argument
  • 19. Quill val account: Option[Account] = ctx.run( quote { (mailAddress: String, includeRemoved: Boolean) => query[Account].filter { t => if(includeRemoved){ t.mailAddress == mailAddress } else { t.mailAddress == mailAddress && t.removed == false } } } )(mailAddress, includeRemoved).headOption Assemble condition dynamically?
  • 20. Quill SELECT ... FROM account t WHERE CASE WHEN ? THEN t.mail_address = ? ELSE (t.mail_address = ?) AND (t.removed = false) END No, translated to CASE expression
  • 21. doobie ● A pure-functional JDBC layer for Scala ○ It is not an ORM ● Designed for people who are interested in: ○ typed ○ pure functional programming ● IO and monadic effects
  • 22. doobie sql"select * from account where uid = $id" .query[Account] .option .transact(xa) .unsafePerformAsync { case -/(throwable) => ... case /-(account) => ... }
  • 23. doobie sql"select * from account where uid = $id" .query[Account] // Query0[Account] .option // ConnectionIO[Option[Account]] .transact(xa) // Task[Option[Account]] .unsafePerformAsync { case -/(throwable) => … // Throwable case /-(account) => … // Option[Account] } Query0[Account] is all columns query that maps one returned row. Ultimately producing a value of type Option[Account].
  • 24. doobie sql"select * from account where uid = $id" .query[Account] // Query0[Account] .option // ConnectionIO[Option[Account]] .transact(xa) // Task[Option[Account]] .unsafePerformAsync { case -/(throwable) => … // Throwable case /-(account) => … // Option[Account] } Task is scalaz.concurrent.Task!!
  • 25. doobie ● Typechecking (experimental) ○ Validate queries against the database schema in runtime val q: Query0[Account] = sql"select * from account where uid = $id".query[Account] q.check.unsafePerformSync ✓ SQL Compiles and Typechecks ✕ C01 UID INTEGER (INTEGER) NOT NULL → String - INTEGER (INTEGER) is ostensibly coercible to String according to the JDBC specification but is not a recommended target type. Fix this by changing the schema type to CHAR or VARCHAR; or the Scala type to Int or JdbcType. ✓ C02 LOGIN_ID VARCHAR (VARCHAR) NOT NULL → String
  • 26. ScalikeJDBC ● A tidy SQL-based DB access library for Scala ○ Naturally wrap JDBC APIs ○ easy-to-use ● QueryDSL is available (since 1.6)
  • 27. ScalikeJDBC val id = 1 // QueryDSL val a = Account.syntax("a") val account: Option[Account] = DB readOnly { implicit s => withSQL { select.from(Account as a).where.eq(a.uid, id) }.map(Account(a)).single.apply() }
  • 28. ScalikeJDBC val id = 1 case class Email(name: String, address: String) // basic SQL val email: Option[Email] = DB readOnly { implicit s => sql"select * from account where uid = ${id}" .map(rs => Email(rs.get("name"), rs.get("mail_address")) ).single.apply() }
  • 29. Results Version Monad Async Mapping Typesafe DSL Genarated SQL Timing PlainSQL Slick 3.1.1 Required Always Required ※2 Supported Non-intuitiv e Runtime Supported Quill 0.10.0 Option ※1 - Supported ※3 Intuitive Compile time - doobie 0.3.0 Required Option - - - - Supported ※4 Scalike JDBC 2.4.2 - ※1 Required ※2 Supported Intuitive Runtime Supported ※1 Provides non-blocking API using postgresql-async or mysql-async ※2 A tool to generate table mappings from actual database schema is available ※3 Compile time SQL validation is available ※4 Runtime typechecking is available as experimental feature
  • 31. Conclusion ● Web Fraemwork ○ All alternatives look good, but Play2 is not so bad as well ○ For servlet container, Skinny Micro would be good ● Database Framework ○ There is no de-facto standard library currently ○ ScalikeJDBC looks good for us and almost users