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
1
vote
1 answer

Filtering in Slick with foreign key field

Is it possible to use a foreign key field in a Slick where or filter statement? Something like (where the user field is a foreign key to a Table for which User is its mapped projection) (this does not compile): def findByUser(user: User)(implicit s:…
Artur Soler
  • 2,974
  • 2
  • 23
  • 24
1
vote
1 answer

Scala Slick 2.0: converting from Query[Mixed, T#TableElementType] to Query[T, T#TableElementType]

Assume we have a table class Entry(tag :Tag) extends Table[(String, Long)](tag, "entries") { def name = column[String]("name") def value = column[Long]("value") def * = (name, value) } val Entries = new TableQuery(new Entry(_)) and a…
Turin
  • 2,208
  • 15
  • 23
1
vote
1 answer

scala slick 2.0 custom column type supporting nulls

I'm new to scala and slick and am having a bit of trouble. I am trying to implement a custom type mapper that supports nulls. This example is straightforward... http://slick.typesafe.com/doc/2.0.0/userdefined.html I'm looking for an example where…
m2512
  • 23
  • 4
1
vote
1 answer

Compilation Error with Slick for table > 22 columns (using HLists)

I've created a custom generator to map my database into my app and I'm having an issue. I've customized it to generate the auto increment columns as optional, so I've made this: val codegen = new scala.slick.model.codegen.SourceCodeGenerator(model)…
Augusto
  • 1,234
  • 1
  • 16
  • 35
1
vote
1 answer

Dynamically changing the database shard that I am connecting too

I want to have a pool of database connections, connecting to various sharded databases. On a per query basis I will pass in the tenant/customerId, and based on the customerId I will choose which database to connect and use for the current query. Is…
loyalflow
  • 14,275
  • 27
  • 107
  • 168
1
vote
1 answer

Scala/Play: Assigning a value that's not there yet

Say I have something like this: case class User(id:Option[Long], name: String) case class Account(id:Option[Long], userId: Long) object Account { // apply method def apply(i: Identity): Account = { Account(None,SomeFutureUserId) …
goo
  • 2,230
  • 4
  • 32
  • 53
1
vote
0 answers

Construct Completely Ad-hoc Slick Query

Pardon my newbieness but im trying to build a completely ad-hoc query builder using slick. From our API, I will get a list of strings that is representative of the table, as well as another list that represents the filter for the tables, munge then…
critium
  • 612
  • 5
  • 16
1
vote
1 answer

why slick2.0 can not find the TableQuery class in playframework 2.2.1?

My model is: import scala.slick.driver.PostgresDriver.simple._ import scala.slick.lifted.TableQuery class User(tag: Tag) extends Table[(Int, String, String)](tag, "User") { def id = column[Int]("SUP_ID", O.PrimaryKey) def name =…
user504909
  • 9,119
  • 12
  • 60
  • 109
1
vote
1 answer

Configuring DB driver dependency for Slick2-based projects in SBT?

I have two Scala projects managed by SBT - models_project and client_project. The models_project contains the DB models (Slick2-based). This project contains all the Slick tables and rows definitions. The client_project depends on the models_project…
polo
  • 1,352
  • 2
  • 16
  • 35
1
vote
2 answers

How to retrieve the auto incremented ID using slick / plainSQL?

Isn't there a slick/plainSQL native solution to retrieve the auto incremented id of the current INSERT? userId is an auto incremental field in my mySQL table. sql""" INSERT INTO `table`(`email`) OUTPUT INSERTED.userId VALUES…
OliverKK
  • 505
  • 4
  • 15
1
vote
1 answer

How to write a global object for table creation using Slick MultiDBCake principle?

I'm using Play framework btw. Slick does not help you "create" tables. Users have to create it by themselves, using tableQuery.ddl.create. When it was still Slick 1.0, I read a post about creating a Global.scalaand inside it looks like this: import…
windweller
  • 2,365
  • 5
  • 33
  • 56
1
vote
1 answer

Slick 2.0 MultiDBCakeExample AutoInc "into" function

I found many old posts on how the "old" AutoInc function works, but there is almost no post on how the new AutoInc function actually…
windweller
  • 2,365
  • 5
  • 33
  • 56
1
vote
1 answer

Scala/ Slick: Differentiate items inside an Union

How can I merge these two Coffee queries into one and indicate whether or not it's coffee or otherCoffee? Code: protected lazy val coffeeQuery = for { id <- Parameters[Long] coffee <- CoffeesTable if coffee.userId === id } yield…
goo
  • 2,230
  • 4
  • 32
  • 53
1
vote
1 answer

Filter using SQL JOIN syntax rather than WHERE in Slick 2.0

Is there a way in Slick 2.0 to create a method on a table class,that generates a SQL JOIN syntax rather than just a WHERE clause? Using an example similar to the documentation: class Suppliers(tag: Tag) extends Table[(Int, String)](tag, "SUPPLIER")…
headexplodes
  • 125
  • 1
  • 5
1
vote
0 answers

How construct a one-to-many relationship form in Play with Scala and Slick?

Based on @JacobusR's answer how can I program a form in the controller that allows me to send it to the view as a Form type with all one-side table columns mapping and many-side table seq-mapping? Something like this: In the Controller private val…
BigJoke
  • 855
  • 1
  • 7
  • 14