slick

How to do “OR” filter in slick

只愿长相守 提交于 2019-11-30 18:28:25
In slick we can use query.filter( m => (m.state === state1 && m.status === status1) || (m.state === state2 && m.status == status2)) for an "OR" condition in where clause. However my requirement is I have "OR" conditions in a list (passed by user as part of URL). Conditions list includes tuples of state and status like List[(state1, status1),(state2, status2),(state3, status3)] So what I wanted was to either be able to build the || statement inside of filter so that I can use each of the conditions from the list to generate the query but I am not sure how to achieve that. Or if there is

How to write nested queries in select clause

核能气质少年 提交于 2019-11-30 18:04:58
I'm trying to produce this SQL with SLICK 1.0.0: select cat.categoryId, cat.title, ( select count(product.productId) from products product right join products_categories productCategory on productCategory.productId = product.productId right join categories c on c.categoryId = productCategory.categoryId where c.leftValue >= cat.leftValue and c.rightValue <= cat.rightValue ) as productCount from categories cat where cat.parentCategoryId = 2; My most successful attempt is (I dropped the "joins" part, so it's more readable): def subQuery(c: CategoriesTable.type) = (for { p <- ProductsTable } yield

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

一世执手 提交于 2019-11-30 17:07:12
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" % "1.0.1" withSources(), Then, when I run an integration spec for controller I got following exception both on Intellij IDE and command line activator test. After Google I found the solution: https://www.playframework.com/documentation/2.4.x/PlaySlickFAQ#A-binding-to-play.api.db.DBApi-was-already-configured After I removed the jdbc dependency, the integration spec passed when I using the

How can I roll back an integration test with Slick 3 + Specs2?

岁酱吖の 提交于 2019-11-30 14:01:49
问题 I want to write some integration tests for a service that runs slick and then clean a postgresql database up afterward up by rolling back a transaction, but I don't see a way to do it. I understand that I can test DBIO objects which have been composed together and roll them back, but it doesn't look like it's possible if I want to test at a higher level of abstraction. In pseudocode, I want to do this: StartDbTransaction() // setup DoSomethingInDB() AssertSomething() RollBackDbTransaction() /

How to use Slick's mapped tables with foreign keys?

前提是你 提交于 2019-11-30 13:40:37
I'm struggling with Slick's lifted embedding and mapped tables. The API feels strange to me, maybe just because it is structured in a way that's unfamiliar to me. I want to build a Task/Todo-List. There are two entities: Task: Each task has a an optional reference to the next task. That way a linked list is build. The intention is that the user can order the tasks by his priority. This order is represented by the references from task to task. TaskList: Represents a TaskList with a label and a reference to the first Task of the list. case class Task(id: Option[Long], title: String, nextTask:

Is it possible to use IN clause in plain sql Slick?

99封情书 提交于 2019-11-30 11:16:19
For example, I want to create the following query: SELECT c.* FROM Coffees c WHERE c.name IN ('robusta', 'arabica') My attempt failed: val cnames = List("robusta", "arabica") sql""" SELECT c.* FROM Coffees c WHERE c.name IN ${cnames} """ could not find implicit value for parameter pconv: scala.slick.jdbc.SetParameter[List[String]] Is it possible to somehow use in clause in Slick plain sql queries? I don't see anything out of the box to handle this. You're best bet is probably something like this: val cnames = List("robusta", "arabica").map("'" + _ + "'").mkString(",") val query = sql""" SELECT

How can I roll back an integration test with Slick 3 + Specs2?

送分小仙女□ 提交于 2019-11-30 09:06:13
I want to write some integration tests for a service that runs slick and then clean a postgresql database up afterward up by rolling back a transaction, but I don't see a way to do it. I understand that I can test DBIO objects which have been composed together and roll them back, but it doesn't look like it's possible if I want to test at a higher level of abstraction. In pseudocode, I want to do this: StartDbTransaction() // setup DoSomethingInDB() AssertSomething() RollBackDbTransaction() // teardown For example, if I have this (simplified from the play-silhouette-slick-seed ): class

How can I handle a > 22 column table with Slick using nested tuples or HLists?

眉间皱痕 提交于 2019-11-30 08:09:01
I'm new to Scala (using 2.10) and Slick (using 2.0-M2). I see that one of the ways to get around the 22 column limit for tables in Slick is to use nested tuples. I can't figure out how to do that, despite finding this partial code on GitHub . Current dev branch Scala (2.11-M5) supports case classes with more than 22 elements, but not tuples with arity > 22. And Slick is not yet distributed for Scala 2.11 pre-releases. How can I define a 33 column table (and have it work with all Slick's syntactic sugar)? N.B., I'm trying to support an existing schema and can't change the table normalization.

Slick, how to map a query to an inheritance table model?

混江龙づ霸主 提交于 2019-11-30 07:08:38
Slick, how to map a query to an inheritance table model? i.e, I have table A, B, C A is the "parent" table and B & C are "child" tables What I would like to know is how should I model this using slick so A will be abstract and B & C concrete types, and querying for a row in A will result in a B or C object Something like JPA's InheritanceType.TABLE_PER_CLASS . We need to do couple of things. First find a way to map the hierarchy to an table. In this case I am using a column that stores the type. But you can use some other tricks as well. trait Base { val a: Int val b: String } case class

Slick and filtering by Option columns

旧巷老猫 提交于 2019-11-30 06:40:30
I'm trying to filter against an optional date column with Scala Slick 1.0.1. It may be I just don't see it, but I've got a table that looks something like this: case class UserRole(id:UUID, userID:UUID, role:String) object UserRole extends Table[UserRole]("User_Role") { //(id: Long = 0l, name: String, active: Boolean) extends KeyedEntity[Long] { def id = column[UUID]("ID", O.PrimaryKey) def userID = column[UUID]("user_id") def vendorID = column[UUID]("vendor_id") def role = column[String]("role") def user = foreignKey("user_FK", userID, User)(_.id) def start = column[java.sql.Date]("startDate"