Reactive Database Access in Scala with Slick 3

Slides:



Advertisements
Similar presentations
Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
Advertisements

Slick SQL Interaction in Scala
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
A comparison of MySQL And Oracle Jeremy Haubrich.
Database Systems More SQL Database Design -- More SQL1.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Session-01. Hibernate Framework ? Why we use Hibernate ?
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
CVSQL 2 The Design. System Overview System Components CVSQL Server –Three network interfaces –Modular data source provider framework –Decoupled SQL parsing.
What is Slick and why we use it? Mark van der Tol.
MIS Week 11 Site:
PostgreSQL and relational databases As well as assignment 4…
Analysis of SQL injection prevention using a proxy server By: David Rowe Supervisor: Barry Irwin.
PHP Data Object (PDO) Khaled Al-Sham’aa. What is PDO? PDO is a PHP extension to formalise PHP's database connections by creating a uniform interface.
CSE314 Database Systems More SQL: Complex Queries, Triggers, Views, and Schema Modification Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
Python MySQL Database Access
Component 4/Unit 6f Topic VI: Create simple querying statements for the database The SELECT statement Clauses Functions Joins Subqueries Data manipulation.
Web Services Week 8 Aims: –Using web services as front ends to databases Objectives: –Review of relational databases –Connecting to and querying databases.
Chapter 7 Advanced SQL Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
Module 7 Reading SQL Server® 2008 R2 Execution Plans.
PostgreSQL and relational databases As well as assignment 4…
Databases and Data Access  Introduction to ADO.NET  ADO.NET objects  ADP.NET namespaces  Differences between ADO and ADO.NET.
Chapter 6 PHP Interacts with Mysql Database. Introduction In PHP, there is no consolidated interface. Instead, a set of library functions are provided.
SQL 101 for Web Developers 14 November What is a database and why have one? Tables, relationships, normalization SQL – What SQL is and isn’t – CRUD:
Understanding SQL Server 2008 Change Data Capture Bret Stateham Training Manager Vortex Learning Solutions blogs.netconnex.com.
Hibernate 3.0. What is Hibernate Hibernate is a free, open source Java package that makes it easy to work with relational databases. Hibernate makes it.
CS146 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Introduction to ADO.NET ADO.NET - Lesson 01  Training time: 10 minutes  Author:
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
ABSTRACT The JDBC (Java Database Connectivity) API is the industry standard for database- independent connectivity between the Java programming language.
Course FAQ’s I do not have any knowledge on SQL concepts or Database Testing. Will this course helps me to get through all the concepts? What kind of.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
1 Chapter 20 – Data sources and datasets Outline How to create a data source How to use a data source How to use Query Builder to build a simple query.
Visual Programing SQL Overview Section 1.
PHP Workshop ‹#› PHP Data Object (PDO). PHP Workshop ‹#› What is PDO? PDO is a PHP extension to formalise PHP's database connections by creating a uniform.
Database Design And Implementation. Done so far… Started a design of your own data model In Software Engineering, recognised the processes that occur.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Aliya Farheen October 29,2015.
JDBC CS 260 Database Systems. Overview  Introduction  JDBC driver types  Eclipse project setup  Programming with JDBC  Prepared statements  SQL.
ECMM6018 Enterprise Networking For Electronic Commerce Tutorial 6 CGI/Perl and databases.
Fundamentals of MyBATIS
IMS 4212: Constraints & Triggers 1 Dr. Lawrence West, Management Dept., University of Central Florida Stored Procedures in SQL Server.
Oracle Business Intelligence Foundation – Testing and Deploying OBI Repository.
Confidencial - TRACASA Automatize test [e- Reporting]
Best Practices in Loading Large Datasets Asanka Padmakumara (BSc,MCTS) SQL Server Sri Lanka User Group Meeting Oct 2013.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
MYSQL AND MYSQL WORKBENCH MIS2502 Data Analytics.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
 CONACT UC:  Magnific training   
Scott Fallen Sales Engineer, SQL Sentry Blog: scottfallen.blogspot.com.
 MySQL  DDL ◦ Create ◦ Alter  DML ◦ Insert ◦ Select ◦ Update ◦ Delete  DDL(again) ◦ Drop ◦ Truncate.
BTM 382 Database Management Chapter 8 Advanced SQL Chitu Okoli Associate Professor in Business Technology Management John Molson School of Business, Concordia.
JDBC.
Diving into Query Execution Plans ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
In this session, you will learn to: Create and manage views Implement a full-text search Implement batches Objectives.
High Performance Functions SQLBits VI. Going backwards is faster than going forwards.
SQL Introduction SQL stands for “Structured Query Language” and can be pronounced as “SQL” or “sequel – (Structured English.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Top 10 Entity Framework Features Every Developer Should Know
Connect to SQL Server and run select statements
Database Mysql Hayk Avdalyan.
A very brief introduction
Introduction To Codeigniter
Structured Query Language (SQL) William Klingelsmith
Overview Implementing Triggers Implementing XML Schemas.
SQL Fundamentals in Three Hours
Chapter 10 ADO.
Data Access Layer (Con’t) (Overview)
Updating Databases With Open SQL
Updating Databases With Open SQL
Presentation transcript:

Reactive Database Access in Scala with Slick 3 Ihor Mielientiev AUGUST 3, 2015

AGENDA What is Slick? 1 Introduction To Slick 2 Reactive Slick 3 3 Reactive Streams in Slick 3 4 Advices 5 Pros & Cons (Summary) 6 Q&A 7

WHAT IS SLICK? 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

Minimal Configuration

/resource/application.conf

Mapping

Slick Mapping

No XML, no Annotations, no “magic” Slick Mapping Do mapping in Scala Type Safe No XML, no Annotations, no “magic”

Scala collection-like API

Slick Querying Get users with age > 20 OR

Slick Querying Slick Generate Next SQL (H2):

Slick Querying (Insert) Inserting Batching Insert or update

Slick Querying (Insert 2) Insert and return object Batching with returning object

Slick Querying (Update / Delete) 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.

Joins Cross Join Inner Join

Joins Left Join Right Join Full Join

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

Joins

Joins (for-comprehension)

Joins Generated SQL Applicative join Monadic join

Joins Generated SQL If changes 'filter' order in applicative joins... Be careful, and look at generated SQL

Transactions - Transactions disabled by default - To enable transaction just add .transactionally

Transactions

Pre Compiled Queries

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.

Plain SQL - sql is used for statements which produce a result set. - For mapping sql result to Model, you need to implement GetResult

Type-checked SQL - Ability to type check hand-written SQL statements Add annotation: Use it (tsql):

Type-checked SQL Bad syntax:

Type-checked SQL Incorrect type:

Type-checked SQL Table doesn't exist: Field name error:

- Compilation depends on running DB Type-checked SQL (Issues) - Compilation depends on running DB - Increase compilation time - Limited IDE support

Supported Databases - DB2 (via slick-extensions) - Derby/JavaDB - H2 - HSQLDB/HyperSQL - Microsoft SQL Server (via slick-extensions) - MySQL - Oracle (via slick-extensions) - PostgreSQL - SQLite

Reactive Slick 3

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.

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

Pros Cons Summary - Generated SQL is far from perfect + Full Control + Type Safe + Composable Queries + Reactive + Minimal Boilerplate - Generated SQL is far from perfect - Not always intuitive - DSL has limitations

Thank you Questions?