doobie : un jdbc fonctionnel qui ne cache pas sql

34
Feedbacks from the trenches François ARMAND @fanf42 - 2016-10

Upload: paris-scala-user-group

Post on 16-Apr-2017

100 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Doobie : Un JDBC fonctionnel qui ne cache pas SQL

Feedbacks from the trenches

François ARMAND @fanf42 - 2016-10

Page 2: Doobie : Un JDBC fonctionnel qui ne cache pas SQL

?

Who knows...

Page 3: Doobie : Un JDBC fonctionnel qui ne cache pas SQL

??JdbcTemplate

Who knows...

Page 4: Doobie : Un JDBC fonctionnel qui ne cache pas SQL

??JdbcTemplate

?Who knows...

Page 5: Doobie : Un JDBC fonctionnel qui ne cache pas SQL

?

Anorm ??Who knows...

?JdbcTemplate

Page 6: Doobie : Un JDBC fonctionnel qui ne cache pas SQL

?

Anorm ?Squeryl ? ?JdbcTemplate

?Who knows...

Page 7: Doobie : Un JDBC fonctionnel qui ne cache pas SQL

?

Anorm ?Squeryl ? ?JdbcTemplate

?

?

Who knows...

Page 8: Doobie : Un JDBC fonctionnel qui ne cache pas SQL

?

Anorm ?Squeryl ? ?JdbcTemplate

?

?SQL?

Who knows...

OBJECT MAPPING

PURESQL

Page 9: Doobie : Un JDBC fonctionnel qui ne cache pas SQL

?

Anorm ?Squeryl ? ?JdbcTemplate

?

?SQL?

Love SQL ?

Who knows...

Page 10: Doobie : Un JDBC fonctionnel qui ne cache pas SQL

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

● 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

● 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

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

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

● 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

Doobie ?

Page 17: Doobie : Un JDBC fonctionnel qui ne cache pas SQL

Use Doobie. It’s GREAT.

Doobie

Page 18: Doobie : Un JDBC fonctionnel qui ne cache pas SQL

Use Doobie. It’s GREAT.

Questions ?

Doobie

Page 19: Doobie : Un JDBC fonctionnel qui ne cache pas SQL

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

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

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

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

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

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

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

Mapping just works. Returns what you want.

Page 27: Doobie : Un JDBC fonctionnel qui ne cache pas SQL

Mapping just works. No boilerplate.

Page 28: Doobie : Un JDBC fonctionnel qui ne cache pas SQL

Mapping just works. No boilerplate.

Page 29: Doobie : Un JDBC fonctionnel qui ne cache pas SQL

Mapping just works. No boilerplate.

Page 30: Doobie : Un JDBC fonctionnel qui ne cache pas SQL

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

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

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

Testing mapping in the repl

Page 34: Doobie : Un JDBC fonctionnel qui ne cache pas SQL

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