slick

Slick left outer join fetching whole joined row as option

情到浓时终转凉″ 提交于 2019-12-02 22:20:36
My join looks like this: def byIdWithImage = for { userId <- Parameters[Long] (user, image) <- Users leftJoin RemoteImages on (_.imageId === _.id) if user.id === userId } yield (user, image) but slick fails at runtime when user.imageId is null [SlickException: Read NULL value for column RemoteImage.url] Changing the yield to } yield (user, image.?) gives me a compile time exception, it only works on individual columns could not find implicit value for evidence parameter of type scala.slick.lifted.TypeMapper[image.type] Would there be a different way to accomplish what I'm trying to do here?

SELECT DISTINCT in Scala slick

随声附和 提交于 2019-12-02 21:56:58
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 = for { c <- Coffees s <- Suppliers if c.supID === s.id && s.state inSet westCoast } yield c This

Getting autoincrement values with Slick library in Scala

喜欢而已 提交于 2019-12-02 19:15:47
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.unapply _) } implicit val session = Database.forURL("jdbc:h2:mem:test1", driver = "org.h2.Driver")

Get count of rows in table A that have a reference to table B

半腔热情 提交于 2019-12-02 11:35:52
I am left joining two tables, 'device' and 'unit'. Device defines the type of device and an unit is an unique device that points to a row in the device table, defining its type. I am now searching for a solution to select every device type from 'device' and counting how many units are there pointing to this device. The problem I am confronted with in my current solution, SQL : SELECT device.*, COUNT(unit.id) FROM device LEFT JOIN unit ON device.id = unit.device_id GROUPBY device.id Scala Slick : def devicesWithUnitCount = for { (device, unit) <- TableQuery[TDDevice] joinLeft TableQuery[TDUnit]

Run transactionally and retrieve result in Future

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 10:02:43
How to run a transactionally statement in Slick 3.1.x, and capture the result in a Future (without the use of Await)? This works (but uses Await) val action = db.run((for { _ <- table1.filter(_.id1 === id).delete _ <- table2.filter(_.id2=== id).delete } yield ()).transactionally) val result = Await.result(action, Duration.Inf) However this does not print anything: val future = db.run((for { _ <- table1.filter(_.id1 === id).delete _ <- table2.filter(_.id2=== id).delete } yield ()).transactionally) future.map { result => println("result:"+result) } UPDATE This is the real code taken from the

Scala slick 2.0 updateAll equivalent to insertALL?

ⅰ亾dé卋堺 提交于 2019-12-02 05:24:34
问题 Looking for a way to do a batch update using slick. Is there an equivalent updateAll to insertALL? Goole research has failed me thus far. I have a list of case classes that have varying status. Each one having a different numeric value so I cannot run the typical update query. At the same time, I want to save the multiple update requests as there could be thousands of records I want to update at the same time. 回答1: It's not clear to me what you are trying to achieve, insert and update are two

unresolved dependency: com.typesafe.play#play-slick_2.10;0.6.0.1: not found

此生再无相见时 提交于 2019-12-02 00:31:15
问题 I am getting unresolved dependencies errors when trying to use slick or play-slick with Play Framework 2.2.2, sbt 0.13.0 and Scala 2.10.3 on Mac OS X Mavericks. [info] Updating {file:/Users/michaelrichardson/Documents/Play/glasgowEffect/}glasgoweffect... [info] Resolving com.typesafe.play#slick_2.10;2.0.0 ... [warn] module not found: com.typesafe.play#slick_2.10;2.0.0 [warn] ==== Typesafe Releases Repository: tried [warn] http://repo.typesafe.com/typesafe/releases/com/typesafe/play/slick_2.10

Scala slick 2.0 updateAll equivalent to insertALL?

纵饮孤独 提交于 2019-12-01 23:34:50
Looking for a way to do a batch update using slick. Is there an equivalent updateAll to insertALL? Goole research has failed me thus far. I have a list of case classes that have varying status. Each one having a different numeric value so I cannot run the typical update query. At the same time, I want to save the multiple update requests as there could be thousands of records I want to update at the same time. Ende Neu It's not clear to me what you are trying to achieve, insert and update are two different operation, for insert makes sense to have a bulk function, for update it doesn't in my

unresolved dependency: com.typesafe.play#play-slick_2.10;0.6.0.1: not found

丶灬走出姿态 提交于 2019-12-01 21:02:35
I am getting unresolved dependencies errors when trying to use slick or play-slick with Play Framework 2.2.2, sbt 0.13.0 and Scala 2.10.3 on Mac OS X Mavericks. [info] Updating {file:/Users/michaelrichardson/Documents/Play/glasgowEffect/}glasgoweffect... [info] Resolving com.typesafe.play#slick_2.10;2.0.0 ... [warn] module not found: com.typesafe.play#slick_2.10;2.0.0 [warn] ==== Typesafe Releases Repository: tried [warn] http://repo.typesafe.com/typesafe/releases/com/typesafe/play/slick_2.10/2.0.0/slick_2.10-2.0.0.pom [info] Resolving com.typesafe.play#play-slick_2.10;0.6.0.1 ... [warn]

Inserting default values if column value is 'None' using slick

不羁的心 提交于 2019-12-01 16:12:14
My problem is simple. I have a column seqNum: Double which is NOT NULL DEFAULT 1 in CREATE TABLE statement as follows: CREATE TABLE some_table ( ... seq_num DECIMAL(18,10) NOT NULL DEFAULT 1, ... ); User can enter a value for seqNum or not from UI. So the accepting PLAY form is like: case class SomeCaseClass(..., seqNum: Option[Double], ...) val secForm = Form(mapping( ... "seqNum" -> optional(of[Double]), ... )(SomeCaseClass.apply)(SomeCaseClass.unapply)) The slick Table Schema & Objects looks like this: case class SomeSection ( ... seqNum: Option[Double], ... ) class SomeSections(tag: Tag)