3. 3
• Slick is database query and access library for Scala
• Slick IS NOT ORM it's Functional-Relational Mapper
• Brings relational model to Scala (not hidden)
• Natural fit (no impedance mismatch)
• Stateless
WHAT IS SLICK?
14. 14
Slick Querying (Update / Delete)
Update
A query for an UPDATE statement must resolve to a
comprehension with a single table
Delete
A query for deleting must only select from a single table.
17. 17
Joins
It's too simple... Lets consider more complex
example.
Get all users' addresses,
who subscribed on “New York
Times“ and has age > 18 and lives
in USA
25. 25
Plain SQL
- Slick allows you to write your own SQL
- Plain SQL queries in Slick are built via string interpolation
using the sql, sqlu and tsql
- sqlu is used for DML statements which produce a row count
instead of a result set.
26. 26
Plain SQL
- sql is used for statements which produce a result set.
- For mapping sql result to Model, you need to implement GetResult
34. 34
Reactive Streams In Slick 3
- Reactive Streams is an initiative to provide a standard for asynchronous stream
processing with non-blocking back pressure.
http://www.reactive-streams.org/
- Reactive Streams is a “protocol” for efficiently passing data between two
independent units of execution (producer & consumer) in an asynchronous,
non-blocking and bounded fashion.
35. 35
Advices
1. Always view on generated SQL
2. Try to get data you actually need in that moment (Query granularity)
3. Stay tuned with updates
4. Learn SQL
36. 36
Summary
Pros
+ Full Control
+ Type Safe
+ Composable Queries
+ Reactive
+ Minimal Boilerplate
Cons
- Generated SQL is far from
perfect
- Not always intuitive
- DSL has limitations