Questions tagged [slick-3.0]

Slick is a modern database query and access library for Scala by Typesafe.

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.

New in Slick 3.0.0-M1

These are the major new features in this miletone:

  • A new API for composing and executing database actions.
  • Improved configuration of database connections via Typesafe Config, including built-in support for HikariCP.
  • Support for nested Option types and non-primtive Option types in the Lifted Embedding.
  • Properly typed outer join operators based on the improved Option support.

Useful Links

488 questions
3
votes
0 answers

Mock database in Slick 3.x

I'm using Scalatest and Slick 3.1.1 and I want to mock Database to be able to return what I need. I've tried Scalamock. It doesn't even compile. And I've tried Mockito. It compiles, but mock always return null instead of specified Future. As I…
Artem Malinko
  • 1,761
  • 1
  • 22
  • 39
3
votes
0 answers

How to write date object into implicit converter?

I have a scala class with function named getUser which take a year & month. I am going to fetch a list of users with year & month based on birthday column which is defined as Instant. I am using postgresql & slick. I wrote a sql like as:-…
testuser
  • 793
  • 3
  • 13
  • 35
3
votes
1 answer

Why a block variable in scala function could not update after executed the inner block(s)?

I am new to scala. I have written a function named calculateSubTotal with a list of product id and quantities. At first the function will pick up a product from the database for each of the product id, then calculate the individual sub total and…
testuser
  • 793
  • 3
  • 13
  • 35
3
votes
1 answer

How to get String value from Rep[String] using slick 3 in Play scala?

I have a DAO method which returns an Future Option, it is like this: def authenticate(username: String, password: String): Future[Option[User]] = { val query = db.run(Users.filter(x => x.email === username &&…
Maverick
  • 2,738
  • 24
  • 91
  • 157
3
votes
2 answers

Defining and reading a nullable date column in Slick 3.x

I have a table with a column type date. This column accepts null values, therefore, I declared it as an Option (see field perDate below). The issue is that apparently the implicit conversion from/to java.time.LocalDate/java.sql.Date is incorrect as…
ps0604
  • 1,227
  • 23
  • 133
  • 330
3
votes
2 answers

Dynamic sortBy with Slick 3

I'm attempting to dynamically include a sortBy to my query which sorts based on its string name from a query parameter. In Slick 3 this has proven to be quite tricky. Currently my setup is: trait Model { type ATable <: AbstractTable[_] def…
Andreas Jarbol
  • 745
  • 2
  • 11
  • 27
3
votes
1 answer

Processing Akka stream in Slick transaction

Software versions: Akka 2.4.4 Slick 3.1.0 I want to process elements from an Akka stream in a Slick transaction. Here is some simplified code to illustrate one possible approach: def insert(d: AnimalFields): DBIO[Long] = animals returning…
devkat
  • 1,624
  • 14
  • 15
3
votes
2 answers

Performance slick query one to many

I'm using play 2.5 and slick 3.1.1 and I'm trying to build optimal query for multiple relations one to many, and one to one. I have a such db model: case class Accommodation(id: Option[Long], landlordId: Long, name: String) case class LandLord(id:…
Michał Jurczuk
  • 3,728
  • 4
  • 32
  • 56
3
votes
1 answer

Slick compile query with Set[Int] parameter

I have a query that takes Seq[Int] as it's argument (and performs filtering like WHERE x IN (...)), and I need to compile it since this query is failry complex. However, when I try the naive approach: Compiled((xs: Set[Int]) => someQuery.filter(_.x…
Maxim
  • 1,209
  • 15
  • 28
3
votes
1 answer

Slick 3.1.1 not creating unique constraint

I have simple User table with id set as auto increment and also username to be set as unique in table. class Users (tag: Tag) extends Table[User](tag, "Users") { def id = column[Int]("id", O.PrimaryKey, O.AutoInc) def username =…
surenyonjan
  • 2,097
  • 3
  • 17
  • 26
3
votes
3 answers

Is it possible to create an "infinite" stream from a database table using Akka Stream

I'm playing with Akka Streams 2.4.2 and am wondering if it's possible to setup a stream which uses a database table for a source and whenever there is a record added to the table that record is materialized and pushed downstream? UPDATE:…
Mark J Miller
  • 4,751
  • 5
  • 44
  • 74
3
votes
1 answer

Slick 3 many to many relations: how to get all the element of a table and their relations if they exist?

I'm working with Slick 3 and Play! 2.4 and I have a very common problem that I don't manage to resolve. I have a table playlist that can be linked to some tracks with the help of a relation table playlistsTracks. I want to be able to get all the…
Simon
  • 6,025
  • 7
  • 46
  • 98
3
votes
1 answer

Scala Slick - Convert TableQuery[E] to Query[E] to chain operations

I'm trying to apply a series of optional filtering operations to a query by using a list of the operations and folding over the list. val table = TableQuery[Fizz] val filters = List(filter1(option1)_, filter2(option2)_, filter3(option3)_) val…
kevin.qiu
  • 31
  • 1
  • 4
3
votes
1 answer

Build dynamic UPDATE query in Slick 3

I am looking for a way to generate an UPDATE query over multiple columns that are only known at runtime. For instance, given a List[(String, Int)], how would I go about generating a query in the form of UPDATE SET k1=v1, k2=v2, kn=vn for all…
Luke Cycon
  • 648
  • 4
  • 12
3
votes
0 answers

Slick + Dynamic TableQuery

For my own (mostly didactic - understanding the black magic behind slick and the reflection API of scala) purposes, I'd like to create a function that would be able to create a table if it is missing from the database, with an API such as…
Ákos Vandra-Meyer
  • 1,890
  • 1
  • 23
  • 40