slick

Slick: combine actions with a Seq of DBIOAction

☆樱花仙子☆ 提交于 2019-12-04 09:45:24
I have the (working) following code: val actions = (for { _ <- slickUsers.insertOrUpdate(dbUser) loginInfo <- loginInfoAction _ <- slickUserLoginInfos += DBUserLoginInfo(dbUser.userID, loginInfo.id.get) } yield ()).transactionally with loginInfoAction being a DBIOAction. I would like to change loginInfoActions to a Seq of DBIOAction and for each of them, execute the same DBUserLoginInfo action afterwards. I tried this stupidly: val actions = (for { _ <- slickUsers.insertOrUpdate(dbUser) loginInfoAction <- loginInfoActions loginInfo <- loginInfoAction _ <- slickUserLoginInfos += DBUserLoginInfo

right usage of slick filter

血红的双手。 提交于 2019-12-04 09:15:26
I'm using slick to access database. I want to query like this: case class Coupon(couponId: Long, shopId: String) class Coupons(tag: Tag) extends Table[Coupon](tag, "coupons"){ def couponId = column[Long]("coupon_id") def shopId = column[String]("shop_id") override def * = (couponId, shopId) <> (Coupon.tupled, Coupon.unapply) } object Coupons extends TableQuery(new Coupons(_)){ def findCouponBy(couponId: Long, shopId: Option[String]) = { val s = DB.createSession() try { val q = for { coupon <- this.filter(c => c.couponId === couponId && shopId.map(s => c.shopId === s).getOrElse(true) } yield

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

一曲冷凌霜 提交于 2019-12-04 06:48:57
问题 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

Streaming in slick/scala

◇◆丶佛笑我妖孽 提交于 2019-12-04 04:59:33
I'm looking at scala/slick streaming, and trying to understand how it works. Here is my test code val bigdata = TableQuery[BigData] val x = db.stream(bigdata.result.transactionally.withStatementParameters(fetchSize = 100)).foreach { (tuple: (Int, UUID)) => println(tuple._1 + " " + tuple._2) Thread.sleep(50)//emulating slow consumer. } Await.result(x, 100000 seconds) While the code is running I enabled postgresql query log to understand whats going under the hood. I see a re-query happening every 100 elements 2015-11-06 15:03:24 IST [24379-3] postgres@scala_test LOG: execute fetch from S_2/C_3:

Filtering when using custom column type in Slick

六月ゝ 毕业季﹏ 提交于 2019-12-04 03:11:26
I'm having some difficulties querying/filtering in Slick 2.1.0 when using a custom column type. A simplified version of my problem: import scala.slick.driver.MySQLDriver.simple._ sealed class Status(val intValue: Int) case object Active extends Status(1) case object Disabled extends Status(2) case object Deleted extends Status(3) case class TableMapping(id: Long, status: Status) class MyTableDefinition(tag: Tag) extends Table[TableMapping](tag, "sometable") { implicit val statusColumnType = MappedColumnType.base[Status, Int](statusToInt, intToStatus) def id = column[Long]("ID", O.PrimaryKey, O

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

人走茶凉 提交于 2019-12-04 03:06:00
问题 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

How to use SQL “LIKE” operator in SLICK

て烟熏妆下的殇ゞ 提交于 2019-12-03 23:33:24
Maybe a silly question. But I have not found an answer so far. So how do you represent the SQL's "LIKE" operator in SLICK ? Exactly as you normally would! val query = for { coffee <- Coffees if coffee.name like "%expresso%" } yield (coffee.name, coffee.price) Will generate SQL like SELECT name, price FROM coffees WHERE NAME like '%expresso%'; 来源: https://stackoverflow.com/questions/14700821/how-to-use-sql-like-operator-in-slick

Turn Slick logging off

ε祈祈猫儿з 提交于 2019-12-03 18:01:14
问题 Slick fills up the console with a massive amount of log messages. I wanted, like the documentation suggested, to use slf4j-nop , so logging is turned off, but Akka needs its own slf4j library. So I'm left with akka-slf4j_2.10 that Slick also uses. I've tried many things. Included in my application.conf is this (tried with and without "): logger="OFF" logger.scala.slick="OFF" logger.scala.slick.session="OFF" logger.scala.slick.jdbc.JdbcBackend.statement="OFF" logger.scala.slick.jdbc="OFF" It

scala slick one-to-many collections

流过昼夜 提交于 2019-12-03 16:08:37
问题 I have a database that contain activities with a one-to-many registrations relation. The goal is to get all activities, with a list of their registrations. By creating a cartesian product of activities with registrations, all necessary data to get that data is out is there. But I can't seem to find a nice way to get it into a scala collection properly; let's of type: Seq[(Activity, Seq[Registration])] case class Registration( id: Option[Int], user: Int, activity: Int ) case class Activity( id

Scala Slick table inheritance

≯℡__Kan透↙ 提交于 2019-12-03 15:55:24
I have SQL table inheritance implemented this way: Table Shape: Column | Type ------------+--------- shape_id | integer square | foat name | character varying(64) Table Triangle Column | Type ------------+--------- shape_id | integer a | float b | float c | float Foreign-key constraints: "fkey1" FOREIGN KEY (shape_id) REFERENCES Shape(shape_id) Table Circle Column | Type ------------+--------- shape_id | integer r | float Foreign-key constraints: "fkey2" FOREIGN KEY (shape_id) REFERENCES Shape(shape_id) Is it possible with slick to create class model where Triangle extends Shape and Circle