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
0 answers

How do I provide the proper type information to get my generic filter function working for slick

I'm trying to implement some generic filters in a base class for my slick tables. What I'm trying to accomplish is the ability to translate url query strings into database filters. I've come up with a working solution, but the code isn't very DRY.…
1
vote
1 answer

scala.slick.SlickException: JdbcProfile has no JdbcType for type UnassignedType - on Option fields

I was successfully mapped case classes w/o Optional fields to Postgres db via class that extends Table. Now I need to use case class with Optional[String] and Optional[DateTime] fields. I has found how to declare mapping for it: case class…
1
vote
1 answer

How to compile a query with 2 parameters

Now sure how to do this correctly, I'm trying to do this: def byId(id: Column[Int], locationId: Column[Int]) = { for { m <- users if m.id === id && m.locationId == locationId } yield m } val byIdCompiled = Compiled(byId _) // ????????????…
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
1
vote
1 answer

How to do an sortBy with a field and a count(*) on a joined table in Slick 2?

I'm trying to sort my query by one field and the count of the joined query. That's my SQL: SELECT * FROM stmt s LEFT JOIN rctn r ON s.id = r.stmt_id GROUP BY s.id ORDER BY (s.time + INTERVAL 1*COUNT(r.stmt_id) DAY) DESC I already…
pichsenmeister
  • 2,132
  • 4
  • 18
  • 34
1
vote
2 answers

Can I wrap sessions to create a transaction with slick?

I have my DAO code that looks like: UserDao.scala: def save(user: User)(implicit session: Session) ... { .... } Then UserService: def save(user: User) .. { db.withSession { implicit session => userDao.save(user) } } I have other…
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
1
vote
1 answer

Incrementing a column without using plain sql

I am currently incrementing a column (not a auto-increment PK column) in my database using the following: def incrementLikeCount(thingId: Int)(implicit session: Session) = { sqlu"update things set like_count = like_count + 1 where id =…
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
1
vote
1 answer

Slick 2 - combine queries

I would like to combine queries programatically to create a query resulting in all requirements satisfied. I can see there is a union and ++ operator, but I see no "intersection" or **. Assuming Slick FirstExample, let us have a code: val notCheap…
Suma
  • 33,181
  • 16
  • 123
  • 191
1
vote
1 answer

Slick/Scala - how do I access fields of the mapped projection/projected table part of a join in a where query

I have a number of basic queries define, and am using query composition to add stuff such as ordering, paging, where clauses and so on... But I have a problem accessing the fields of the joined 2nd table in the where clause... Here's my table…
1
vote
1 answer

Scala Slick Model with Optional Image column

I am trying to add a column to an existing model that has an optional image, I am using Scala Slick with the Play Framework. What would be an example of storing a image with a Scala Slick model? case class…
Lilluda 5
  • 1,111
  • 3
  • 18
  • 38
1
vote
1 answer

Slick 2 aggregation - how to get a scalar result?

I have a table with an Int column TIME in it: def time = column[Int]("TIME") The table is mapped to a custom type. I want to find a maximum time value, i.e. to perform a simple aggregation. The example in the documentation seems easy enough: val q…
Suma
  • 33,181
  • 16
  • 123
  • 191
1
vote
1 answer

Type mismatch error between Joda DateTime and sql Timestamp in Slick GetResult

I want to retrieve data of a column with type DateTime and I am using jodatime for it. Even though I have a custom TypeMapper, I am getting type mismatch error. [error] C:\sample\modules\test\com\samp\user.scala:55: type mismatch; [error] found :…
1
vote
1 answer

Guidance on play's execution context and creating my jdbc thread pool

I'm trying to understand play's execution context and exactly how this fits into how I am using play with google guice. A typical control that I am building looks like: @Singleton class MyController @Inject()(myService: MyService) extends Controller…
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
1
vote
2 answers

Passing Slick 2.0 implicit session in elegant way

I'm new to Slick and Scala. First of take a look at my example table with case class mapping and helper for queries SuitsManager. Now methods of SuitsManager are called by Play! controllers inside DBAction (I'm using play-slick 0.6.0.1). package…
Sebastian
  • 663
  • 1
  • 7
  • 20
1
vote
2 answers

SLICK: How to use query result in another query?

I'd like to perform something like the following: I'd like to return a list of users sorted first by who the user is "following", second by some additional point score. The following code below which I wrote however doesn't work because the funder…
Setheron
  • 3,520
  • 3
  • 34
  • 52
1
vote
1 answer

Four different functions with different return type, same error

I am studying scala and slick. And I got an error like this: found : Option[Int] required: Int def update(c: Color): Int = findById(c.id).update(c) I am not sure what is found and required stand for. So I add other functions: def update(c:…
Sato
  • 8,192
  • 17
  • 60
  • 115