Questions tagged [slick]

Slick acronym for Scala Language-Integrated Connection Kit, is a modern database query and access library for Scala by Lightbend.

Slick

Slick is a modern database query and access library for Scala. It allows you to work with stored data almost as if you were using Scala collections while at the same time giving you full control over when a database access happens and which data is transferred. You can write your database queries in Scala instead of SQL, thus profiting from the static checking, compile-time safety and compositionality of Scala. Slick features an extensible query compiler which can generate code for different backends.

Slick (Scala Language-Integrated Connection Kit) is Lightbend‘s Functional Relational Mapping (FRM) library for Scala that makes it easy to work with relational databases. It allows you to work with stored data almost as if you were using Scala collections while at the same time giving you full control over when a database access happens and which data is transferred. You can also use SQL directly. Execution of database actions is done asynchronously, making Slick a perfect fit for your reactive applications based on Play and Akka.

2469 questions
21
votes
7 answers

Using Auto Incrementing fields with PostgreSQL and Slick

How does one insert records into PostgreSQL using AutoInc keys with Slick mapped tables? If I use and Option for the id in my case class and set it to None, then PostgreSQL will complain on insert that the field cannot be null. This works for H2,…
Jack
  • 16,506
  • 19
  • 100
  • 167
20
votes
2 answers

Slick 3.0.0: How to query one-to-many / many-to-many relations

Basically the same question has been asked about a year ago for slick 2.x (scala slick one-to-many collections). I'm wondering if there has any progression been made with the release of reactive slick. Let's say for example we have three tables.…
Roman
  • 5,651
  • 1
  • 30
  • 41
19
votes
1 answer

Optimizing Slick generated SQL query

I have a very simple query which in SQL can be represented as follows: SELECT c.id, count(cp.product_id) FROM cart c LEFT OUTER JOIN cart_product cp ON c.id = cp.cart_id WHERE c.id = 3 GROUP BY c.id; I was very surprised when using Slick DSL to…
Mon Calamari
  • 4,403
  • 3
  • 26
  • 44
19
votes
1 answer

Scala / Slick, "Timeout after 20000ms of waiting for a connection" error

The block of code below has been throwing an error. Timeout after 20000ms of waiting for a connection.","stackTrace":[{"file":"BaseHikariPool.java","line":228,"className":"com.zaxxer.hikari.pool.BaseHikariPool","method":"getConnection" Also, my…
user2827214
  • 1,191
  • 1
  • 13
  • 32
19
votes
5 answers

[SlickException: Read NULL value for column (USERS /670412212).LOGIN_ID]

I am using Slick 1.0.0 with play framework 2.1.0. I am getting the following error when I query my Users table. The value of LOGIN_ID is null in DB. The query I am executing is: val user = { for { u <- Users if u.providerId === id.id } yield…
Abhishek Pande
  • 313
  • 1
  • 4
  • 7
19
votes
2 answers

How does Scala Slick translate Scala code into JDBC?

How does Slick translate code such as: val q2 = for { c <- Coffees if c.price < 9.0 s <- Suppliers if s.id === c.supID } yield (c.name, s.name) for(t <- q2) println(" " + t._1 + " supplied by " + t._2) Into JDBC? Does it use Scala Virtualized?…
Phil
  • 46,436
  • 33
  • 110
  • 175
18
votes
1 answer

Slick 3.1 - Retrieving subset of columns as a case class

I'm working with Slick 3.1.1 and the problem is that in some cases I want to omit some columns that are fairly heavy and still materialize that subset of columns as a case class. Consider the following table definition: class AuditResultTable(tag:…
BrokenGlass
  • 158,293
  • 28
  • 286
  • 335
18
votes
3 answers

How to write dynamic SQL queries with sql""" interpolation in slick

I am new to Scala and Slick and trying to write a plain SQL queries with Slick interpolation. Case 1: I want the generalize the code so that queries are stored as constants. for instance: val SQL_ALL_TABLE_METADATA: String = """SELECT DISTINCT…
John
  • 443
  • 1
  • 5
  • 11
17
votes
3 answers

How do you run a patch/partial database UPDATE in Scala Slick?

We'd like to run a patch/partial UPDATE with Slick (3.0.0) so that we only modify some of the fields in a record. Exactly which fields will be updated exactly will only be known at runtime. For example, for a REST PATCH request. Currently we run a…
Ricardo Gladwell
  • 3,770
  • 4
  • 38
  • 59
17
votes
1 answer

Slick - Filter Row if Column is Null

How do I filter rows in Slick if a column is null? val employees = Queryable[Employees] // Error val query = employees.filter( _.terminationDate == Nil ) Might be important to note that terminationDate: Option[String] I am using Direct…
BAR
  • 15,909
  • 27
  • 97
  • 185
17
votes
4 answers

Turn Slick logging off

Slick fills up the console with a massive amount of log messages. I wanted, like the documentation suggested, to use slf4j-nop, so logging is turned off, but Akka needs its own slf4j library. So I'm left with akka-slf4j_2.10 that Slick also uses.…
Arthur C
  • 1,274
  • 1
  • 14
  • 34
17
votes
4 answers

Slick left/right/outer joins with Option

In the Slick examples there are a few examples of joining where one of the resulting columns can be nulls, as it can be the case when doing left, right, or outer joins. For example: val explicitLeftOuterJoin = for { (c, s) <- Coffees leftJoin…
siki
  • 9,077
  • 3
  • 27
  • 36
17
votes
1 answer

Why does Play action fail with "no suitable driver found" with Slick and PostgreSQL?

I'm writing a Scala web app using Play Framework 2.1.1 using a local Postgres database along with Slick 1.0.0, and I'm running into what seems to be a contradiction here. This is the error I'm running into: [SQLException: No suitable driver found…
Meredith
  • 3,928
  • 4
  • 33
  • 58
17
votes
8 answers

Logging options for Slick

I'm createing a Play 2.1 app, in which I have decided to use Slick for database interaction. However I can't find documentation about how to configure/enable logging for Slick. Anyone knows this?
user425367
17
votes
4 answers

Getting autoincrement values with Slick library in Scala

How do I get the auto-incremented values for records inserted with Slick? The following code prints 1111. I would have expected it to print 1234 import scala.slick.driver.H2Driver.simple._ object TestMappedTable extends App{ case class User(id:…
Jack
  • 16,506
  • 19
  • 100
  • 167