slick

Extending SLICK Tables in a DRY manner

给你一囗甜甜゛ 提交于 2019-12-20 12:34:01
问题 I have an interesting question around Slick/Scala that I am hoping that one of you nice chaps might be able to assist me with. I have several tables and by extension in SLICK case classes case class A(...) case class B(...) case class C(...) that share these common fields (id: String, livemode: Boolean, created: DateTime, createdBy : Option[Account]) . Because these fields are repeated in every case class, I'd like to explore the possibility of extracting them into a single object or type.

How to COUNT(*) in Slick 2.0?

时间秒杀一切 提交于 2019-12-20 11:51:25
问题 According to the Slick 2.0 documentation, to get the count of rows in a table: val q1 = coffees.length // compiles to SQL (simplified): // select count(1) from "COFFEES" However, it turns out that coffees.length is of type Column[Int] . How does one execute the query and get the value? 回答1: I just had this same problem upgrading to slick 2.0. I forget where the exact method lives, but the generic .run seems to work for me, i.e. coffees.length.run 回答2: StaticQuery.queryNA[Int]("select count(*)

How does Scala Slick translate Scala code into JDBC?

风流意气都作罢 提交于 2019-12-20 11:37:44
问题 How does Slick translate code such as: val q2 = for { c <- Coffees if c.price < 9.0 s <- Suppliers if s.id === c.supID } yield (c.name, s.name) for(t <- q2) println(" " + t._1 + " supplied by " + t._2) Into JDBC? Does it use Scala Virtualized? Does it use some other method? 回答1: Slick's stable API achieves this via what it calls lifted embedding . Your example is clearly using the stable API (as you use === for equality and not == ). The beauty of Slick (and in turn Scala) is that - this much

How does Scala Slick translate Scala code into JDBC?

删除回忆录丶 提交于 2019-12-20 11:36:16
问题 How does Slick translate code such as: val q2 = for { c <- Coffees if c.price < 9.0 s <- Suppliers if s.id === c.supID } yield (c.name, s.name) for(t <- q2) println(" " + t._1 + " supplied by " + t._2) Into JDBC? Does it use Scala Virtualized? Does it use some other method? 回答1: Slick's stable API achieves this via what it calls lifted embedding . Your example is clearly using the stable API (as you use === for equality and not == ). The beauty of Slick (and in turn Scala) is that - this much

Scala slick query where in list

丶灬走出姿态 提交于 2019-12-20 10:36:21
问题 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 = ? """).firstOption(visitorId,locationCode) What I would like to know is how can I change the above to query to get a List[Visit] for a collection of Locations...something like this: val locationCodes = List("loc1","loc2","loc3"...) Q.query[(Int,Int,List[String]), Visit](""" select *

Slick 3.1 - Retrieving subset of columns as a case class

独自空忆成欢 提交于 2019-12-20 10:28:07
问题 I'm working with Slick 3.1.1 and the problem is that in some cases I want to omit some columns that are fairly heavy and still materialize that subset of columns as a case class. Consider the following table definition: class AuditResultTable(tag: Tag) extends Table[AuditResult](tag, AuditResultTableName) { def auditResultId: Rep[Long] = column[Long]("AuditResultId", O.PrimaryKey, O.AutoInc) def processorId: Rep[Long] = column[Long]("ProcessorId") def dispatchedTimestamp: Rep[Timestamp] =

SELECT DISTINCT in Scala slick

Deadly 提交于 2019-12-20 10:19:31
问题 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 close to my situation). Here, I want all coffees that are provided by suppliers on the west coast. I want the Coffee only, I am only interested in navigating to Suppliers to apply the filter: val westCoast = Seq("CA", "OR", "WA") val implicitInnerJoin

Getting autoincrement values with Slick library in Scala

时光总嘲笑我的痴心妄想 提交于 2019-12-20 09:37:23
问题 How do I get the auto-incremented values for records inserted with Slick? The following code prints 1111. I would have expected it to print 1234 import scala.slick.driver.H2Driver.simple._ object TestMappedTable extends App{ case class User(id: Option[Int], first: String, last: String) object Users extends Table[User]("users") { def id = column[Int]("id", O.PrimaryKey, O.AutoInc) def first = column[String]("first") def last = column[String]("last") def * = id.? ~ first ~ last <> (User, User

Executing non-database actions in a transaction in Slick 3

夙愿已清 提交于 2019-12-20 08:58:29
问题 I'm having trouble understanding the new Slick DBIOAction API, which does not seem to have a lot of examples in the docs. I am using Slick 3.0.0, and I need to execute some DB actions and also some calculations with the data received from the database, but all of those actions have to be done inside a single transaction. I'm trying to do the following: Execute a query to database (the types table). Do some aggregations and filtering of the query results (this calculation can't be done on the

Compose “Insert…Select…Where” query

ε祈祈猫儿з 提交于 2019-12-19 19:46:23
问题 I'm trying to compose a query using Slick 3.0, but can't seem to figure it out. The equivalent SQL is "insert into SavedMail select * from Inbox where Inbox.id = 1" val mailTable = TableQuery[Tables.Inbox] val savedMailTable = TableQuery[Tables.Savedmail] val select = mailTable.filter(_.id === msgId) I'm stuck on how to do the insert now. Help appreciated. 回答1: Here's a solution I've come up with. Perhaps there's a way to not use forceInsertQuery, but hey, this works. val mailTable =