What is Slick and why we use it? Mark van der Tol.

Slides:



Advertisements
Similar presentations
Relationell auch ohne SQL Relationale Datenbanken mit ScalaQuery nutzen Stefan Zeiger Commerzbank AG.
Advertisements

Patterns for Slick database applications Jan Christopher Vogt, EPFL Slick Team #scalax.
Slick SQL Interaction in Scala
Native XML Database or RDBMS. Data or Document orientation If you are primarily storing documents, then a Native XML Database may be the best option.
Aqua Data Studio. Find the application We are using Aqua Data Studio v11.
Scaling Scala to the Database Jan Christopher Vogt, EPFL Stefan Zeiger, Typesafe.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
Database Security CS461/ECE422 Spring Overview Database model – Relational Databases Access Control Inference and Statistical Databases Database.
Dr Gordon Russell, Napier University Unit Data Dictionary 1 Data Dictionary Unit 5.3.
CSCI 150 Database Applications Chapter 1 – Getting Started.
Informatiesystemen in de Bouw 7M711 Joran Jessurun en Jos van Leeuwen Week 3.
Getting Started (Excerpts) Chapter One DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
A Guide to MySQL 7. 2 Objectives Understand, define, and drop views Recognize the benefits of using views Use a view to update data Grant and revoke users’
Client-server database systems and ODBC l Client-server architecture and components l More on reliability and security l ODBC standard.
A little bit more about SQL Alternatives to MySQL Views/Triggers By Loïs Desplat.
Session-01. Hibernate Framework ? Why we use Hibernate ?
What is MongoDB? Developed by 10gen It is a NoSQL database A document-oriented database It uses BSON format.
Databases Dan Otero Alex Loddengaard
10. Creating and Maintaining Geographic Databases.
The Relational Model These slides are based on the slides of your text book.
Database Design for DNN Developers Sebastian Leupold.
CSCI 6962: Server-side Design and Programming JDBC Database Programming.
ASP.NET Programming with C# and SQL Server First Edition
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.
PRESENTED BY: LASONYA SHELBY 04/18/2010 LSTE 7309 The Importance of Databases.
MongoDB An introduction. What is MongoDB? The name Mongo is derived from Humongous To say that MongoDB can handle a humongous amount of data Document.
Database Solutions for Storing and Retrieving XML Documents.
Database Technical Session By: Prof. Adarsh Patel.
Goodbye rows and tables, hello documents and collections.
Eurotrace Hands-On The Eurotrace File System. 2 The Eurotrace file system Under MS ACCESS EUROTRACE generates several different files when you create.
DBSQL 14-1 Copyright © Genetic Computer School 2009 Chapter 14 Microsoft SQL Server.
Introduction to Database Management. 1-2 Outline  Database characteristics  DBMS features  Architectures  Organizational roles.
SQL Server 7.0 Maintaining Referential Integrity.
Relational Databases Database Driven Applications Retrieving Data Changing Data Analysing Data What is a DBMS An application that holds the data manages.
PHP Features. Features Clean syntax. Object-oriented fundamentals. An extensible architecture that encourages innovation. Support for both current and.
MySQL Group IV. Overview  Why Businesses need a database? Efficiency in everyday business operationsEfficiency in everyday business operations Reduced.
Dimu' Rumpak © 2009 by Prentice Hall 1 Getting Started Didimus Rumpak, M.Si. Database Concepts Chapter 1 1.
Reactive Database Access in Scala with Slick 3
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.
INFO1408 Database Design Concepts Week 15: Introduction to Database Management Systems.
1. When things go wrong: how to find SQL error Sveta Smirnova Principle Technical Support Engineer, Oracle.
Creating and Maintaining Geographic Databases. Outline Definitions Characteristics of DBMS Types of database Relational model SQL Spatial databases.
Nhóm thực hiện: nhóm 1 Nguyễn Ngọc Trường Trần Minh Khang Bùi Quốc Huy Nguyễn Ngọc Linh Nguyễn Thành Phương Trần.
Visual Programing SQL Overview Section 1.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
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.
SQL Overview Structured Query Language. Description  When Codd first described the theory of relational databases, he asserted that there should be a.
PHP Workshop ‹#› أطلق إبداعك 2 أطلق إبداعك 2 مدرس معتمد من مركز زووم PHP Data Object (PDO)
Database Systems Lecture 1. In this Lecture Course Information Databases and Database Systems Some History The Relational Model.
Basics of JDBC Session 14.
IT420: Database Management and Organization Triggers and Stored Procedures 24 February 2006 Adina Crăiniceanu
Oracle Business Intelligence Foundation – Testing and Deploying OBI Repository.
Copyright © 2004 Pearson Education, Inc. Chapter 1 Introduction and Conceptual Modeling.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
Chapter 3 The Relational Model. Why Study the Relational Model? Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. “Legacy.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
Introduction to Databases & SQL Ahmet Sacan. What you’ll need Firefox, SQLite plugin Mirdb and Targetscan databases.
Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.
Dive into NoSQL with Azure Niels Naglé Hylke Peek.
HOW TO DESKTOP USE by Mario C. Ponciano – a.k.a: Razec DBJMIN MULTI-DB Client (easy-to-use) (Step-by-Step) Jun/ v0.1.
Introduction to Mongo DB(NO SQL data Base)
Stored Procedures.
Dineesha Suraweera.
Tools for Memory: Database Management Systems
T-SQL Transact - Structured Query Language (Microsoft)
The Relational Model Relational Data Model
Data Model.
Introduction of Week 11 Return assignment 9-1 Collect assignment 10-1
Database SQL.
INTRODUCTION A Database system is basically a computer based record keeping system. The collection of data, usually referred to as the database, contains.
Presentation transcript:

What is Slick and why we use it? Mark van der Tol

Why we moved to SQL MongoDB has No joins or referential integrity No transactions Max element size for index Advantages PostgreSQL has Better indexes Better tooling Strict schema 2

Problem faced with MongoDB Query unseen alerts for users Data: { "message": "Example alert", "seenBy": [...] } Query: { "seenBy": { "$ne": "user" } } Max element size for indexed elements: 1 KB 3

Trivial in SQL SELECT message FROM alerts WHERE id NOT IN ( SELECT messageId FROM views WHERE user = "user" ) 4

MongoDB We keep using Mongo for statistics data Easier to shard/replicate No schema enforcement 5

What is Slick Database query library for Scala Table mapping Strongly typed Collection like syntax 6

Available for DB2* Derby/JavaDB H2 HSQLDB/HyperSQL Microsoft Access Microsoft SQL Server MySQL Oracle* PostgreSQL SQLite *Requires subscription for production use 7

Database connection import scala.slick.driver.PostgresDriver.simple._ import Database.threadLocalSession Database.forURL("jdbc:postgresql://…", driver = "org.postgresql.Driver") withSession { //session is now implicitly available in thread-local storage } Database.forURL("jdbc:postgresql://…", driver = "org.postgresql.Driver") withTransaction { //session is now implicitly available in thread-local storage } 8

Table definition object CoffeeTable extends Table[(String, BigDecimal, Int)]("COFFEE") { def name = column[String]("NAME", O.PrimaryKey) def price = column[BigDecimal]("PRICE") def sales = column[Int]("SALES") def * = name ~ price ~ sales } 9

Simple SELECT query val minPrice: BigDecimal = 1.0 val query = for { c <- CoffeeTable if (c.price >= minPrice) } yield (c.name) val names = query.list 10

Table definition for Case class case class Coffee (name: String, price: BigDecimal, sales: Int) object CoffeeTable extends Table[Coffee]("coffee") { def name = column[String]("NAME", O.PrimaryKey) def price = column[BigDecimal]("PRICE") def sales = column[Int]("SALES") def * = name ~ price ~ sales <> (Coffee, Coffee.unapply _) } 11

Simple SELECT query val query = for { c <- CoffeeTable } yield (c) val coffees = query.list 12

SELECT query with join val query = for { p <- PersonTable c <- CoffeeTable if (p.favoriteCoffee === c.name) } yield (p.name, c.name, c.price) 13

INSERT query CoffeeTable.insert( Coffee("Java", 2.50, 0) ) 14

UPDATE/DELETE query val query = for { c <- CoffeeTable if (c.price < 1.50) } yield (c.price) query.update(1.50) query.delete 15

Plain SQL queries val query = StaticQuery.query[BigDecimal, (String, Int)]( """select c.name, c.sales from coffees c where c.price < ?""" ) 16

Features not shown Queries with parameters Extensible: Add own types and functions "Direct embedding" 17

Features Query library that stays close to SQL Hides dbms specific syntax Prevents SQL-injections Many checks compile time 18

Disadvantages DSL not always intuitive Difficult compile errors Focus on single thread usage Not very comprehensive documentation 19

Multi-threaded use workaround val session = Database.forURL("jdbc:…", driver = “…").createSession() session.conn.setAutoCommit(false) //prevent Slick from creating transactions itself session.asInstanceOf[BaseSession].inTransaction = true … session.conn.commit() session.close() 20

Resources Slick: Sheets: 21

THANK YOU 22