Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Slick - The Structured Way

1,804 views

Published on

Slick (part of the Typesafe stack) is a modern database query and access library for Scala, based on functional principles. It allows you to write queries as if you are working with regular Scala collections.

In this presentation we’ll have a deep dive into how you can use this library in real projects. How to map your tables and queries to structured objects, how to create more advanced queries with multiple joins, how to setup integration tests against an in-memory database and how you can integrate Slick with the Play Framework are all questions which will have been answered at the end of this presentation.

Originally presented on the BeScala user group.

Published in: Technology
  • Be the first to comment

Slick - The Structured Way

  1. 1. Slick The Structured Way
  2. 2. YENNICK? YANNICK? JANNICK? Reactive Applications Consultant Certified Typesafe “Fast Track to Scala” trainer @SlevinBE yennicktrevels.com Yennick.Trevels@xploregroup.be
  3. 3. WHY SLICK? Option(Anorm).orElse(Hibernate).orElse(Slick) Pure Scala Immutable data structures DB agnostic code Type safety
  4. 4. TALK MOTIVATION
  5. 5. MEAT OF THE TALK
  6. 6. ESSENTIALS Build queries with Scala Lifted embedding Query result  result rows ID TITLE ID FIRSTNAME LASTNAME 1 “Scala” 10 Yennick Trevels 1 “Scala” 11 Eric Loots 2 “Slick” 12 Filip Maelbrancke
  7. 7. IMPORTS Database specific Database agnostic import  use Play-Slick plugin
  8. 8. SESSION SCOPE
  9. 9. TRANSACTION SCOPE
  10. 10. SAMPLE DATABASE MEETING DOCUMENT ATTENDEE_LINK ATTENDEE ID … MEETING_I D ATTENDEE_I D ID … MEETING_ID ID … ID …
  11. 11. LEVEL 1: MAPPING TABLES
  12. 12. TABLE MAPPING: MEETING
  13. 13. TABLE MAPPING: MEETING
  14. 14. TABLE MAPPING: LINK TABLE
  15. 15. LEVEL 2: BASIC QUERIES
  16. 16. FILTER STATEMENTS Slick SQL  === instead of ==
  17. 17. FILTER STATEMENTS Slick Brackets Put || or && at end of line ↵
  18. 18. SORTING Slick SQL
  19. 19. EXISTS Slick SQL
  20. 20. DEFINING THE RESULT Slick SQL Result
  21. 21. DEFINING THE RESULT Slick SQL Result
  22. 22. DEFINING THE RESULT Slick meetings.list  List[Meeting] meetings.first  Meeting or NoSuchElementException meetings.firstOption  Option[Meeting]
  23. 23. LEVEL 3: ADVANCED QUERIES
  24. 24. INNER JOIN Slick SQL Result
  25. 25. INNER JOIN (RESULT MAPPING) Slick Result
  26. 26. OUTER JOINS (THE PROBLEM) Slick
  27. 27. OUTER JOINS (THE PROBLEM) ID TITLE ID MEETING_ID ATTENDEE_ID 1 “Scala” NULL NULL NULL 2 “Slick” 10 2 20 3 “Slick” 11 2 21 ID TITLE 1 “Scala” 2 “Slick” ID MEETING_ID ATTENDEE_ID 10 2 20 11 2 21 Left Join Ref: http://www.slideshare.net/skillsmatter/patterns-for-slick-database-applications
  28. 28. OUTER JOINS Slick Result
  29. 29. OUTER JOINS (RESULT TRANSF.) Slick
  30. 30. THE ? FUNCTION Solution expected somewhere this year
  31. 31. LEVEL 4: INSERT/UPDATE/DELETE
  32. 32. INSERT Slick SQL
  33. 33. UPDATE Slick SQL
  34. 34. DELETE Slick SQL
  35. 35. LEVEL 5: SLICK + PLAY
  36. 36. APPLICATION.CONF
  37. 37. DATABASE AGNOSTIC IMPORTS
  38. 38. DB WRAPPER
  39. 39. LEVEL 6: INTEGRATION TESTING
  40. 40. TABLE CREATION Using Play-Slick plugin classes
  41. 41. IN-MEMORY DATABASE CONFIG
  42. 42. TEST DATA SETUP Just use Slick…
  43. 43. CONCLUSION
  44. 44. THOUGHTS ON SLICK + Lightweight + Level of control + Production ready - Documentation - Generated Queries (readability)
  45. 45. Development Coaching Training Hello Scala seminarJune 25th 2014 Fast Track to Scala October 09th 2014 Fast Track to Akka with Scala November 04th 2014 Yennick.Trevels@xploregroup.be CONTACT US

×