doobie : un jdbc fonctionnel qui ne cache pas sql
TRANSCRIPT
![Page 1: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/1.jpg)
Feedbacks from the trenches
François ARMAND @fanf42 - 2016-10
![Page 2: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/2.jpg)
?
Who knows...
![Page 3: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/3.jpg)
??JdbcTemplate
Who knows...
![Page 4: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/4.jpg)
??JdbcTemplate
?Who knows...
![Page 5: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/5.jpg)
?
Anorm ??Who knows...
?JdbcTemplate
![Page 6: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/6.jpg)
?
Anorm ?Squeryl ? ?JdbcTemplate
?Who knows...
![Page 7: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/7.jpg)
?
Anorm ?Squeryl ? ?JdbcTemplate
?
?
Who knows...
![Page 8: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/8.jpg)
?
Anorm ?Squeryl ? ?JdbcTemplate
?
?SQL?
Who knows...
OBJECT MAPPING
PURESQL
![Page 9: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/9.jpg)
?
Anorm ?Squeryl ? ?JdbcTemplate
?
?SQL?
Love SQL ?
Who knows...
![Page 10: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/10.jpg)
Who’s talkin’ for why?
● 10 years of Scala
● CTO @Normation● Lead-dev on Rudder● chose Scala 7y ago for Rudder
Continuous Configuration for Effective ComplianceFrançois ARMAND / @fanf42
![Page 11: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/11.jpg)
● 10 years of Scala
● CTO @Normation● Lead-dev on Rudder● chose Scala 7y ago for Rudder
Continuous Configuration for Effective Compliance
Squeryl
François ARMAND / @fanf42
Who’s talkin’ for why?
![Page 12: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/12.jpg)
● 10 years of Scala
● CTO @Normation● Lead-dev on Rudder● chose Scala 7y ago for Rudder
Continuous Configuration for Effective Compliance
SquerylJdbcTemplate
François ARMAND / @fanf42
Who’s talkin’ for why?
![Page 13: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/13.jpg)
But what ?
● 10 years of Scala
● CTO @Normation● Lead-dev on Rudder● chose Scala 7y ago for Rudder
Continuous Configuration for Effective Compliance
SquerylJdbcTemplate
François ARMAND / @fanf42
Who’s talkin’ for why?
![Page 14: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/14.jpg)
Slick 3 ?
● Fairly popular, ~ default choice in 2016 for Scala world
● Let’s test it ! ⇒ ported ~ 50% of Rudder code to it.
![Page 15: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/15.jpg)
● Fairly popular, ~ default choice in 2016 for Scala world
● Let’s test it ! ⇒ ported ~ 50% of Rudder code to it.
● Does not work for us :● Feels magic and ORM-y, with *Surprises*
○ in generated SQL■ you can’t precisely control it (that’s the point)
○ in performance (using path of least resistance)■ ex: run-time compilation for EACH request in the path of least resistance
○ with lift embeding type ■ i.e working with Rep[MyClass] in place of MyClass
● An awful lot of boilerplate
Slick 3 ?
![Page 16: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/16.jpg)
Doobie ?
![Page 17: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/17.jpg)
Use Doobie. It’s GREAT.
Doobie
![Page 18: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/18.jpg)
Use Doobie. It’s GREAT.
Questions ?
Doobie
![Page 19: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/19.jpg)
Use Doobie.It’s GREAT.
● A pure functional database access layer for Scala
Doobie
![Page 20: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/20.jpg)
Use Doobie.It’s GREAT.
● A pure functional database access layer for Scala
● Mapping is a joy (actually make me smile)
Doobie
![Page 21: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/21.jpg)
Use Doobie.It’s GREAT.
● A pure functional database access layer for Scala
● Mapping is a joy (actually make me smile)
● No surprises :○ it just works as expected. ○ Performance are ~ raw JDBC.○ NO JDBC part is beyond reach.
■ Even dirty things about JDBC connection like SQLXML. Or variable number of params.
Doobie
![Page 22: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/22.jpg)
Use Doobie.It’s GREAT.
● A pure functional database access layer for Scala
● Mapping is a joy (actually make me smile)
● No surprises :○ it just works as expected. ○ Performance are ~ raw JDBC.○ NO JDBC part is beyond reach.
■ Even dirty things about JDBC connection like SQLXML. Or variable number of params.
● Rob Norris (@tpolecat) is über nice and helpful
Doobie
![Page 23: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/23.jpg)
Use Doobie.It’s GREAT.
● A pure functional database access layer for Scala
● Mapping is a joy (actually make me smile)
● No surprises :○ it just works as expected. ○ Performance are ~ raw JDBC.○ NO JDBC part is beyond reach.
■ Even dirty things about JDBC connection like SQLXML. Or variable number of params.
● Rob Norris (@tpolecat) is über nice and helpful
● It actually makes me like SQL ○ (it tooks 15 years, and PostgreSQL helps a lot)
Doobie
![Page 24: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/24.jpg)
Use Doobie.It’s GREAT.
● A pure functional database access layer for Scala
● Mapping is a joy (actually make me smile)
● No surprises :○ it just works as expected. ○ Performance are ~ raw JDBC.○ NO JDBC part is beyond reach.
■ Even dirty things about JDBC connection like SQLXML. Or variable number of params.
● Rob Norris (@tpolecat) is über nice and helpful
● It actually makes me like SQL ○ (it tooks 15 years, and PostgreSQL helps a lot)
Doobie
![Page 25: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/25.jpg)
A pure functional database access layer for Scala
● everything is a value● standard functional programming idioms apply● Clear separation of concepts
○ (I won’t talk about Free Monad - oups)
![Page 26: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/26.jpg)
Mapping just works. Returns what you want.
![Page 27: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/27.jpg)
Mapping just works. No boilerplate.
![Page 28: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/28.jpg)
Mapping just works. No boilerplate.
![Page 29: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/29.jpg)
Mapping just works. No boilerplate.
![Page 30: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/30.jpg)
Performance (especially in pure FP) matters
● The exact, 50 lines if you want,SQL queries you want to write.
● PreparedStatement by default.● Batch updates are given.
● Comparison with JDBC
![Page 31: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/31.jpg)
Rob Norris @tpolecat
(like, he produced working code for SQLXML mapping. At 3 a.m. Just for me)(OK, 3 a.m for my timezone. But still :)
is extremely nice and helpful
actually likes SQL
![Page 32: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/32.jpg)
Yes. Really.
Savant word for
“Makes you love SQL - No surprise, it just works”
Questions ?
The End
![Page 33: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/33.jpg)
Testing mapping in the repl
![Page 34: Doobie : Un JDBC fonctionnel qui ne cache pas SQL](https://reader031.vdocuments.mx/reader031/viewer/2022022412/58f2944a1a28ab48648b45ff/html5/thumbnails/34.jpg)
References
● Book of Doobie : https://tpolecat.github.io/doobie-0.3.0/00-index.html
● Really nice presentation of concepts:○ SBTB 2015: Rob Norris, Programs as Values: JDBC Programming with Doobie
■ https://www.youtube.com/watch?v=M5MF6M7FHPo
● https://twitter.com/tpolecat
● https://gitter.im/tpolecat/doobie