slick-3.0

Slick 3.1 - Retrieving subset of columns as a case class

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 22:44:10
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] = column[Timestamp]("DispatchedTimestamp", O.SqlType("timestamp(2)")) def SystemAOutput: Rep[Array[Byte]] =

Run transactionally and retrieve result in Future

梦想与她 提交于 2019-12-02 22:20:52
问题 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 ())

How to use transaction in slick

*爱你&永不变心* 提交于 2019-12-02 10:11:15
问题 I have insert method like this (weight is index) implicit def run[A](action: DBIOAction[A, NoStream, _ <: slick.dbio.Effect]): Future[A] = { db.run(action) } def insert(newCategory: CategoryExtractor): Future[Either[String, CategoryResponse]] = { category.map(_.weight).max.result.flatMap { case Some(weight) => val temp = newCategory.copy(weight = weight+1) (category += temp).andThen(DBIO.successful(Right(toCategoryExtractor(temp)))) case None => val temp = newCategory.copy(weight = 1)

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

Can't connect to mysql database with play-slick 1.0.1/slick 3.0 : configuration error

别来无恙 提交于 2019-12-02 04:41:43
I'm trying to migrate from anorm to slick, using play 2.4.2, and getting a configuration error: play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [dethcs]] at play.api.Configuration$.configError(Configuration.scala:178) ~[play_2.11-2.4.0.jar:2.4.0] ... Caused by: slick.SlickException: Error getting instance of Slick driver "slick.driver.MySQLDriver" ... Caused by: java.lang.NoSuchMethodException: slick.driver.MySQLDriver.<init>() Previous answers I've found on SO have focused on having the right MySQL driver and other dependencies. I believe my build.sbt covers the

Slick 3.0.0 - update row with only non-null values

巧了我就是萌 提交于 2019-12-01 09:39:17
问题 Having a table with the columns class Data(tag: Tag) extends Table[DataRow](tag, "data") { def id = column[Int]("id", O.PrimaryKey) def name = column[String]("name") def state = column[State]("state") def price = column[Int]("price") def * = (id.?, name, state, price) <> ((DataRow.apply _).tupled, DataRow.unapply) } I'd like to write a function that would select a single row, and update the columns where the supplied values are not null. def update(id: Int, name: Option[String], state: 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

How are reactive streams used in Slick for inserting data

吃可爱长大的小学妹 提交于 2019-11-29 04:01:17
In Slick's documentation examples for using Reactive Streams are presented just for reading data as a means of a DatabasePublisher. But what happens when you want to use your database as a Sink and backpreasure based on your insertion rate? I've looked for equivalent DatabaseSubscriber but it doesn't exist. So the question is, if I have a Source, say: val source = Source(0 to 100) how can I crete a Sink with Slick that writes those values into a table with schema: create table NumberTable (value INT) Serial Inserts The easiest way would be to do inserts within a Sink.foreach . Assuming you've

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

懵懂的女人 提交于 2019-11-29 00:25:55
问题 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

Slick 3.0 Insert and then get Auto Increment Value

依然范特西╮ 提交于 2019-11-28 18:55:35
问题 I have written this code which works perfectly class Items(tag: Tag) extends Table[Item](tag, "ITEMS") { def id = column[Long]("ITEMS_ID", O.PrimaryKey, O.AutoInc) def name = column[String]("ITEMS_NAME") def price = column[Double]("ITEMS_PRICE") def * = (id, name, price) <> ((Item.apply _).tupled, Item.unapply _) } object Shop extends Shop{ val items = TableQuery[Items] val db = Database.forConfig("h2mem1") def create(name: String, price: Double) : Int = { val action = items ++= Seq(Item(0,