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

scala slick method I can not understand so far

I try to understand some Slick works and what it requires. Here it an example: package models case class Bar(id: Option[Int] = None, name: String) object Bars extends Table[Bar]("bar") { def id = column[Int]("id", O.PrimaryKey, O.AutoInc) //…
ses
  • 13,174
  • 31
  • 123
  • 226
62
votes
4 answers

How to write database-agnostic Play application and perform first-time database initialization?

I'm using Slick with a Play Framework 2.1 and I have some troubles. Given the following entity... package models import scala.slick.driver.PostgresDriver.simple._ case class Account(id: Option[Long], email: String, password: String) object…
j3d
  • 9,492
  • 22
  • 88
  • 172
49
votes
2 answers

How do you update multiple columns using Slick Lifted Embedding?

How do you update multiple columns using Slick Lifted Embedding ? This document doesn't say much. I expected it to be something like this Query(AbilitiesTable).filter((ab: AbilitiesTable.type) => ab.id === ability_id).map((ab: AbilitiesTable.type)…
expert
  • 29,290
  • 30
  • 110
  • 214
46
votes
2 answers

View SQL query in Slick

Is there a way to observe an SQL statement that will be generated by Query? For example, I have this: val q = actions.filter(v => v.actionHash === hash && v.carriedAt > past) Can I view its underlying raw SQL?
src091
  • 2,807
  • 7
  • 44
  • 74
44
votes
4 answers

Using .tupled method when companion object is in class

I am in the process of migrating from Slick to Slick 2, and in Slick 2 you are meant to use the tupled method when projecting onto a case class (as shown here http://slick.typesafe.com/doc/2.0.0-RC1/migration.html) The problem is when the case class…
mdedetrich
  • 1,899
  • 1
  • 18
  • 29
38
votes
2 answers

Slick 3.0 Insert and then get Auto Increment Value

I have written this code which works perfectly class Items(tag: Tag) extends Table[Item](tag, "ITEMS") { def id = column[Long]("ITEMS_ID", O.PrimaryKey, O.AutoInc) def name = column[String]("ITEMS_NAME") def price =…
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
33
votes
2 answers

Scala Slick table tag

In slick table there is a tag parameter: class Companies(tag: Tag) extends Table[Company](tag,"COMPANY") {...} What is it used for, and is there any way not to write it with each table class definition?
Taras Bilinsky
  • 579
  • 5
  • 10
33
votes
3 answers

How to use SQL "LIKE" operator in SLICK

Maybe a silly question. But I have not found an answer so far. So how do you represent the SQL's "LIKE" operator in SLICK?
wassertim
  • 3,116
  • 2
  • 24
  • 39
32
votes
3 answers

Slick 3.0 bulk insert or update (upsert)

what is the correct way to do a bulk insertOrUpdate in Slick 3.0? I am using MySQL where the appropriate query would be INSERT INTO table (a,b,c) VALUES (1,2,3),(4,5,6) ON DUPLICATE KEY UPDATE c=VALUES(a)+VALUES(b); MySQL bulk INSERT or UPDATE Here…
opus111
  • 2,744
  • 4
  • 25
  • 41
31
votes
4 answers

SELECT DISTINCT in Scala slick

I am using Slick 1, and I have to be able to apply a filter in a query to lookup all entities that match a condition in a related table. This example using the Slick documentation shows what I am trying to do (this is a contrived example that is…
noplay
  • 2,391
  • 6
  • 26
  • 33
29
votes
2 answers

A binding to play.api.db.DBApi was already configured, evolutions and injector error with play-slick

I want to introduce slick to my play project, so I add the following dependencies to build.sbt: "com.typesafe.play" %% "play-slick" % "1.0.1" withSources(), "com.typesafe.play" %% "play-slick-evolutions" %…
ttt
  • 3,934
  • 8
  • 46
  • 85
29
votes
1 answer

Is Slick 3.0 reactive/asynchronous at the database driver level? For which databases?

Slick has historically relied on JDBC drivers, which internally block waiting for socket I/O in response to queries. Every outstanding database call requires a thread to block on a socket; hence, it's not really reactive in the same sense as…
Ed Staub
  • 15,480
  • 3
  • 61
  • 91
29
votes
2 answers

Upsert in Slick

Is there a way I can neatly do an upsert operation in Slick? The following works but is too obscure/verbose and I need to explicitly state the fields that should be updated: val id = 1 val now = new Timestamp(System.currentTimeMillis) val q = for {…
Synesso
  • 37,610
  • 35
  • 136
  • 207
29
votes
4 answers

Scala slick query where in list

I am attempting to learn to use Slick to query MySQL. I have the following type of query working to get a single Visit object: Q.query[(Int,Int), Visit](""" select * from visit where vistor = ? and location_code =…
ShatyUT
  • 1,375
  • 2
  • 14
  • 28
28
votes
4 answers

Connection pooling in slick?

Is there an easy way to use a DB connection pool with scala's Slick?
Pablo Fernandez
  • 103,170
  • 56
  • 192
  • 232
1
2 3
99 100