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
12
votes
2 answers

How to catch slick postgres exceptions for duplicate key value violations

My table has a unique index on a pair of columns in my postgresql database. I want to know how I can catch a duplicate key exception when I am inserting: def save(user: User)(implicit session: Session): User = { val newId = (users returning…
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
12
votes
1 answer

Slick - Compiled with dynamic sortBy

I know as of slick 2.1. one can use ConstColumn for take and drop in precompiled Query's using "Compiled". private val findXXXCompiled = Compiled { (someId:Column[Long], sortBy:???, drop:ConstColumn[Long], take:ConstColumn[Long]) => val q…
tfh
  • 620
  • 1
  • 4
  • 14
12
votes
1 answer

Selecting many arbitrary columns in Slick

I'm trying to run a SELECT *-style query in Slick against a view. Ideally, I'd end up with a function that you can pass a set of column names as a Seq[String] and it'd execute the query SELECT col1, col2, ... FROM view. If that's not feasible then…
Alex
  • 439
  • 4
  • 8
12
votes
1 answer

Scala, Play Framework Slick issue - could not find implicit value for parameter rconv

I'm following guidelines of Slick documentation and I don't understand what I'm doing wrong here: package models import scala.slick.session.Database import Database.threadLocalSession import scala.slick.jdbc.{GetResult, StaticQuery => Q} import…
Caballero
  • 11,546
  • 22
  • 103
  • 163
12
votes
2 answers

Play scala advice on anorm vs slick

I am thinking of learning and using the play framework with scala for building web apps. However, I would like real advice on choosing between anorm and slick. My reservation for slick is the following: Will it remain free? Note: Quote from the…
zulqarnain
  • 1,695
  • 1
  • 16
  • 33
12
votes
2 answers

Scala Slick: Issues with groupBy and missing shapes

I'm trying to use Slick to query a many-to-many relationship, but I'm running into a variety of errors, the most prominent being "Don't know how to unpack (User, Skill) to T and pack to G". The structure of the tables is similar to the…
kcuf
  • 133
  • 5
12
votes
5 answers

Select single row based on Id in Slick

I want to query a single row from user based on Id. I have following dummy code case class User( id: Option[Int], name: String } object Users extends Table[User]("user") { def id = column[Int]("id", O.PrimaryKey, O.AutoInc) def name =…
Khalid Saifullah
  • 747
  • 2
  • 8
  • 21
12
votes
5 answers

Slick issue when going with PostgreSQL

I'm using slick in a scala project to query some tables. //define table object Addresses extends Table[Address]("assetxs.address") { def id = column[Int]("id", O.PrimaryKey) def street = column[String]("street") def number =…
Cristian Boariu
  • 9,603
  • 14
  • 91
  • 162
12
votes
1 answer

Select rows based on MAX values of a column in ScalaQuery/SLICK

Say that i have table such as: UserActions UserId INT ActionDate TIMESTAMP Description TEXT that holds dates where users perfomed certainActions. If i wanted to get the last action that every user perfomed, i would have to do something…
Angel Blanco
  • 681
  • 7
  • 18
11
votes
2 answers

How to convert java.sql.Timestamp to java.time.OffsetDateTime?

I'm working on a Scala project and I need to map OffsetDateTime type to SQL Timestamp type. In DB I would like to have UTC times. The conversion from OffsetDateTime to Timestamp is straightforward (hint from this question) and it works as…
Alberto Coletta
  • 1,563
  • 2
  • 15
  • 24
11
votes
1 answer

No operations allowed after connection closed errors in Slick/HikariCP

I'm using Slick3.1.1 + HikariCP2.5.1. My config is: rdsConfig = { url = "jdbc:mysql://mydb.........us-west-2.rds.amazonaws.com:3306/owlschema" driver = "com.mysql.jdbc.Driver" connectionPool = HikariCP maxConnections = 222 …
thund
  • 1,842
  • 2
  • 21
  • 31
11
votes
4 answers

Play/Slick: SQLTimeoutException: Timeout after 1001ms of waiting for a connection

I've created an empty (activator template play-scala) Play 2.4.3 application with PostgreSQL 9.4 database and trying to use Slick 3.1.0 with it, but it's throwing an error: play.api.UnexpectedException: Unexpected exception[SQLTimeoutException:…
Caballero
  • 11,546
  • 22
  • 103
  • 163
11
votes
1 answer

SLICK 3.0 - multiple queries depending on one another - db.run(action)

I am new to Slick 3 and so far I have understood that db.run are asynchronous call. the .map or .flatMap is run once the Future is returned. The problem in my code below is that all the sub queries do not work (nested db.run). Conceptually speaking,…
user1237981
  • 165
  • 1
  • 8
11
votes
1 answer

Slick/Scala: What is a Rep[Bind] and how do I turn it into a value?

I'm trying to figure out Slick (the Scala functional relational model). I've started to build a prototype in Slick 3.0.0 but of course... most of the documentation is either out of date or incomplete. I've managed to get to a point where I can…
Zaphod
  • 1,387
  • 2
  • 17
  • 33
11
votes
1 answer

How to select max, min in same query in slick

I want to do this SELECT MAX(age), MIN(age) FROM users WHERE name = 'Rick'. The best I came up with involves 2 queries: Users.filter(_.name === 'Rick').map(_.age).max
pathikrit
  • 32,469
  • 37
  • 142
  • 221