slick-3.0

Slick 3.0 - Update columns in a table and return whole table object?

别等时光非礼了梦想. 提交于 2019-12-18 09:33:57
问题 Here is the implementation for Slick 2. Slick 2 - Update columns in a table and return whole table object Does anyone have ideas about how to implement this in Slick 3? 回答1: I was able to make this work by extending the awesome work by Tim Harper in https://stackoverflow.com/a/28148606/310275 Here's what I've done now: package utils import scala.language.existentials import slick.ast._ import slick.driver.PostgresDriver._ import slick.driver.PostgresDriver.api._ import slick.jdbc.{GetResult,

How are reactive streams used in Slick for inserting data

前提是你 提交于 2019-12-18 04:10:44
问题 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

How to mix Slick and JDBC in the same Play Framework project?

喜你入骨 提交于 2019-12-14 04:02:01
问题 I'd like to mix regular JDBC into my Play Framework project using Slick. I've ran into a few hurdles. Directly adding the jdbc dependency to my project yields this error from this question A binding to play.api.db.DBApi was already configured, evolutions and injector error with play-slick removing the jdbc dependency means I cannot use the play.api.db.Database class and yields this error Play error on startup: No implementation for play.api.db.Database was bound So how can I use regular jdbc

Slick Transactionally future is not invoked in Play for Scala [duplicate]

大兔子大兔子 提交于 2019-12-13 08:20:05
问题 This question already has answers here : Run transactionally and retrieve result in Future (2 answers) Closed 3 years ago . The code below prints '1' and never prints '2', as a result the browser hangs when it requests the page served by the index method. The future is never invoked. If the future.map statement is replaced with Await.result(future, Duration.Inf) the code works correctly. What is the problem? case class UserRole (sk: Int, name: String) class UserRoleDB(tag: Tag) extends Table

Translate nested join and groupby query to Slick 3.0

对着背影说爱祢 提交于 2019-12-12 10:55:40
问题 I'm implementing a todo list. A user can have multiple lists and a list can have multiple users. I want to be able to retrieve all the lists for a user, where each of these lists contain a list of the users for which it's shared (including the owner). Not succeeding implementing this query. The table definitions: case class DBList(id: Int, uuid: String, name: String) class Lists(tag: Tag) extends Table[DBList](tag, "list") { def id = column[Int]("id", O.PrimaryKey, O.AutoInc) // This is the

How to avoid Slick exception “A query for an UPDATE statement must select table columns only”

余生颓废 提交于 2019-12-12 05:54:17
问题 I have the following case class (note the Option in the last field) case class BranchVO(sk: Int, name: String, bankSk: Int, bankName: Option[String]) And the following class to have Slick access the database (Note the None in the * method, as the case class has an additional last field): class BranchDB(tag: Tag) extends Table[BranchVO](tag, "branches") { def sk: Rep[Int] = column[Int]("sk", O.PrimaryKey, O.AutoInc) def name: Rep[String] = column[String]("name") def bankSk: Rep[Int] = column

How to get max(id) of table = Rep[Option[Long]] for subsequent insert, without calling db.run in between

你离开我真会死。 提交于 2019-12-12 04:45:51
问题 I have an insert to a table, that depends on the max id of another table. def add(languageCode: String, typeId: Long, properties: Seq[Property]): Unit = { val dbAction = ( for{ nodeId <- (nodes.all returning nodes.all.map(_.id)) += Node(typeId) language <- (languages.all filter (_.code === languageCode)).result.head _ <- DBIO.seq(properties.map { property => val id = property.id val name = property.key val value = property.value if(id == 0) { val currentPropId: FixedSqlAction[Option[Long],

How to perform leftJoin on tables from different databases(data sources) using Scala Slick?

吃可爱长大的小学妹 提交于 2019-12-12 04:29:11
问题 I have 2 databases (database1 and database2). database1 has table1 with field id database2 has table2 with field id Now how do i perform leftJoin(as shown below) using Slick? SELECT tb1.`id` FROM `database1`.`table1` t1 LEFT JOIN `database1`.`table2` t2 ON t1.`id`=t2.`id` 回答1: I may be wrong here but most existing relational databases don't allow you to span multiple databases within single operation. However, what you showed above is easily achievable by using schema (and I strongly believe

Slick MTable.getTables always fails with Unexpected exception[JdbcSQLException: Invalid value 7 for parameter columnIndex [90008-60]]

最后都变了- 提交于 2019-12-11 20:45:30
问题 I have written this very simple code object PersonDAO { val db = Database.forConfig("h2mem1") val people = TableQuery[People] def checkTable() : Boolean = { val action = MTable.getTables val future = db.run(action) val retVal = future map {result => result map {x => x} } val x = Await.result(retVal, Duration.Inf) if (x.length > 0) { true } else { false } } } However this always fails with error message play.api.UnexpectedException: Unexpected exception[JdbcSQLException: Invalid value 7 for

Slick 3.0 (scala) queries don't return data till they are run multiple times (I think)

こ雲淡風輕ζ 提交于 2019-12-11 19:29:36
问题 So I'm very (extremely) new to Databases and slick and scala, so I was using the example code from their documentation at http://slick.typesafe.com/doc/3.0.0/gettingstarted.html My problem is that for some reason, I have to run a query multiple times before it returns data. I have to rerun it atleast 3-4 times before it returns results. I use a for-loop to rerun the query and they don't necessarily give me the exact same results each time either. to create two tables as followed: class