slick

Using .tupled method when companion object is in class

十年热恋 提交于 2019-11-30 06:25:59
问题 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 has a companion object, i.e. if you have something like this case class Person(firstName:String,lastName:String) { } Along with a companion object object Person { def something = "rawr" } In the same scope, the tupled method no longer works,

Type Projection of Foreign Keys in Scala-Slick

六月ゝ 毕业季﹏ 提交于 2019-11-30 04:37:13
问题 I'm using Scala, and new to Play and Slick. I'm starting to block out a simple database structure and I'm not sure about the correct way to handle foreign keys and projections. In the example at page bottom it currently doesn't compile because a ForeignKey cannot be lifted directly, so what's the correct way to have query results lift into my type (which is basically this sans methods and additional constructors): case class UserCompanyPermission(pk: UUID, company: Company, user: User,

How to make aggregations with slick

a 夏天 提交于 2019-11-30 04:33:14
I want to force slick to create queries like select max(price) from coffees where ... But slick's documentation doesn't help val q = Coffees.map(_.price) //this is query Query[Coffees.type, ...] val q1 = q.min // this is Column[Option[Double]] val q2 = q.max val q3 = q.sum val q4 = q.avg Because those q1-q4 aren't queries, I can't get the results but can use them inside other queries. This statement for { coffee <- Coffees } yield coffee.price.max generates right query but is deprecated (generates warning: " method max in class ColumnExtensionMethods is deprecated: Use Query.max instead"). How

Slick- use foreignKey constraint and access referenced object directly as column

浪子不回头ぞ 提交于 2019-11-30 03:55:04
问题 I have two models (say, Supplier and Coffee ) and Coffee model has foreign key reference to Supplier model. During ddl, I want this relationship to exist in table creation. But I also want to be able to refer the Supplier object through Coffee object like coffeeObj.supplier.name . Below is my dummy code. I am using MappedTable, foreignKey and TypeMapper. import scala.slick.driver.H2Driver.simple._ import Database.threadLocalSession object SlickTest { // Supplier case class Supplier(id: Option

Slick 3.0.0: How to query one-to-many / many-to-many relations

╄→гoц情女王★ 提交于 2019-11-30 03:23:16
Basically the same question has been asked about a year ago for slick 2.x ( scala slick one-to-many collections ). I'm wondering if there has any progression been made with the release of reactive slick. Let's say for example we have three tables. library , book and library_to_book where a library has many books. What I want is a list of libraries with their books. In scala this would be something like Seq[(Library, Seq[Book])] . The query I have is as follows: val q = (for { l <- libraries ltb <- libraryToBooks if l.id === ltb.libraryId b <- books if ltb.bookId === b.id } yield (l, b) db.run

Slick/Scala: What is a Rep[Bind] and how do I turn it into a value?

坚强是说给别人听的谎言 提交于 2019-11-30 03:05:57
问题 I'm trying to figure out Slick (the Scala functional relational model). I've started to build a prototype in Slick 3.0.0 but of course... most of the documentation is either out of date or incomplete. I've managed to get to a point where I can create a schema and return an object from the database. The problem is, what I'm getting back is a "Rep[Bind]" and not the object I would expect to get back. I can't figure out what to do this this value. For instance, if I try something like rep

How to write nested queries in select clause

痞子三分冷 提交于 2019-11-30 02:39:00
问题 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"

Slick left/right/outer joins with Option

你说的曾经没有我的故事 提交于 2019-11-30 01:54:43
In the Slick examples there are a few examples of joining where one of the resulting columns can be nulls, as it can be the case when doing left, right, or outer joins. For example: val explicitLeftOuterJoin = for { (c, s) <- Coffees leftJoin Suppliers on (_.supID === _.id) } yield (c.name, s.name.?) But what if I want to return the entire mapped object? What I mean is: val explicitLeftOuterJoin = for { (c, s) <- Coffees leftJoin Suppliers on (_.supID === _.id) } yield (c, s.?) This doesn't seem to work as it complains about "could not find implicit value for evidence parameter of type scala

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

£可爱£侵袭症+ 提交于 2019-11-30 01:03:51
问题 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

Upsert in Slick

笑着哭i 提交于 2019-11-29 23:58:44
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 { u <- Users if u.id === id } yield u.lastSeen q.update(now) match { case 0 => Users.insert((id, now, now)) case _ => Unit } Updated for native upsert/merge support in Slick 2.1 Attention You have to use plain SQL embedding with your database native MERGE statement. All trials to simulate this statement will very likely lead to incorrect results.